Skip to content

Commit

Permalink
Honor PK settings (#402)
Browse files Browse the repository at this point in the history
* Honor PK settings

* Lint fixes
  • Loading branch information
rromanchuk authored Feb 14, 2024
1 parent 67411c7 commit d7ed992
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions db/migrate/20231215190233_create_noticed_tables.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class CreateNoticedTables < ActiveRecord::Migration[6.1]
def change
create_table :noticed_events do |t|
primary_key_type, foreign_key_type = primary_and_foreign_key_types
create_table :noticed_events, id: primary_key_type do |t|
t.string :type
t.belongs_to :record, polymorphic: true
t.belongs_to :record, polymorphic: true, type: foreign_key_type
if t.respond_to?(:jsonb)
t.jsonb :params
else
Expand All @@ -12,14 +13,24 @@ def change
t.timestamps
end

create_table :noticed_notifications do |t|
create_table :noticed_notifications, id: primary_key_type do |t|
t.string :type
t.belongs_to :event, null: false
t.belongs_to :recipient, polymorphic: true, null: false
t.belongs_to :event, null: false, type: foreign_key_type
t.belongs_to :recipient, polymorphic: true, null: false, type: foreign_key_type
t.datetime :read_at
t.datetime :seen_at

t.timestamps
end
end

private

def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end

0 comments on commit d7ed992

Please sign in to comment.