charm icon indicating copy to clipboard operation
charm copied to clipboard

Add DB Versioning

Open dezren39 opened this issue 6 months ago • 0 comments

Hello

So I added a few features to the migration within charm so that I could feel safe using and merging code while also adding my own migrations. I've attempted to make a 'clean' pr that you could potentially use. I've confirmed this 'builds' and I confirmed my fork works ok, but I didn't 'battle-test' this exact branch. One specific thing I didn't test, I tried to revert my changes to allow libsql driver #250, I didn't test this. if you merge #250 or this pr, the other may need updates. Additionally, I assume you have an existing charm database, you may want to make a patch to add the version table and existing migrations already, although all the current migrations seem to be very safe, (if not exists type of things).

I know this may not be exactly the direction you want to take your tool, so please do close this or suggest any changes you would like. In my other projects I'm using goose, but you had rolled your own so I added to the existing structure. I believe this wouldn't be needed with minimal changes or only changes that are additions/mostly complementary. This is a start towards some safeguards I've become used to from using dedicated tools for these type of things.

  • validate incremental versions in code, starting from 1 until end
  • insert version, run transaction which completes version, if err then insert err into table
  • check version on boot, if no version table, init db, else note if migration is possible or incomplete version exists then error
  • make initial create tables a migration like other migrations (increment fk migration from 1 to 2)
  • init db and serve migrate now use same 'migrate' function
  • log.Print -> log.Info, started using log.Error

is there a way to enable debug mode within charm serve? charm_debug or charm_serve_debug or something? or charm(_serve)(_log)_level?

dezren39 avatar Jan 05 '24 03:01 dezren39