Skip to content

fix(database/mysql): drop views in Drop() - #1454

Open
dannyshafer wants to merge 1 commit into
golang-migrate:masterfrom
dannyshafer:fix-847-mysql-drop-views
Open

dannyshafer wants to merge 1 commit into
golang-migrate:masterfrom
dannyshafer:fix-847-mysql-drop-views

Conversation

@dannyshafer

Copy link
Copy Markdown

Fixes #847

Drop() for MySQL lists objects with SHOW TABLES and runs DROP TABLE IF EXISTS on each one. SHOW TABLES also returns views, but DROP TABLE IF EXISTS on a view only produces a warning, so views survived migrate ... drop -f.

This switches to SHOW FULL TABLES, which also returns Table_type, and drops views with DROP VIEW IF EXISTS before dropping the base tables as before.

Testing

  • Added TestDropViews in database/mysql/mysql_test.go: creates a table and a view on it, calls Drop(), and checks that information_schema.tables has nothing left for the schema. It fails on master (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).

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
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 54.957%. first build — dannyshafer:fix-847-mysql-drop-views into golang-migrate:master

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate cli mysql drop does not delete views

3 participants