Skip to content
Snippets Groups Projects

Split commit_id and noteable_id for Note

Merged gitlab-qa-bot requested to merge fix_postgres_notes into master

Created by: dzaporozhets

This PR will fix issue with postgres and noteable_id as string

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
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 equal NULL

    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)

  • gitlab-qa-bot
  • 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
    • Created by: riyad

      You should add indexes for :commit_id and :noteable_id

      By Administrator on 2012-12-19T10:08:42 (imported from GitLab project)

      By Administrator on 2012-12-19T10:08:42 (imported from GitLab)

  • Created by: vsizov

    good idea

    By Administrator on 2012-12-18T21:25:59 (imported from GitLab project)

    By Administrator on 2012-12-18T21:25:59 (imported from GitLab)

  • Please register or sign in to reply
    Loading