0

I wonder how to change data type of id field from INT to BIGINT safely following strong_migrations suggestions?

Changing the type of an existing column requires the entire
table and indexes to be rewritten. A safer approach is to:
  1. Create a new column
  2. Write to both columns
  3. Backfill data from the old column to the new column
  4. Move reads from the old column to the new column
  5. Stop writing to the old column
  6. Drop the old column

What should be the name of new column in that case?

Hubert Jakubiak
  • 853
  • 8
  • 19
  • Based on this method you need columns with two different names, so the name is up to you. Maybe `user_number` and `user_big_number`. You will have two columns at least until you get to step 6. – whodini9 Nov 09 '18 at 21:47
  • @whodini9 I'm about updating `id` column which is primary key for table. – Hubert Jakubiak Nov 09 '18 at 21:59
  • I see, would this solution work? https://stackoverflow.com/questions/33504982/postgresql-concurrently-change-column-type-from-int-to-bigint – whodini9 Nov 09 '18 at 22:02
  • Reading this https://jilt.com/blog/migrations-zero-downtime-rails/ I think that suggestion from `strong_migrations` gem just missed part about renaming column at the end. – Hubert Jakubiak Nov 09 '18 at 22:08

0 Answers0