3 DBIx::Class::DeploymentHandler::Intro - Introduction to DBIx::Class::DeploymentHandler
5 =head1 Why DBIx::Class::DeploymentHandler is worth using
8 =head1 Our Sample database
10 Follow L<DBIx::Class::Manual::Intro> except for the parts setting up the database.
11 After you are done, You should have the following files.
24 Our first script, preinstall.pl reads our schema file and creates the tables in the database.
26 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
28 use lib "$FindBin::Bin/../lib";
30 my $schema = MyDatabase::Main->connect('dbi:SQLite:mydb');
35 script_directory => "$FindBin::Bin/dbicdh",
36 databases => 'SQLite',
37 sql_translator_args => { add_drop_table => 0 },
43 $dh->install({version => 1});
47 Someone really ought to fix the bug causing dbicdh/SQLite/deploy/1/001-auto.sql to have the dbix_class_deploymenthandler_versions
49 Right now, you need to comment out the version table crap in the sql file , then run install, then uncomment it.
53 =head2 dbicdh - Our migration scripts
55 Running preinstall.pl should create the following:
69 DBIx::Class::DeploymentHandler automatically generates SQL from our schema that is suitable for SQLite
73 This contains all of the raw information about our schema that is then translated into the sql.
77 Add a line to MyDatabase/Main/Result/Cd.pm below
79 __PACKAGE__->add_columns(qw/ cdid artist title /);
83 __PACKAGE__->add_column("isbn" => { is_nullable => 1 });
85 (We need it to either be nullable, or have a default - merely adding it to the add_columns line will not work)
87 Then run the following script:
91 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
93 use lib "$FindBin::Bin/../lib";
95 my $schema = MyDatabase::Main->connect('dbi:SQLite:mydb');
100 script_directory => "$FindBin::Bin/dbicdh",
101 databases => 'SQLite',
102 sql_translator_args => { add_drop_table => 0 },
110 $dh->prepare_upgrade({ from_version => 1, to_version => 2});
115 Our script directory now looks like:
121 | | | `-- 001-auto.sql
134 The new deploy/001-auto.sql and deploy/001-auto.yml files are the state of the db as at that version. The upgrade/1-2/001-auto.sql file is the most interesting one
136 -- Convert schema '/home/jdobbie/Projects/intro/dbicdh/_source/deploy/1/001-auto.yml' to '/home/jdobbie/Projects/intro/dbicdh/_source/deploy/2/001-auto.yml':;
142 ALTER TABLE cd ADD COLUMN isbn;