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

"id" fields in goose_db_version are not unique #3

Open
kevinburke opened this issue Jan 7, 2020 · 0 comments
Open

"id" fields in goose_db_version are not unique #3

kevinburke opened this issue Jan 7, 2020 · 0 comments

Comments

@kevinburke
Copy link
Owner

kevinburke commented Jan 7, 2020

If you run "goose down" goose will write a new row to the database with is_applied set to false, so there will be two rows for the same version; one with is_applied true and a newer one with is_applied set to false.

The key to determining the application state is to look at the most recent row for each version. You likely want a query like this:

WITH most_recent_migration AS (
	SELECT DISTINCT ON (version_id) version_id, is_applied, id 
	FROM goose_db_version 
	ORDER BY version_id, id DESC
)
SELECT version_id FROM most_recent_migration
WHERE is_applied = true
ORDER BY id DESC

This is a bad pattern because it can easily lead to errors, however I'm not sure what to do about it.

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

No branches or pull requests

1 participant