NAME
DBIO::Deploy::Base::TempDatabase - Deploy base for drivers that diff against a temporary database
VERSION
version 0.900000
DESCRIPTION
A DBIO::Deploy::Base specialization for drivers whose diff builds the target model by deploying the desired schema into a freshly created temporary database and introspecting it -- PostgreSQL and MySQL. (Drivers that use an in-memory database, such as DuckDB and SQLite, do not need this: they override "_build_target_model" in DBIO::Deploy::Base with a :memory: connection.)
It provides the shared temp-database orchestration:
"_build_target_model" -- create a temp db, deploy + introspect into it, then always drop it (even if the deploy or introspection dies), and re-raise any error afterwards.
"_deploy_and_introspect_temp" -- connect to the temp db, run the install DDL, introspect, disconnect.
"_temp_connect_info" -- derive the temp-db connection info from the live storage's connect info by rewriting the database name in the DSN.
A subclass supplies only the genuinely engine-specific seam: "_create_temp_db" and "_drop_temp_db" (the CREATE DATABASE / DROP DATABASE dialect, and any transaction handling), plus the three class-name hooks from DBIO::Deploy::Base.
METHODS
_create_temp_db
my $name = $self->_create_temp_db($dbh);
Create a uniquely-named temporary database and return its name. Abstract -- the CREATE DATABASE statement and quoting/transaction handling are engine-specific.
_drop_temp_db
$self->_drop_temp_db($dbh, $name);
Drop the temporary database named $name. Abstract.
temp_db_prefix
Prefix for generated temp-database names. Defaults to _dbio_tmp_. A subclass's "_create_temp_db" typically builds the full name as prefix . $$ . '_' . time().
_build_target_model
Creates a temp database, deploys + introspects the desired schema into it via "_deploy_and_introspect_temp", and drops the temp database. The drop runs unconditionally (wrapped in its own eval) so a failed deploy or introspection never leaks a temp database; the original error is then re-raised.
_deploy_and_introspect_temp
my $model = $self->_deploy_and_introspect_temp($temp_db);
Connects to $temp_db (via "_temp_connect_info"), runs the install DDL, introspects the result, disconnects, and returns the model. Errors during deploy or introspection are re-raised after the connection is closed.
_temp_connect_info
my ($dsn, $user, $pass) = $self->_temp_connect_info($temp_db);
Derives connection info for the temp database from the live storage's connect_info, rewriting the dbname= / database= component of the DSN to $temp_db (appending it when absent). Handles both the array ($dsn, $user, $pass) and single-hashref ({ dsn, user, password }) connect-info shapes. Dies on a coderef DSN.
_temp_dsn
my $temp_dsn = $self->_temp_dsn($dsn, $temp_db);
Given the live storage's $dsn and the temp-database name $temp_db, return the DSN string used to connect to the temp database. The default rewrites the database= / dbname= component of $dsn to $temp_db (appending ;dbname=$temp_db when absent) -- the standard form for engines whose DSN names the database with a dbname= key (PostgreSQL, MySQL).
This is the single overridable seam for the temp-db DSN form: a driver whose DSN shape differs (e.g. Firebird's dbi:Firebird:localhost:$db) overrides only this method and inherits the rest of "_temp_connect_info" (the connect-info shape handling, user/password extraction, coderef-DSN guard).
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.