Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollbacks are not supported for DDL statements. #301

Open
jokineno opened this issue Nov 13, 2024 · 0 comments
Open

Rollbacks are not supported for DDL statements. #301

jokineno opened this issue Nov 13, 2024 · 0 comments
Labels
question Further information is requested Workaround Issues that can be addressed via a workaround

Comments

@jokineno
Copy link

We use the schemachange library to run database migrations, and I would like to highlight a limitation: rollbacks are not supported for DDL operations like CREATE TABLE or ALTER TABLE statements because Snowflake executes these operations in their own separate transactions.

A possible workaround is to take a backup of resources using Snowflake's built-in CLONE feature (e.g., CREATE TABLE CLONE ) before running any migrations (SQL files containing one or multiple statements). If schemachange deploy returns an exit code 1, a rollback can be triggered by SWAPping the resources, such as tables, and then removing the backups. This approach would effectively revert the changes in case of any issues during the migration.

Anyone who has multiple role grants in the database resources should pay attention how those are impacted after CLONE/SWAP.

I believe adding a similar rollback mechanism as a wrapper around the deploy command could make the schemachange library more flexible and attractive to users. It would provide a much-needed safety net for DDL migrations, aligning with best practices for robust database management.

Also, I am happy to hear how others have solved rollback for DDL operations.

@jokineno jokineno added question Further information is requested Workaround Issues that can be addressed via a workaround labels Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Workaround Issues that can be addressed via a workaround
Projects
None yet
Development

No branches or pull requests

1 participant