NAME

DBIO::Admin - Lightweight schema administration helper for DBIO

VERSION

version 0.900004

SYNOPSIS

use DBIO::Admin;

my $admin = DBIO::Admin->new(
  schema_class => 'MyApp::Schema',
  connect_info => ['dbi:Pg:dbname=myapp', 'user', 'pass', {}],
  mode => 'auto',
);

$admin->deploy;
$admin->upgrade;

See t/92admin_core.t for a runnable example.

DESCRIPTION

Administrative helper used by dbioadmin.

Supported operations:

  • upgrade (native driver upgrade)

  • deploy

  • select, insert, update, delete

ATTRIBUTES

schema_class

The schema class to connect with. Read-only.

config_stanza

::-separated path into the configuration naming the entry whose connect_info to use (see "connect_info"). Read-only.

sql_dir

Directory handed to "deploy" in DBIO::Schema as its second argument by "deploy". Read-only.

config_file

Configuration file loaded through Config::Any when no config was given. Read-only.

resultset

Default source name for "insert", "update", "delete" and "select". Read/write; the setter returns the object for chaining.

force

When true, "update", "delete" and "upgrade" run without asking for confirmation; for "upgrade" it is the release of a destructive diff. Read/write; the setter returns the object.

dry_run

When true, "upgrade" prints the summary and the SQL of the diff and executes nothing. Read/write; the setter returns the object. dbioadmin sets it with --dry-run.

all

When true, "update" and "delete" may run without a condition and change every row of the source (ADR 0069); the release is handed to "update" in DBIO::ResultSet and "delete" in DBIO::ResultSet. Without it a statement without a condition throws, as in the core. Read/write; the setter returns the object. dbioadmin sets it with --all.

quiet

When true, "insert", "update" and "delete" print nothing. Read/write; the setter returns the object.

mode

Upgrade mode, auto (default) or native; see "MODES". Read/write; the setter returns the object.

where

Default search condition for "update", "delete" and "select". Read/write; the setter accepts a hashref or JSON string and returns the object.

set

Default column values for "insert" and "update". Read/write; the setter accepts a hashref or JSON string and returns the object.

attrs

Default search attributes for "delete" and "select". Read/write; the setter accepts a hashref or JSON string and returns the object.

trace

When true, storage debugging (SQL tracing) is enabled on the schema. The setter also switches $schema->storage->debug immediately (connecting the schema if needed) and returns the object.

schema

The connected schema. Built lazily from "schema_class" and "connect_info" unless one was passed to "new": for a known DSN driver (Pg, SQLite, MySQL, MariaDB, Oracle, DB2, Informix, Firebird, Sybase, MSSQL) it first croaks if no matching DBIO driver distribution is installed, then connects with ignore_version set.

connect_info

Connection arguments for "schema". Built lazily from "config" by walking "config_stanza" (and descending into its connect_info key if present). May resolve to an arrayref (passed through as-is) or a hashref with dsn, user, password and further attributes.

config

The parsed configuration hashref. Built lazily by loading "config_file" through Config::Any (which must be installed).

METHODS

new

my $admin = DBIO::Admin->new(%args);

Accepted arguments: schema_class, resultset, config_stanza, sql_dir, config_file, mode (stored as given); force, quiet, trace, all, dry_run (stored as booleans); where, set, attrs (hashrefs, or JSON strings that are decoded -- the decoder is relaxed and, where supported, accepts bare keys and single quotes); connect_info (arrayref, hashref, or a JSON string); config (hashref or JSON string); and a ready schema. schema_class is loaded immediately (croaking if it cannot be); mode defaults to auto.

upgrade

Runs the native upgrade path for the schema's driver: computes the diff of the live database against the schema class and applies it ("apply" in DBIO::Deploy::Base). Returns the diff, or false when the database was already up to date or the run was not confirmed. Currently the native path is the PostgreSQL one, used when the schema can('pg_deploy') (requires DBIO-PostgreSQL). Croaks on an unknown "mode", or when no native upgrade path is available.

A diff that drops or may alter stored data (a table, schema, type, extension or column the schema class does not declare, a possibly lossy type change) is announced with the summary of those operations and runs after the confirmation YES on STDIN, as "update" and "delete" do; "force" gives the release without asking (dbioadmin --force). Operations the deploy refuses are never applied, with or without "force".

With "dry_run" the summary and the SQL of the diff are printed and nothing is executed (dbioadmin --dry-run); the diff is returned.

deploy

$admin->deploy(\%sqlt_args);

Calls $schema->deploy($args, $admin->sql_dir).

insert

my $row = $admin->insert($source, \%set);

Inserts one row into $source (default "resultset") with the values %set (default "set"), prints its id unless "quiet", and returns the row object. Croaks if either is missing.

update

my $n = $admin->update($source, \%set, \%where);

Updates every row of $source matching %where via update_all. Arguments default to "resultset", "set" and "where". Unless "quiet", prints how many records will be modified; unless "force", asks on STDIN for YES first and returns 0 if not confirmed.

delete

my $n = $admin->delete($source, \%where, \%attrs);

Deletes every row of $source matching %where / %attrs via delete_all. Arguments default to "resultset", "where" and "attrs"; announcement and confirmation work as in "update".

select

my $data = $admin->select($source, \%where, \%attrs);

Returns an arrayref of arrayrefs: the first row holds the source's column names, each further row the raw column values of one matching record. Arguments default to "resultset", "where" and "attrs".

SEE ALSO

dbioadmin, DBIO::Schema

MODES

mode controls how upgrade is executed. Both accepted values use the native driver upgrade path; upgrade croaks if the schema/driver provides no native upgrader.

  • auto (default)

  • native

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.