Split commit_id and noteable_id for Note
Created by: dzaporozhets
This PR will fix issue with postgres and noteable_id as string
Merge request reports
Activity
Created by: dzaporozhets
related to #2185 (closed)
By Administrator on 2012-12-18T18:08:05 (imported from GitLab project)
By Administrator on 2012-12-18T18:08:05 (imported from GitLab)
Created by: dzaporozhets
All tests passes on local machine but I got randomly this one:
PG::Error: ERROR: deadlock detected (ActiveRecord::StatementInvalid)
By Administrator on 2012-12-18T18:22:58 (imported from GitLab project)
By Administrator on 2012-12-18T18:22:58 (imported from GitLab)
4 add_column :notes, :new_noteable_id, :integer, null: true 5 Note.where(noteable_type: 'Commit').update_all('commit_id = noteable_id') 6 7 if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' 8 Note.where("noteable_type != 'Commit'").update_all('new_noteable_id = CAST (noteable_id AS INTEGER)') 9 else 10 Note.where("noteable_type != 'Commit'").update_all('new_noteable_id = noteable_id') 11 end 12 13 remove_column :notes, :noteable_id 14 rename_column :notes, :new_noteable_id, :noteable_id 15 end 16 17 def down 18 raise ActiveRecord::IrreversibleMigration 19 end Created by: riyad
This will fail:
- there is no
:new_noteable_id
column any more - all commit notes will have
:noteable_id
equalNULL
raise ActiveRecord::IrreversibleMigration
would be simpler. ;)By Administrator on 2012-12-19T10:08:42 (imported from GitLab project)
By Administrator on 2012-12-19T10:08:42 (imported from GitLab)
- there is no
1 class MoveNoteableCommitToOwnField < ActiveRecord::Migration 2 def up 3 add_column :notes, :commit_id, :string, null: true 4 add_column :notes, :new_noteable_id, :integer, null: true 5 Note.where(noteable_type: 'Commit').update_all('commit_id = noteable_id') 6 7 if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' 8 Note.where("noteable_type != 'Commit'").update_all('new_noteable_id = CAST (noteable_id AS INTEGER)') 9 else 10 Note.where("noteable_type != 'Commit'").update_all('new_noteable_id = noteable_id') 11 end 12 13 remove_column :notes, :noteable_id 14 rename_column :notes, :new_noteable_id, :noteable_id