Use dedicated sequence record instead of deal with issues with ids and uuids when using the previous approach

This commit is contained in:
Jorge Manrubia
2025-11-27 11:55:47 +01:00
parent 07b4c55185
commit 2061ab4ab2
8 changed files with 91 additions and 28 deletions
@@ -0,0 +1,9 @@
class CreateAccountExternalIdSequences < ActiveRecord::Migration[8.0]
def change
create_table :account_external_id_sequences do |t|
t.bigint :value, null: false, default: 0
t.index :value, unique: true
end
end
end
@@ -1,15 +0,0 @@
class CreateExternalAccounts < ActiveRecord::Migration[8.0]
def up
create_table :external_accounts do |t|
end
max_id = Account.maximum(:external_account_id) || 0
if max_id > 0
execute "INSERT INTO external_accounts (id) VALUES (#{max_id})"
end
end
def down
drop_table :external_accounts
end
end