NAME
DBIO::PostgreSQL::Deploy - Deploy and upgrade PostgreSQL schemas via test-deploy-and-compare
VERSION
version 0.900000
DESCRIPTION
DBIO::PostgreSQL::Deploy orchestrates the deployment and upgrade of PostgreSQL schemas using a test-deploy-and-compare strategy. The shared orchestration (install, diff, apply, upgrade) and the temporary-database dance are inherited from DBIO::Deploy::Base::TempDatabase; this class supplies only the genuinely PostgreSQL-specific seams (the CREATE DATABASE / DROP DATABASE dialect and the schema_filter passed to the introspector).
For upgrades, the strategy is:
- 1. Introspect the live database via
pg_catalog - 2. Create a temporary database
- 3. Deploy the desired schema (from DBIO classes) into the temp database
- 4. Introspect the temp database via
pg_catalog - 5. Compute the diff between the two models using DBIO::PostgreSQL::Diff
- 6. Drop the temp database
This means PostgreSQL is comparing with itself — the diff is always accurate regardless of how complex the schema features are.
my $deploy = DBIO::PostgreSQL::Deploy->new(
schema => MyApp::DB->connect($dsn),
);
# Fresh install
$deploy->install;
# Upgrade (test-deploy + compare + apply)
$deploy->upgrade;
# Or in steps:
my $diff = $deploy->diff;
print $diff->summary;
$deploy->apply($diff) if $diff->has_changes;
METHODS
install_schema
$deploy->install_schema('tenant_42');
Creates a single PostgreSQL schema (namespace) using CREATE SCHEMA IF NOT EXISTS. Useful for multi-tenant setups where each tenant gets its own schema.
_new_introspect
my $intro = $self->_new_introspect($dbh);
Factory for the introspector. Override in a subclass to use a custom DBIO::PostgreSQL::Introspect subclass (e.g. DBIO::PostgreSQL::PostGIS::Introspect).
The base class only passes dbh; here we also forward the schema_filter derived from the connected schema's pg_schemas so introspection stays scoped to the schemas this driver manages.
_create_temp_db
my $name = $self->_create_temp_db($dbh);
PostgreSQL CREATE DATABASE cannot run inside a transaction block, so the dbh is forced into autocommit mode for the duration. Returns the new database name (temp_db_prefix . $$ . '_' . time()).
_drop_temp_db
$self->_drop_temp_db($dbh, $name);
Drops the temporary database. Forcibly commits any open transaction first (symmetric to "_create_temp_db").
DBIO::PostgreSQL - schema component with
pg_deployfactory methodDBIO::PostgreSQL::DDL - generates the DDL used by
installanddiffDBIO::PostgreSQL::Introspect - reads the live and temp database state
DBIO::PostgreSQL::Diff - compares the two introspected models
DBIO::Deploy::Base::TempDatabase - inherited orchestration
AUTHOR
DBIO & DBIx::Class Authors
COPYRIGHT AND LICENSE
Copyright (C) 2026 DBIO Authors Portions Copyright (C) 2005-2025 DBIx::Class Authors Based on DBIx::Class, heavily modified.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.