Repository navigation
fix(database/mysql): drop views in Drop() - #1454
Open
dannyshafer wants to merge 1 commit into
Open
dannyshafer wants to merge 1 commit into
dannyshafer wants to merge 1 commit into
Conversation
SHOW TABLES also lists views, but DROP TABLE IF EXISTS on a view only raises a warning and leaves the view in place, so `migrate drop` left views behind. List objects with SHOW FULL TABLES and drop views with DROP VIEW before dropping the tables. Fixes golang-migrate#847
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #847
Drop()for MySQL lists objects withSHOW TABLESand runsDROP TABLE IF EXISTSon each one.SHOW TABLESalso returns views, butDROP TABLE IF EXISTSon a view only produces a warning, so views survivedmigrate ... drop -f.This switches to
SHOW FULL TABLES, which also returnsTable_type, and drops views withDROP VIEW IF EXISTSbefore dropping the base tables as before.Testing
TestDropViewsindatabase/mysql/mysql_test.go: creates a table and a view on it, callsDrop(), and checks thatinformation_schema.tableshas nothing left for the schema. It fails onmaster(found 1) and passes with this change.go test ./database/mysql/passes locally against mysql 8.0, 8.4 and 9.0 (including the ANSI_QUOTES variants).golangci-lint run ./database/mysql/...reports 0 issues.This change was prepared with AI assistance (Claude Code).