diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb index 3fd2f1b0bf..4657cadc38 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/create_event_store_events_template.erb @@ -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: true + 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 t.index [:stream, :position], unique: true t.index [:stream, :event_id], unique: true end - - add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id" end end diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb index 9bbe22d3e8..78c0d6d0f5 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/mysql/create_event_store_events_template.erb @@ -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: true + 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 t.index [:stream, :position], unique: true t.index [:stream, :event_id], unique: true end - - add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id" end end diff --git a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb index ea3c3c8bd1..2221589733 100644 --- a/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb +++ b/ruby_event_store-active_record/lib/ruby_event_store/active_record/generators/templates/postgres/create_event_store_events_template.erb @@ -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: true + 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 t.index [:stream, :position], unique: true t.index [:stream, :event_id], unique: true end - - add_foreign_key "event_store_events_in_streams", "event_store_events", column: "event_id", primary_key: "event_id" end end