1 package DBIx::Class::DeploymentHandler::Manual::CatalystIntro
3 # ABSTRACT: Introduction to using DBIx::Class::DeploymentHandler with a new Catalyst Project
9 This introduction will use PostgreSQL and L<Catalyst>. Background
10 information on using PostgreSQL with Catalyst can be found at
11 L<Catalyst::Manual::Tutorial::10_Appendices>. This guide will assume that
12 you have some understanding of Catalyst. Please go through the Catalyst
13 tutorials first if you have not yet done so.
17 Start by creating a user C<catalyst>, with password C<catalyst>
19 $ sudo -u postgres createuser -P catalyst
20 Enter password for new role: <catalyst>
21 Enter it again: <catalyst>
22 Shall the new role be a superuser? (y/n) n
23 Shall the new role be allowed to create databases? (y/n) n
24 Shall the new role be allowed to create more new roles? (y/n) n
26 Then create a new database called C<deploymentintro>
28 sudo -u postgres createdb -O catalyst deploymentintro
30 =head1 Create the project
32 $ catalyst.pl DeploymentIntro
36 =head1 Create the Schema
38 $ script/deploymentintro_create.pl model DB DBIC::Schema DeploymentIntro::Schema \
39 create=static 'dbi:Pg:dbname=deploymentintro' 'catalyst' 'catalyst' '{ AutoCommit => 1 }'
41 $ mkdir -p lib/Schema/Result
43 Remove the following from C<lib/DeploymentIntro/Model/DB.pm>:
46 dsn => 'dbi:Pg:dbname=deploymentintro',
48 password => 'catalyst',
52 Remove C<deploymentintro.conf> and create a new file called
53 C<deploymentintro_local.pl> with the following:
56 name => "DeploymentIntro",
59 schema_class => 'DeploymentIntro::Schema',
62 dsn => 'dbi:Pg:dbname=deploymentintro',
64 password => 'catalyst',
70 Copy the following program into scripts, under the name
71 C<deploymentintro_dbicdh.pl>
80 use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
82 use lib "$FindBin::Bin/../lib";
83 use DeploymentIntro::Schema;
86 my $config = Config::JFDI->new( name => 'DeploymentIntro' );
87 my $config_hash = $config->get;
88 my $connect_info = $config_hash->{"Model::DB"}{"connect_info"};
89 my $schema = DeploymentIntro::Schema->connect($connect_info);
93 script_directory => "$FindBin::Bin/../dbicdh",
94 databases => 'PostgreSQL',
103 die "Please update the version in Schema.pm"
104 if ( $dh->version_storage->version_rs->search({version => $dh->schema_version})->count );
106 die "We only support positive integers for versions around these parts."
107 unless $dh->schema_version =~ /^\d+$/;
110 $dh->prepare_upgrade;
114 sub current_version {
115 say $dh->database_version;
127 help unless $ARGV[0];
130 when ('install') { install() }
131 when ('upgrade') { upgrade() }
132 when ('current-version') { current_version() }
135 Copy the following files into C<lib/DeploymentIntro/Schema/Result>:
139 package DeploymentIntro::Schema::Result::Cd;
144 use parent 'DBIx::Class::Core';
146 __PACKAGE__->load_components(qw(InflateColumn::DateTime));
147 __PACKAGE__->table('cd');
149 __PACKAGE__->add_columns(
151 data_type => 'integer',
152 is_auto_increment => 1,
155 data_type => 'integer'
162 __PACKAGE__->set_primary_key('id');
164 __PACKAGE__->belongs_to(
165 artist => 'DeploymentIntro::Schema::Result::Artist', 'artist_id' );
167 __PACKAGE__->has_many(
168 tracks => 'DeploymentIntro::Schema::Result::Track', 'cd_id' );
175 package DeploymentIntro::Schema::Result::Artist;
180 use parent 'DBIx::Class::Core';
182 __PACKAGE__->table('artist');
184 __PACKAGE__->add_columns(
186 data_type => 'integer',
187 is_auto_increment => 1,
194 __PACKAGE__->set_primary_key('id');
196 __PACKAGE__->has_many(
197 cds => 'DeploymentIntro::Schema::Result::Cd', 'artist_id' );
204 package DeploymentIntro::Schema::Result::Track;
209 use parent 'DBIx::Class::Core';
211 __PACKAGE__->table('track');
213 __PACKAGE__->add_columns(
215 data_type => 'integer',
216 is_auto_increment => 1,
219 data_type => 'integer',
226 __PACKAGE__->set_primary_key('id');
228 __PACKAGE__->belongs_to(
229 cd => 'DeploymentIntro::Schema::Result::Cd', 'cd_id' );
234 And then edit C<lib/DeploymentIntro/Schema.pm> and add the following above the
239 Now it is just a matter of running
241 ./script/deploymentintro_dbicdh.pl install