.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "DBIx::Class::DeploymentHandler::Manual::CatalystIntro 3pm" .TH DBIx::Class::DeploymentHandler::Manual::CatalystIntro 3pm "2018-01-13" "perl v5.26.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DBIx::Class::DeploymentHandler::Manual::CatalystIntro \- Introduction to using DBIx::Class::DeploymentHandler with a new Catalyst Project .SH "Background" .IX Header "Background" This introduction will use PostgreSQL and Catalyst. Background information on using PostgreSQL with Catalyst can be found at 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. .SH "Database Setup" .IX Header "Database Setup" Start by creating a user \f(CW\*(C`catalyst\*(C'\fR, with password \f(CW\*(C`catalyst\*(C'\fR .PP .Vb 6 \& $ 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 .Ve .PP Then create a new database called \f(CW\*(C`deploymentintro\*(C'\fR .PP .Vb 1 \& sudo \-u postgres createdb \-O catalyst deploymentintro .Ve .SH "Create the project" .IX Header "Create the project" .Vb 3 \& $ catalyst.pl DeploymentIntro \& $ cd DeploymentIntro \& $ perl Makefile.PL .Ve .SH "Create the Schema" .IX Header "Create the Schema" .Vb 2 \& $ script/deploymentintro_create.pl model DB DBIC::Schema DeploymentIntro::Schema \e \& create=static \*(Aqdbi:Pg:dbname=deploymentintro\*(Aq \*(Aqcatalyst\*(Aq \*(Aqcatalyst\*(Aq \*(Aq{ AutoCommit => 1 }\*(Aq \& \& $ mkdir \-p lib/Schema/Result .Ve .PP Remove the following from \f(CW\*(C`lib/DeploymentIntro/Model/DB.pm\*(C'\fR: .PP .Vb 6 \& connect_info => { \& dsn => \*(Aqdbi:Pg:dbname=deploymentintro\*(Aq, \& user => \*(Aqcatalyst\*(Aq, \& password => \*(Aqcatalyst\*(Aq, \& AutoCommit => q{1}, \& } .Ve .PP Remove \f(CW\*(C`deploymentintro.conf\*(C'\fR and create a new file called \&\f(CW\*(C`deploymentintro_local.pl\*(C'\fR with the following: .PP .Vb 2 \& { \& name => "DeploymentIntro", \& \& "Model::DB" => { \& schema_class => \*(AqDeploymentIntro::Schema\*(Aq, \& \& connect_info => { \& dsn => \*(Aqdbi:Pg:dbname=deploymentintro\*(Aq, \& user => \*(Aqcatalyst\*(Aq, \& password => \*(Aqcatalyst\*(Aq, \& AutoCommit => 1, \& } \& } \& } .Ve .PP Copy the following program into scripts, under the name \&\f(CW\*(C`deploymentintro_dbicdh.pl\*(C'\fR .PP .Vb 1 \& #!/usr/bin/env perl \& \& use strict; \& use warnings; \& \& use feature ":5.10"; \& \& use aliased \*(AqDBIx::Class::DeploymentHandler\*(Aq => \*(AqDH\*(Aq; \& use FindBin; \& use lib "$FindBin::Bin/../lib"; \& use DeploymentIntro::Schema; \& use Config::JFDI; \& \& my $config = Config::JFDI\->new( name => \*(AqDeploymentIntro\*(Aq ); \& 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 => \*(AqPostgreSQL\*(Aq, \& }); \& \& sub install { \& $dh\->prepare_install; \& $dh\->install; \& } \& \& sub upgrade { \& 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 =~ /^\ed+$/; \& \& $dh\->prepare_deploy; \& $dh\->prepare_upgrade; \& $dh\->upgrade; \& } \& \& sub current_version { \& say $dh\->database_version; \& } \& \& sub help { \& say <<\*(AqOUT\*(Aq; \& usage: \& install \& upgrade \& current\-version \& OUT \& } \& \& help unless $ARGV[0]; \& \& given ( $ARGV[0] ) { \& when (\*(Aqinstall\*(Aq) { install() } \& when (\*(Aqupgrade\*(Aq) { upgrade() } \& when (\*(Aqcurrent\-version\*(Aq) { current_version() } \& } .Ve .PP Copy the following files into \f(CW\*(C`lib/DeploymentIntro/Schema/Result\*(C'\fR: .PP \&\f(CW\*(C`Cd.pm\*(C'\fR .PP .Vb 1 \& package DeploymentIntro::Schema::Result::Cd; \& \& use strict; \& use warnings; \& \& use parent \*(AqDBIx::Class::Core\*(Aq; \& \& _\|_PACKAGE_\|_\->load_components(qw(InflateColumn::DateTime)); \& _\|_PACKAGE_\|_\->table(\*(Aqcd\*(Aq); \& \& _\|_PACKAGE_\|_\->add_columns( \& id => { \& data_type => \*(Aqinteger\*(Aq, \& is_auto_increment => 1, \& }, \& artist_id => { \& data_type => \*(Aqinteger\*(Aq \& }, \& title => { \& data_type => \*(Aqtext\*(Aq \& }, \& ); \& \& _\|_PACKAGE_\|_\->set_primary_key(\*(Aqid\*(Aq); \& \& _\|_PACKAGE_\|_\->belongs_to( \& artist => \*(AqDeploymentIntro::Schema::Result::Artist\*(Aq, \*(Aqartist_id\*(Aq ); \& \& _\|_PACKAGE_\|_\->has_many( \& tracks => \*(AqDeploymentIntro::Schema::Result::Track\*(Aq, \*(Aqcd_id\*(Aq ); \& \& 1; .Ve .PP \&\f(CW\*(C`Artist.pm\*(C'\fR .PP .Vb 1 \& package DeploymentIntro::Schema::Result::Artist; \& \& use strict; \& use warnings; \& \& use parent \*(AqDBIx::Class::Core\*(Aq; \& \& _\|_PACKAGE_\|_\->table(\*(Aqartist\*(Aq); \& \& _\|_PACKAGE_\|_\->add_columns( \& id => { \& data_type => \*(Aqinteger\*(Aq, \& is_auto_increment => 1, \& }, \& name => { \& data_type => \*(Aqtext\*(Aq \& }, \& ); \& \& _\|_PACKAGE_\|_\->set_primary_key(\*(Aqid\*(Aq); \& \& _\|_PACKAGE_\|_\->has_many( \& cds => \*(AqDeploymentIntro::Schema::Result::Cd\*(Aq, \*(Aqartist_id\*(Aq ); \& \& 1; .Ve .PP \&\f(CW\*(C`Track.pm\*(C'\fR .PP .Vb 1 \& package DeploymentIntro::Schema::Result::Track; \& \& use strict; \& use warnings; \& \& use parent \*(AqDBIx::Class::Core\*(Aq; \& \& _\|_PACKAGE_\|_\->table(\*(Aqtrack\*(Aq); \& \& _\|_PACKAGE_\|_\->add_columns( \& id => { \& data_type => \*(Aqinteger\*(Aq, \& is_auto_increment => 1, \& }, \& cd_id => { \& data_type => \*(Aqinteger\*(Aq, \& }, \& title => { \& data_type => \*(Aqtext\*(Aq, \& } \& ); \& \& _\|_PACKAGE_\|_\->set_primary_key(\*(Aqid\*(Aq); \& \& _\|_PACKAGE_\|_\->belongs_to( \& cd => \*(AqDeploymentIntro::Schema::Result::Cd\*(Aq, \*(Aqcd_id\*(Aq ); \& \& 1; .Ve .PP And then edit \f(CW\*(C`lib/DeploymentIntro/Schema.pm\*(C'\fR and add the following above the 1 at the bottom .PP .Vb 1 \& our $VERSION = 1; .Ve .PP Now it is just a matter of running .PP .Vb 1 \& ./script/deploymentintro_dbicdh.pl install .Ve .SH "AUTHOR" .IX Header "AUTHOR" Arthur Axel \*(L"fREW\*(R" Schmidt .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2018 by Arthur Axel \*(L"fREW\*(R" Schmidt. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.