[Catalyst] DBIx::Migration released
Sebastian Riedel
sri at oook.de
Mon Oct 24 02:28:16 CEST 2005
You know the problem, you've got a Catalyst app installed on multiple
servers, now you have to update them all.
Updating the Perl modules is quite easy, but the database schema
changed! What now?
To prevent this problem completely there is now DBIx::Migration.
You can think of it as database schema revisions.
Everything starts at revision 1 for the first release, then you add a
new revision for the following ones.
So you don't build a new schema, you extend/change the previous one.
The files are plain sql and can contain whatever your db supports,
only the filename is important, it has to end in _VERSION_TYPE.sql
Here's a simple example that supports up- and downgrades:
# /Users/sri/myapp/db/sqlite/schema_1_up.sql
CREATE TABLE foo (
id INTEGER PRIMARY KEY,
bar TEXT
);
# /Users/sri/myapp/db/sqlite/schema_1_down.sql
DROP TABLE foo;
# /Users/sri/myapp/db/sqlite/schema_2_up.sql
CREATE TABLE bar (
id INTEGER PRIMARY KEY,
baz TEXT
);
# /Users/sri/myapp/db/sqlite/schema_2_down.sql
DROP TABLE bar;
You don't have to use the module api directly, there is also a
command line tool.
# Initialize database with version 1
dbix-migration.pl dbi:SQLite:/Users/sri/myapp/db/sqlite.db /
Users/sri/myapp/db/sqlite 1
# Upgrade database to version 2
dbix-migration.pl dbi:SQLite:/Users/sri/myapp/db/sqlite.db /
Users/sri/myapp/db/sqlite 2
# Downgrade to version 0 (meaning uninstall)
dbix-migration.pl dbi:SQLite:/Users/sri/myapp/db/sqlite.db /
Users/sri/myapp/db/sqlite 0
Downgrades are just a goodie, you don't have to use them, but they
could be quite useful during development.
--
sebastian
More information about the Catalyst
mailing list