From: Arthur Axel 'fREW' Schmidt Date: Sat, 10 Jul 2010 08:58:35 +0000 (-0500) Subject: rearrange tutorial and codebits X-Git-Tag: v0.001003~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-DeploymentHandler.git;a=commitdiff_plain;h=adae121b124b0b8128473ffdcca7af07de5d31ad rearrange tutorial and codebits --- diff --git a/lib/DBIx/Class/DeploymentHandler/Manual/CatalystIntro.pod b/lib/DBIx/Class/DeploymentHandler/Manual/CatalystIntro.pod index 47284ab..59d6f53 100644 --- a/lib/DBIx/Class/DeploymentHandler/Manual/CatalystIntro.pod +++ b/lib/DBIx/Class/DeploymentHandler/Manual/CatalystIntro.pod @@ -2,61 +2,55 @@ package DBIx::Class::DeploymentHandler::Manual::CatalystIntro # ABSTRACT: Introduction to using DBIx::Class::DeploymentHandler with a new Catalyst Project - -__END__ =pod -=head1 NAME - -DBIx::Class::DeploymentHandler::Manual::CatalystIntro - Introduction to using DBIx::Class::DeploymentHandler with a new Catalyst Project - =head1 Background -This introduction will use PostgreSQL and Catalyst. Background information on using PostgreSQL with Catalyst can be found at L. 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. +This introduction will use PostgreSQL and L. Background +information on using PostgreSQL with Catalyst can be found at +L. 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. =head1 Database Setup -Start by creating a user catalyst, with password catalyst +Start by creating a user C, with password C - $ sudo -u postgres createuser -P catalyst - Enter password for new role: - Enter it again: - Shall the new role be a superuser? (y/n) n - Shall the new role be allowed to create databases? (y/n) n - Shall the new role be allowed to create more new roles? (y/n) n + $ sudo -u postgres createuser -P catalyst + Enter password for new role: + Enter it again: + Shall the new role be a superuser? (y/n) n + Shall the new role be allowed to create databases? (y/n) n + Shall the new role be allowed to create more new roles? (y/n) n -Then create a new database, deploymentintro +Then create a new database called C - sudo -u postgres createdb -O catalyst deploymentintro + sudo -u postgres createdb -O catalyst deploymentintro =head1 Create the project - $ catalyst.pl DeploymentIntro - $ cd DeploymentIntro - $ perl Makefile.PL + $ catalyst.pl DeploymentIntro + $ cd DeploymentIntro + $ perl Makefile.PL =head1 Create the Schema - $ script/deploymentintro_create.pl model DB DBIC::Schema DeploymentIntro::Schema \ - create=static 'dbi:Pg:dbname=deploymentintro' 'catalyst' 'catalyst' '{ AutoCommit => 1 }' + $ script/deploymentintro_create.pl model DB DBIC::Schema DeploymentIntro::Schema \ + create=static 'dbi:Pg:dbname=deploymentintro' 'catalyst' 'catalyst' '{ AutoCommit => 1 }' - $ mkdir lib/Schema - $ mkdir lib/Schema/Result + $ mkdir -p lib/Schema/Result -Edit out the following from lib/DeploymentIntro/Model/DB.pm: +Remove the following from C: - __PACKAGE__->config( - schema_class => 'DeploymentIntro::Schema', - - connect_info => { - dsn => 'dbi:Pg:dbname=deploymentintro', - user => 'catalyst', - password => 'catalyst', - AutoCommit => q{1}, - } - ); + connect_info => { + dsn => 'dbi:Pg:dbname=deploymentintro', + user => 'catalyst', + password => 'catalyst', + AutoCommit => q{1}, + } -Remove deploymentintro.conf and create a new file, deploymentintro_local.pl with the following: +Remove C and create a new file called +C with the following: { name => "DeploymentIntro", @@ -68,137 +62,182 @@ Remove deploymentintro.conf and create a new file, deploymentintro_local.pl with dsn => 'dbi:Pg:dbname=deploymentintro', user => 'catalyst', password => 'catalyst', - AutoCommit => q{1}, + AutoCommit => 1, } } } -Copy the following program into scripts, under the name deploymentintro_dbicdh.pl - - #!/usr/bin/env perl - use strict; - use warnings; - use feature ":5.10"; - use aliased 'DBIx::Class::DeploymentHandler' => 'DH'; - use FindBin; - use lib "$FindBin::Bin/../lib"; - use DeploymentIntro::Schema; - use Config::JFDI; - my $config = Config::JFDI->new( name => 'DeploymentIntro' ); - my $config_hash = $config->get; - my $connect_info = $config_hash->{"Model::DB"}{"connect_info"}; - my $schema = DeploymentIntro::Schema->connect($connect_info); - - my $dh = DH->new( - { - schema => $schema, - script_directory => "$FindBin::Bin/../dbicdh", - databases => 'PostgreSQL', - } - ); +Copy the following program into scripts, under the name +C - sub install { - $dh->prepare_install; - $dh->install; - } + #!/usr/bin/env perl - sub upgrade { - die "Please set the version in Schema.pm" - unless $dh->schema->schema_version; - die "Please update the version in Schema.pm" - if ( $dh->version_storage->version_rs->search({version => $dh->schema_version})->count ); - die "We only support positive integers for versions around these parts." - unless $dh->schema_version =~ /^\d+$/; - - $dh->prepare_deploy; - $dh->prepare_upgrade; - $dh->upgrade; - } + use strict; + use warnings; - sub current_version { - print $dh->database_version. "\n"; - } + use feature ":5.10"; - sub help { + use aliased 'DBIx::Class::DeploymentHandler' => 'DH'; + use FindBin; + use lib "$FindBin::Bin/../lib"; + use DeploymentIntro::Schema; + use Config::JFDI; - print qq/ - usage: - install - upgrade - upgrade-to [version] - downgrade-to [version] - current-version - /; + my $config = Config::JFDI->new( name => 'DeploymentIntro' ); + my $config_hash = $config->get; + my $connect_info = $config_hash->{"Model::DB"}{"connect_info"}; + my $schema = DeploymentIntro::Schema->connect($connect_info); - } + my $dh = DH->new({ + schema => $schema, + script_directory => "$FindBin::Bin/../dbicdh", + databases => 'PostgreSQL', + }); - help unless $ARGV[0]; + sub install { + $dh->prepare_install; + $dh->install; + } - given ( $ARGV[0] ) { - when ("install") { install(); } - when ("upgrade") { upgrade(); } - when ("current-version") { current_version(); } - } + sub upgrade { + die "Please set the version in Schema.pm" + unless $dh->schema->schema_version; + die "Please update the version in Schema.pm" + if ( $dh->version_storage->version_rs->search({version => $dh->schema_version})->count ); + die "We only support positive integers for versions around these parts." + unless $dh->schema_version =~ /^\d+$/; + + $dh->prepare_deploy; + $dh->prepare_upgrade; + $dh->upgrade; + } + + sub current_version { + say $dh->database_version; + } + + sub help { + say <<'OUT'; + usage: + install + upgrade + current-version + OUT + } + + help unless $ARGV[0]; + + given ( $ARGV[0] ) { + when ('install') { install() } + when ('upgrade') { upgrade() } + when ('current-version') { current_version() } + } + +Copy the following files into C: + +C + + package DeploymentIntro::Schema::Result::Cd; + + use strict; + use warnings; + + use parent 'DBIx::Class::Core'; + + __PACKAGE__->load_components(qw(InflateColumn::DateTime)); + __PACKAGE__->table('cd'); + + __PACKAGE__->add_columns( + id => { + data_type => 'integer', + is_auto_increment => 1, + }, + artist_id => { + data_type => 'integer' + }, + title => { + data_type => 'text' + }, + ); + + __PACKAGE__->set_primary_key('id'); + + __PACKAGE__->belongs_to( + artist => 'DeploymentIntro::Schema::Result::Artist', 'artist_id' ); + + __PACKAGE__->has_many( + tracks => 'DeploymentIntro::Schema::Result::Track', 'cd_id' ); + + 1; + + +C + + package DeploymentIntro::Schema::Result::Artist; + + use strict; + use warnings; + + use parent 'DBIx::Class::Core'; + + __PACKAGE__->table('artist'); + + __PACKAGE__->add_columns( + id => { + data_type => 'integer', + is_auto_increment => 1, + }, + name => { + data_type => 'text' + }, + ); -Copy the following files into lib/DeploymentIntro/Schema/Result + __PACKAGE__->set_primary_key('id'); -Cd.pm + __PACKAGE__->has_many( + cds => 'DeploymentIntro::Schema::Result::Cd', 'artist_id' ); - package DeploymentIntro::Schema::Result::Cd; - use base qw/DBIx::Class::Core/; - __PACKAGE__->load_components(qw/InflateColumn::DateTime/); - __PACKAGE__->table('cd'); - __PACKAGE__->add_columns( - 'cdid', { data_type => 'integer' }, - 'artist', { data_type => 'integer' }, - 'title', { data_type => 'text' } - ); - __PACKAGE__->set_primary_key('cdid'); - __PACKAGE__->belongs_to( - 'artist' => 'DeploymentIntro::Schema::Result::Artist' ); - __PACKAGE__->has_many( 'tracks' => 'DeploymentIntro::Schema::Result::Track' ); + 1; - 1; +C -Artist.pm + package DeploymentIntro::Schema::Result::Track; - package DeploymentIntro::Schema::Result::Artist; - use base qw/DBIx::Class::Core/; - __PACKAGE__->table('artist'); - __PACKAGE__->add_columns( - 'artistid', { data_type => 'integer' }, - 'name', { data_type => 'text' } - ); - __PACKAGE__->set_primary_key('artistid'); - __PACKAGE__->has_many( 'cds' => 'DeploymentIntro::Schema::Result::Cd' ); + use strict; + use warnings; - 1; + use parent 'DBIx::Class::Core'; + __PACKAGE__->table('track'); -Track.pm + __PACKAGE__->add_columns( + id => { + data_type => 'integer', + is_auto_increment => 1, + }, + cd_id => { + data_type => 'integer', + }, + title => { + data_type => 'text', + } + ); - package DeploymentIntro::Schema::Result::Track; - use base qw/DBIx::Class::Core/; - __PACKAGE__->table('track'); - __PACKAGE__->add_columns( - 'trackid', { data_type => 'integer' }, - 'cd', { data_type => 'integer' }, - 'title', { data_type => 'text' } - ); - __PACKAGE__->set_primary_key('trackid'); - __PACKAGE__->belongs_to( 'cd' => 'DeploymentIntro::Schema::Result::Cd' ); + __PACKAGE__->set_primary_key('id'); - 1; + __PACKAGE__->belongs_to( + cd => 'DeploymentIntro::Schema::Result::Cd', 'cd_id' ); + 1; -And then edit lib/DeploymentIntro/Schema.pm and add the following above the 1 at the bottom - use vars qw($VERSION); - $VERSION = "1"; +And then edit C and add the following above the +1 at the bottom + our $VERSION = 1; Now it is just a matter of running - ./script/deploymentintro_dbicdh.pl install + ./script/deploymentintro_dbicdh.pl install