Fixed issue with upgrading metadata table in AWS Redshift #1231 #1256
Conversation
Flyway couldn't upgrade the metadata table, due to the following error: "Amazon Invalid operation: cannot insert/update into table after dropping non-nullable column" This was caused by trying to remove the NOT NULL constraint on the version column by adding/dropping a temp columan and copying the values. For somae unknown reason, this works on some versions of Redshift, but not others. The solution is just to rename the original table, create a new one, copy the data, and drop the original table.
Redshift does not support indexes because it is a column-oriented database. Instead data can be physically stored sorted, to improve reading and sorting performance, based on the sort key.
This comment has been minimized.
This comment has been minimized.
Looks good to me. I just coded something very similar! I'll see if I can test your change instead. |
This comment has been minimized.
This comment has been minimized.
Tried it, failed on the table rename. Apparently renaming a table with the schema specified like this doesn't work (the dot in "schema"."table" is considered a syntax error), see:
for reports of a similar problem. Good news is that when I removed the schema, changing the line
to
then the script worked. That does leave open the possibility of mistakenly renaming a similarly named table in a different schema. Not a problem in my context but don't know if it would make others unhappy. Walter Here's the exception I got: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException: Script failedSQL State : 42601 |
This comment has been minimized.
This comment has been minimized.
Thanks for the feedback. I'm guessing it would also be possible to keep the schema in the old object name and just remove it from the new object name: ALTER TABLE "${schema}"."${table}" RENAME TO "${table}_flyway4_upgrade"; I pushed a new commit with just this change: 7050f3f |
…o 4.0 failed When renaming a table, the schema should not be specified in the new table name.
This comment has been minimized.
This comment has been minimized.
That should work fine. I don't have time to retest the full Flyway core right now, but I did confirm on our Redshift DB that while this command fails: alter table "public"."foo" rename to "public"."fizzle"; this one works - removing the schema qualifier only on the target table name: alter table "public"."foo" rename to "fizzle"; Thanks. |
Thanks Nathan! Merged. |
@nathanvick Could you please contact me by email at axel at boxfuse dot com ? Thanks! |
This fixes the issue where upgrading the metadata table (from Flyway v3.2.1 to v4.0) failed, for at least some installations of AWS Redshift. Redshift does not support altering columns within a table. There are two common workarounds for this:
This pull request changes the approach from "copying data between temp columns" to "copying data between temp tables" because the former approach requires a commit half way through the process, for some installations of Redshift.