Database schema management #6

Closed
opened 2014-02-26 04:25:46 +00:00 by jamie · 3 comments
jamie commented 2014-02-26 04:25:46 +00:00 (Migrated from git.hazaar.io)

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.

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.
jamie commented 2014-03-06 04:40:49 +00:00 (Migrated from git.hazaar.io)

As of c8077a95a this is pretty much working. Currently supported is:

  • Addeding tables
  • Removing tables
  • Renaming tables
  • Adding columns to tables
  • Removing columns from tables

What needs to come next:

  • Support for indexes

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

hazaar migrate db

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:

hazaar migrate db

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:

hazaar migrate db 20140306154709

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.

As of c8077a95a this is pretty much working. Currently supported is: * Addeding tables * Removing tables * Renaming tables * Adding columns to tables * Removing columns from tables What needs to come next: * Support for indexes # 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 ``` hazaar migrate db ``` 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: ``` hazaar migrate db ``` 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: ``` hazaar migrate db 20140306154709 ``` 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.
jamie commented 2014-03-14 05:33:08 +00:00 (Migrated from git.hazaar.io)

Status changed to closed

Status changed to closed
jamie commented 2015-12-03 02:27:10 +00:00 (Migrated from git.hazaar.io)

mentioned in commit d1df84bb24

mentioned in commit d1df84bb240936d97aaa0069138ba7535feb4435
Commenting is not possible because the repository is archived.
No milestone
No project
No assignees
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: hazaar/hazaar-mvc-old#6
No description provided.