From 96f8578f25f094213862d39e3399eb4876f5a31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Pacana?= Date: Fri, 29 Mar 2024 18:15:27 +0100 Subject: [PATCH] Declare foreign_key via references https://github.com/RailsEventStore/rails_event_store/issues/1755 --- .../templates/create_event_store_events_template.erb | 4 +--- .../templates/mysql/create_event_store_events_template.erb | 4 +--- .../templates/postgres/create_event_store_events_template.erb | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) 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