Skip to content

Commit

Permalink
Alter {users,job_definitions}.id to bigint
Browse files Browse the repository at this point in the history
There is the problem that some tables has different type of primary key from
its installed:

- before 0.2.0: using unsigned int for primary key
- after 0.2.0: using signed int for primary key

This problem was made by fa75b20.

This makes hard to keep consistency of code / infra.
For instance, we need to care about 2 types of primary when adding foreign key.
Actually, this is already blocker of cookpad#110

To solve the problem, this patch proposes to alter these primary key to
bigint, which is next default type of rails.
  • Loading branch information
Sangyong Sim committed May 17, 2018
1 parent 877348f commit 271c860
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions db/migrate/033_alter_key_and_index_to_bigint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class AlterKeyAndIndexToBigInt < ActiveRecord::Migration[5.0]
def up
change_column :job_definitions, :id, :bigint, null: false
change_column :admin_assignments, :job_definition_id, :bigint, null: false
change_column :execution_histories, :job_definition_id, :bigint, null: false
change_column :executions, :job_definition_id, :bigint, null: false
change_column :job_definition_tags, :job_definition_id, :bigint, null: false
change_column :job_instances, :job_definition_id, :bigint, null: false
change_column :job_schedules, :job_definition_id, :bigint, null: false
change_column :job_suspend_schedules, :job_definition_id, :bigint, null: false
change_column :memory_expectancies, :job_definition_id, :bigint, null: false
change_column :stars, :job_definition_id, :bigint, null: false
change_column :tokens, :job_definition_id, :bigint, null: false

change_column :users, :id, :bigint, null: false
change_column :admin_assignments, :user_id, :bigint, null: false
change_column :stars, :user_id, :bigint, null: false
end

def down
change_column :job_definitions, :id, :int, unsigned: true, null: false
change_column :admin_assignments, :job_definition_id, :int, unsigned: true, null: false
change_column :execution_histories, :job_definition_id, :int, unsigned: true, null: false
change_column :executions, :job_definition_id, :int, unsigned: true, null: false
change_column :job_definition_tags, :job_definition_id, :int, unsigned: true, null: false
change_column :job_instances, :job_definition_id, :int, unsigned: true, null: false
change_column :job_schedules, :job_definition_id, :int, unsigned: true, null: false
change_column :job_suspend_schedules, :job_definition_id, :int, unsigned: true, null: false
change_column :memory_expectancies, :job_definition_id, :int, unsigned: true, null: false
change_column :stars, :job_definition_id, :int, unsigned: true, null: false
change_column :tokens, :job_definition_id, :int, unsigned: true, null: false

change_column :users, :id, :int, unsigned: true, null: false
change_column :admin_assignments, :user_id, :int, unsigned: true, null: false
change_column :stars, :user_id, :int, unsigned: true, null: false
end
end

0 comments on commit 271c860

Please sign in to comment.