Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prefer migration DSL that calms down strong_migrations #1759

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]

create_table(:event_store_events_in_streams, force: false) do |t|
t.string :stream, null: false
t.integer :position, null: true
t.references :event, null: false, type: :string, limit: 36, index: false
t.integer :position, null: true, default: :null
t.references :event, null: false, type: :string, limit: 36, index: true, foreign_key: { to_table: :event_store_events, primary_key: :event_id }
t.datetime :created_at, null: false, precision: 6, index: true
end
add_index :event_store_events_in_streams, [:stream, :position], unique: true
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
add_index :event_store_events_in_streams, [:event_id]

add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id"
t.index [:stream, :position], unique: true
t.index [:stream, :event_id], unique: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
create_table(:event_store_events_in_streams, force: false) do |t|
t.string :stream, null: false
t.integer :position, null: true
t.references :event, null: false, type: :string, limit: 36, index: false
t.references :event, null: false, type: :string, limit: 36, index: true, foreign_key: { to_table: :event_store_events, primary_key: :event_id }
t.datetime :created_at, null: false, precision: 6, index: true
end
add_index :event_store_events_in_streams, [:stream, :position], unique: true
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
add_index :event_store_events_in_streams, [:event_id]

add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id"
t.index [:stream, :position], unique: true
t.index [:stream, :event_id], unique: true
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ class CreateEventStoreEvents < ActiveRecord::Migration[<%= migration_version %>]
create_table(:event_store_events_in_streams, id: :bigserial, force: false) do |t|
t.string :stream, null: false
t.integer :position, null: true
t.references :event, null: false, type: :uuid, index: false
t.references :event, null: false, type: :uuid, index: true, foreign_key: { to_table: :event_store_events, primary_key: :event_id }
t.datetime :created_at, null: false, type: :timestamp, precision: 6, index: true
end
add_index :event_store_events_in_streams, [:stream, :position], unique: true
add_index :event_store_events_in_streams, [:stream, :event_id], unique: true
add_index :event_store_events_in_streams, [:event_id]

add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id"
t.index [:stream, :position], unique: true
t.index [:stream, :event_id], unique: true
end
end
end
6 changes: 3 additions & 3 deletions ruby_event_store-active_record/spec/migration_test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ module ActiveRecord
PRIMARY KEY (`id`),
UNIQUE KEY `index_event_store_events_in_streams_on_stream_and_event_id` (`stream`,`event_id`),
UNIQUE KEY `index_event_store_events_in_streams_on_stream_and_position` (`stream`,`position`),
KEY `index_event_store_events_in_streams_on_created_at` (`created_at`),
KEY `index_event_store_events_in_streams_on_event_id` (`event_id`),
KEY `index_event_store_events_in_streams_on_created_at` (`created_at`),
CONSTRAINT `fk_rails_c8d52b5857` FOREIGN KEY (`event_id`) REFERENCES `event_store_events` (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=#{charset}#{collation}
SCHEMA
Expand All @@ -132,14 +132,14 @@ module ActiveRecord
expect(
sqlite_schema("event_store_events_in_streams")
).to eq <<~SCHEMA.strip
CREATE TABLE "event_store_events_in_streams" ("id" integer NOT NULL PRIMARY KEY, "stream" varchar NOT NULL, "position" integer DEFAULT NULL, "event_id" varchar(36) NOT NULL, "created_at" datetime(6) NOT NULL, CONSTRAINT "fk_rails_c8d52b5857"
CREATE TABLE "event_store_events_in_streams" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "stream" varchar NOT NULL, "position" integer DEFAULT NULL, "event_id" varchar(36) NOT NULL, "created_at" datetime(6) NOT NULL, CONSTRAINT "fk_rails_c8d52b5857"
FOREIGN KEY ("event_id")
REFERENCES "event_store_events" ("event_id")
)
CREATE INDEX "index_event_store_events_in_streams_on_event_id" ON "event_store_events_in_streams" ("event_id")
CREATE INDEX "index_event_store_events_in_streams_on_created_at" ON "event_store_events_in_streams" ("created_at")
CREATE UNIQUE INDEX "index_event_store_events_in_streams_on_stream_and_position" ON "event_store_events_in_streams" ("stream", "position")
CREATE UNIQUE INDEX "index_event_store_events_in_streams_on_stream_and_event_id" ON "event_store_events_in_streams" ("stream", "event_id")
CREATE INDEX "index_event_store_events_in_streams_on_event_id" ON "event_store_events_in_streams" ("event_id")
SCHEMA
end

Expand Down