1 package DBIx::Class::DeploymentHandler::Manual::CatalystIntro
3 # ABSTRACT: Introduction to using DBIx::Class::DeploymentHandler with a new Catalyst Project
11 DBIx::Class::DeploymentHandler::Manual::CatalystIntro - Introduction to using DBIx::Class::DeploymentHandler with a new Catalyst Project
15 This introduction will use PostgreSQL and Catalyst. Background information on using PostgreSQL with Catalyst can be found at L<Catalyst::Manual::Tutorial::10_Appendices>. This guide will assume that you have some understanding of Catalyst. Please go through the Catalyst tutorials first, if you have not yet done so.
19 Start by creating a user catalyst, with password catalyst
21 $ sudo -u postgres createuser -P catalyst
22 Enter password for new role: <catalyst>
23 Enter it again: <catalyst>
24 Shall the new role be a superuser? (y/n) n
25 Shall the new role be allowed to create databases? (y/n) n
26 Shall the new role be allowed to create more new roles? (y/n) n
28 Then create a new database, deploymentintro
30 sudo -u postgres createdb -O catalyst deploymentintro
32 =head1 Create the project
34 $ catalyst.pl DeploymentIntro
38 =head1 Create the Schema
40 $ script/deploymentintro_create.pl model DB DBIC::Schema DeploymentIntro::Schema \
41 create=static 'dbi:Pg:dbname=deploymentintro' 'catalyst' 'catalyst' '{ AutoCommit => 1 }'
44 $ mkdir lib/Schema/Result
46 Edit out the following from lib/DeploymentIntro/Model/DB.pm:
49 schema_class => 'DeploymentIntro::Schema',
52 dsn => 'dbi:Pg:dbname=deploymentintro',
54 password => 'catalyst',
59 Remove deploymentintro.conf and create a new file, deploymentintro_local.pl with the following:
62 name => "DeploymentIntro",
65 schema_class => 'DeploymentIntro::Schema',
68 dsn => 'dbi:Pg:dbname=deploymentintro',
70 password => 'catalyst',
76 Copy the following program into scripts, under the name deploymentintro_dbicdh.pl
82 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
84 use lib "$FindBin::Bin/../lib";
85 use DeploymentIntro::Schema;
87 my $config = Config::JFDI->new( name => 'DeploymentIntro' );
88 my $config_hash = $config->get;
89 my $connect_info = $config_hash->{"Model::DB"}{"connect_info"};
90 my $schema = DeploymentIntro::Schema->connect($connect_info);
95 script_directory => "$FindBin::Bin/../dbicdh",
96 databases => 'PostgreSQL',
101 $dh->prepare_install;
106 die "Please set the version in Schema.pm"
107 unless $dh->schema->schema_version;
108 die "Please update the version in Schema.pm"
109 if ( $dh->version_storage->version_rs->search({version => $dh->schema_version})->count );
110 die "We only support positive integers for versions around these parts."
111 unless $dh->schema_version =~ /^\d+$/;
114 $dh->prepare_upgrade;
118 sub current_version {
119 print $dh->database_version. "\n";
129 downgrade-to [version]
135 help unless $ARGV[0];
138 when ("install") { install(); }
139 when ("upgrade") { upgrade(); }
140 when ("current-version") { current_version(); }
143 Copy the following files into lib/DeploymentIntro/Schema/Result
147 package DeploymentIntro::Schema::Result::Cd;
148 use base qw/DBIx::Class::Core/;
149 __PACKAGE__->load_components(qw/InflateColumn::DateTime/);
150 __PACKAGE__->table('cd');
151 __PACKAGE__->add_columns(
152 'cdid', { data_type => 'integer' },
153 'artist', { data_type => 'integer' },
154 'title', { data_type => 'text' }
156 __PACKAGE__->set_primary_key('cdid');
157 __PACKAGE__->belongs_to(
158 'artist' => 'DeploymentIntro::Schema::Result::Artist' );
159 __PACKAGE__->has_many( 'tracks' => 'DeploymentIntro::Schema::Result::Track' );
166 package DeploymentIntro::Schema::Result::Artist;
167 use base qw/DBIx::Class::Core/;
168 __PACKAGE__->table('artist');
169 __PACKAGE__->add_columns(
170 'artistid', { data_type => 'integer' },
171 'name', { data_type => 'text' }
173 __PACKAGE__->set_primary_key('artistid');
174 __PACKAGE__->has_many( 'cds' => 'DeploymentIntro::Schema::Result::Cd' );
181 package DeploymentIntro::Schema::Result::Track;
182 use base qw/DBIx::Class::Core/;
183 __PACKAGE__->table('track');
184 __PACKAGE__->add_columns(
185 'trackid', { data_type => 'integer' },
186 'cd', { data_type => 'integer' },
187 'title', { data_type => 'text' }
189 __PACKAGE__->set_primary_key('trackid');
190 __PACKAGE__->belongs_to( 'cd' => 'DeploymentIntro::Schema::Result::Cd' );
195 And then edit lib/DeploymentIntro/Schema.pm and add the following above the 1 at the bottom
197 use vars qw($VERSION);
201 Now it is just a matter of running
203 ./script/deploymentintro_dbicdh.pl install