Class: IdToUuidCredereTables
- Inherits:
-
Object
- Object
- IdToUuidCredereTables
- Defined in:
- lib/generators/credere/templates/id_to_uuid_migration.rb
Instance Method Summary collapse
Instance Method Details
#down ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/generators/credere/templates/id_to_uuid_migration.rb', line 52 def down # Migrate all UUID IDs to integers in all Credere tables. Why would you want to? add_column :credere_accounts, :temp_id, :integer, null: false change_table :credere_accounts do |t| t.remove :id t.rename :temp_id, :id end if column_exists? :credere_accounts, :tenant_id add_column :credere_accounts, :temp_tenant_id, :integer change_table :credere_accounts do |t| t.remove :tenant_id t.rename :temp_tenant_id, :tenant_id end add_index :credere_accounts, :tenant_id end execute "ALTER TABLE credere_accounts ADD PRIMARY KEY (id);" add_column :credere_amounts, :temp_id, :integer, null: false add_column :credere_amounts, :temp_account_id, :integer, null: false add_column :credere_amounts, :temp_entry_id, :integer, null: false change_table :credere_amounts do |t| t.remove :id t.rename :temp_id, :id t.remove :temp_account_id t.rename :temp_account_uuid, :account_id t.remove :temp_entry_id t.rename :temp_entry_uuid, :entry_id end add_index :credere_amounts, :account_id add_index :credere_amounts, :entry_id execute "ALTER TABLE credere_amounts ADD PRIMARY KEY (id);" add_column :credere_entries, :temp_id, :integer, null: false change_table :credere_entries do |t| t.remove :id t.rename :temp_id, :id end execute "ALTER TABLE credere_entries ADD PRIMARY KEY (id);" end |
#up ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/credere/templates/id_to_uuid_migration.rb', line 2 def up # Migrate all integer IDs to UUID in all Credere tables. add_column :credere_accounts, :uuid, :uuid, default: -> { "uuid_generate_v4()" }, null: false change_table :credere_accounts do |t| t.remove :id t.rename :uuid, :id end if column_exists? :credere_accounts, :tenant_id add_column :credere_accounts, :tenant_uuid, :uuid, default: -> { "uuid_generate_v4()" }, null: false change_table :credere_accounts do |t| t.remove :tenant_id t.rename :tenant_uuid, :tenant_id end add_index :credere_accounts, :tenant_id end execute "ALTER TABLE credere_accounts ADD PRIMARY KEY (id);" add_column :credere_amounts, :uuid, :uuid, default: -> { "uuid_generate_v4()" }, null: false add_column :credere_amounts, :account_uuid, :uuid, default: -> { "uuid_generate_v4()" }, null: false add_column :credere_amounts, :entry_uuid, :uuid, default: -> { "uuid_generate_v4()" }, null: false change_table :credere_amounts do |t| t.remove :id t.rename :uuid, :id t.remove :account_id t.rename :account_uuid, :account_id t.remove :entry_id t.rename :entry_uuid, :entry_id end add_index :credere_amounts, :account_id add_index :credere_amounts, :entry_id execute "ALTER TABLE credere_amounts ADD PRIMARY KEY (id);" add_column :credere_entries, :uuid, :uuid, default: -> { "uuid_generate_v4()" }, null: false change_table :credere_entries do |t| t.remove :id t.rename :uuid, :id end execute "ALTER TABLE credere_entries ADD PRIMARY KEY (id);" end |