You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've recently discussed the topic of database migrations on the redbean Discord.
You've provided a helpful example to me and agreed that the upgrade method isn't documented well enough. This was the example:
localdbm=fm.makeStorage(DBNAME, SQLSETUP)
localchanges, cherr=dbm:upgrade()
ifnotchangesthen-- execute VACUUM, which may fix some integrity errors and retry-- change errors are reported later, if VACUUM fixed the issuedbm:execute("VACUUM")
changes=assert(dbm:upgrade())
end-- the rest of the module code-- log the error that was resolved (as a warning)ifcherrthenfm.logWarn("upgraded DB with errors resolved: "..cherr) endif#changes>0thenfm.logWarn("upgraded DB to v%s\n%s",
dbm:fetchOne("PRAGMA user_version").user_version,
table.concat(changes, ";\n"))
end
This was the comment (message) you've sent to me alongside the example.
I include PRAGMA user_version=<version>; in the script itself and increment it as needed (just for my reference in case I need to troubleshoot the issue or ask what DB version is in place). It's also logged after a successful upgrade.
The initial setup is no different from any subsequent one; you just write whatever your current version expects to have in the SQLSETUP script (that is passed to makeStorage) and upgrade is supposed to take care of the rest (with some limitations).
I've created this issue for the purpose of potential further discussions on this topic and so that it doesn't get forgotten. I hope you don't mind, otherwise feel free to close it.
Thanks!
The text was updated successfully, but these errors were encountered:
Hi Paul,
We've recently discussed the topic of database migrations on the redbean Discord.
You've provided a helpful example to me and agreed that the
upgrade
method isn't documented well enough. This was the example:This was the comment (message) you've sent to me alongside the example.
I've created this issue for the purpose of potential further discussions on this topic and so that it doesn't get forgotten. I hope you don't mind, otherwise feel free to close it.
Thanks!
The text was updated successfully, but these errors were encountered: