Skip to content

Implementing a data migration class to transform existing data in columns to new types #52506

Answered by noefleury
Smurrlawa asked this question in Ideas
Discussion options

You must be logged in to vote

Hi,

One of the solution if your column (A) is not compatible with the new type should be to :

  • add a new column (B) with json type
  • apply your transformation row by row using chunks (A to B)
  • drop the old column (A)
  • then finally rename the one you've just filled to the original column name (B -> A)

To be safe about data consistency you should run this logic inside a transaction. I think an implicit commit shouldn't occurred during these actions but you should try it before on some dummy data. Note that It will lock the database during the process.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Smurrlawa
Comment options

@noefleury
Comment options

@Smurrlawa
Comment options

Answer selected by Smurrlawa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants