Database schema management #6
Labels
No labels
bug
confirmed
critical
database
discussion
documentation
email-support
enhancement
feature
suggestion
support
warlock
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set.
Reference: hazaar/hazaar-mvc-old#6
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I had a thought about managing the PDO relational database schemas from inside Hazaar. Similar to how Ruby does it.
So, rather than just leaving it up to the developer to make sure their schema is correct, they can instead update a versioned definition file and then run hazaar migrate or something inside the app directory. This will bring it up to the latest version. A flag can perhaps also be set to allow rolling back to previous versions of the schema.
I need to do some more research on how best to handle this, but I think this would be very beneficial and be the start of trying to make apps just big self-contained bundles that can manage themselves.
As of
c8077a95a
this is pretty much working. Currently supported is:What needs to come next:
How it works
Initially you create a snapshot of the database schema. This stores the current layout of tables as they are in the database. Then, once any changes have been made to the database you can just snapshot the database again and it will store the new schema (to assist in initialising the database on new installs) as well as create a migration file for that snapshot.
Initialising a database
When installing an app, it's then possible to just run
to initialise the database to the latest schema version.
Updating a database to the latest schema version
If you already have a database set up and you have just updated the software you can simply run:
and the Hazaar Tool will replay any changes that have been made to the schema since the current running version.
Migrating to a specific version
Versions are, by default, in the format of yyyymmddhhmmss. For example: 20140306154709. To migrate to a specific version it is possible to execute:
and the Hazaar Tool will either replay or rollback automatically to that version, depending on whether that version is newer or older than the current running version.
Status changed to closed
mentioned in commit
d1df84bb24