Name
Class::Usul::Schema - Support for database schemas
Synopsis
package YourApp::Schema;
use Moo;
use Class::Usul::Functions qw( arg_list );
use YourApp::Schema::Authentication;
use YourApp::Schema::Catalog;
extends 'Class::Usul::Schema';
my %DEFAULTS = ( database => 'library',
schema_classes => {
authentication => 'YourApp::Schema::Authentication',
catalog => 'YourApp::Schema::Catalog', }, );
sub new_with_options {
my ($self, @args) = @_; my $attr = arg_list @args;
return $self->next::method( %DEFAULTS, %{ $attr } );
}
Description
Methods used to install and uninstall database applications
Configuration and Environment
Defines the following attributes
all
-
Optional boolean. Perform operation for all possible schema
database
-
String which is required. The name of the database to connect to
db_admin_accounts
-
Hash reference keyed by the lower case driver value. The hash's value is the name of the administration database for that RDBMS
db_admin_ids
-
Hash reference which defaults to
{ mysql => 'root', pg => 'postgres', }
The default administration identity for each supported RDBMS db_attr
-
Hash reference which defaults to
{ add_drop_table => TRUE, no_comments => TRUE, }
ddl_commands
-
A hash reference keyed by database driver. The DDL commands used to create users and databases
dry_run
-
A boolean that defaults for false. Can be set from the command line with the
-d
option. Prints out commands, do not execute them preversion
-
String which defaults to null. The previous schema version number
rdbms
-
Array reference which defaults to
[ qw(MySQL PostgreSQL) ]
. List of supported RDBMS schema_classes
-
Hash reference which defaults to
{}
. Keyed by model name, the DBIC class names for each model schema_version
-
String which defaults to
0.1
. The schema version number is used in the DDL filenames unlink
-
Boolean which defaults to false. Unlink DDL files if they exist before creating new ones
yes
-
Boolean which defaults to false. When true flips the defaults for yes/no questions
Subroutines/Methods
create_database - Creates a database
$self->create_database;
Understands how to do this for different RDBMSs, e.g. MySQL and PostgreSQL
create_ddl - Dump the database schema definition
$self->create_ddl;
Creates the DDL for multiple RDBMs
create_schema - Creates a database then deploys and populates the schema
$self->create_schema;
Calls edit_credentials, create_database, create_user, and deploy_and_populate
create_user - Creates a database user
$self->create_user;
Creates a database user
deploy_and_populate - Create tables and populates them with initial data
$self->deploy_and_populate;
Called as part of the application install
ddl_paths
@paths = $self->ddl_paths( $schema, $version, $dir );
Returns a list of io objects for each of the DDL files
deploy_file
Deprecated in favour of "populate_class"
driver
$self->driver;
The database driver string, derived from the "dsn" method
drop_database - Drops a database
$self->drop_database;
The database is selected by the database
attribute
drop_user - Drops a user
$self->drop_user;
The user is selected by the user
attribute
dsn
$self->dsn;
Returns the DSN from the call to get_connect_info
edit_credentials - Edits the database login information
$self->edit_credentials;
Encrypts the database connection password before storage
execute_ddl
$self->execute_ddl( $ddl, \%connect_opts, \%command_opts );
Executes the DDL
host
$self->host;
Returns the hostname of the database server derived from the call to "dsn"
password
$self->password;
The unencrypted password used to connect to the database
populate_class
$result = $self->populate_class( $schema, $split, $class, $path );
Populates one table from a single file
repopulate_class - Reloads the given class from the initial load data
$self->repopulate_class;
Specify the class to reload on the command line
user
$self->user;
The user id used to connect to the database
Diagnostics
None
Dependencies
Incompatibilities
There are no known incompatibilities in this module
Bugs and Limitations
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Author
Peter Flanigan, <pjfl@cpan.org>
License and Copyright
Copyright (c) 2017 Peter Flanigan. All rights reserved
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE