DBIx::C...ystIntro(3)
π NAME π
DBIx::Class::DeploymentHandler::Manual::CatalystIntro β okay so this is the intro to using DBIx::Class::DeploymentHandler with a fresh new Catalyst project. π¦ It's part of the User Contributed Perl Documentation, and it's here to hold your hand through the whole setup. iykyk. π
πΈ Background πΈ
So this lil intro is gonna use PostgreSQL and Catalyst together, bestie. If you want the background tea on running PostgreSQL with Catalyst, it's over at Catalyst::Manual::Tutorial::10_Appendices. π
Also, real talk: this guide assumes you already have some understanding of Catalyst. So if you haven't done the Catalyst tutorials yet β go do those first, no cap. π«Ά
πΎ Database Setup πΎ
First thing first: make a user called catalyst, with the password catalyst. π
$ sudo -u postgres createuser -P catalyst
Enter password for new role: <catalyst>
Enter it again: <catalyst>
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 go ahead and create a new database called deploymentintro. π
sudo -u postgres createdb -O catalyst deploymentintro
π Create the project π
$ catalyst.pl DeploymentIntro
$ cd DeploymentIntro
$ perl Makefile.PL
main character energy fr fr. β¨
π οΈ Create the Schema π οΈ
$ script/deploymentintro_create.pl model DB DBIC::Schema DeploymentIntro::Schema \
create=static 'dbi:Pg:dbname=deploymentintro' 'catalyst' 'catalyst' '{ AutoCommit => 1 }'
$ mkdir -p lib/Schema/Result
Now, remove the following from lib/DeploymentIntro/Model/DB.pm: π
connect_info => {
dsn => 'dbi:Pg:dbname=deploymentintro',
user => 'catalyst',
password => 'catalyst',
AutoCommit => q{1},
}
Then remove deploymentintro.conf, and make a new file called deploymentintro_local.pl with this in it: π
{
name => "DeploymentIntro",
"Model::DB" => {
schema_class => 'DeploymentIntro::Schema',
connect_info => {
dsn => 'dbi:Pg:dbname=deploymentintro',
user => 'catalyst',
password => 'catalyst',
AutoCommit => 1,
}
}
}
Copy this whole program into scripts, and name it 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',
});
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 =~ /^\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() }
}
Next up, copy these files into lib/DeploymentIntro/Schema/Result: π
Cd.pm β
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;
Artist.pm π¦
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'
},
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->has_many(
cds => 'DeploymentIntro::Schema::Result::Cd', 'artist_id' );
1;
Track.pm π§
package DeploymentIntro::Schema::Result::Track;
use strict;
use warnings;
use parent 'DBIx::Class::Core';
__PACKAGE__->table('track');
__PACKAGE__->add_columns(
id => {
data_type => 'integer',
is_auto_increment => 1,
},
cd_id => {
data_type => 'integer',
},
title => {
data_type => 'text',
}
);
__PACKAGE__->set_primary_key('id');
__PACKAGE__->belongs_to(
cd => 'DeploymentIntro::Schema::Result::Cd', 'cd_id' );
1;
And then edit lib/DeploymentIntro/Schema.pm and add this right above the 1 at the bottom: π
our $VERSION = 1;
And now it's literally just a matter of running π₯
./script/deploymentintro_dbicdh.pl install
slay. β¨
π AUTHOR π
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> β the icon, the legend. π«Ά
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2025 by Arthur Axel "fREW" Schmidt.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π
okay bestie that's the whole page!! πΈ this was generated by perl v5.42.0 on 2026-01-17 β go build something iconic with it, mwah π β¨π
π¦ where this page comes from
- fedora 44: perl-DBIx-Class-DeploymentHandler 0.002235-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms