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

Assert All Migrations Have Been Run? #711

Open
cycomachead opened this issue Nov 6, 2020 · 2 comments
Open

Assert All Migrations Have Been Run? #711

cycomachead opened this issue Nov 6, 2020 · 2 comments

Comments

@cycomachead
Copy link
Contributor

Would there be interest in a feature that ensures all migrations have been run before contenting to load the app?
I am essentially thinking that every key in the migrations file should be present in the lapis_migrations table.

I'm not sure if I'll do this soon, but I would be happy to attempt a PR at some point. :)

@karai17
Copy link

karai17 commented Nov 19, 2020

I believe Lapis currently executes migrations until it finishes all migrations or hits an error, at which point it bails and continues on loading the app. Halting app load if migrations fail would probably be a nice feature to add but a larger issue is that migrations do not currently use transactions so if a migration function fails, it permanently fails and gets skipped if attempting to re-run migrations. furthermore, the half-executed migration is not rolled back leading to a lot of manual tinkering during development which is most certainly a pain.

If you or anyone else is planning to poke at migrations, I'd request wrapping each migration function in a transaction BEFORE that function gets added to the executed list so that if it fails, it can be completely rolled back to the last successful function.

return {
   [1] = function()
      db.query("select * from users")
   end,

   [2] = function()
      db.query("select * from hurray for syntax errors!")
   end
}

in the above migration, what i would expect would be:

TRANSACTION

INSERT INTO migrations (func) VALUES (1)

> execute function

if success then
   COMMIT
else
   ROLLBACK
end


TRANSACTION

INSERT INTO migrations (func) VALUES (2)

> execute function

if success then
   COMMIT
else
   ROLLBACK
end

@leafo
Copy link
Owner

leafo commented Feb 10, 2023

I could see there maybe being an --assert-migrations flag on the lapis server and lapis build commands, this would fail to start/send signal to server unless it's confirmed that migrations have been run

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

3 participants