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
database
-
String which is required. The name of the database to connect to
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 create_database followed by deploy_and_populate
deploy_and_populate - Create tables and populates them with initial data
$self->deploy_and_populate;
Called as part of the application install
deploy_file
$result = $self->deploy_file( $schema, $split, $class, $path );
Populates one table from a single file
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
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
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
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) 2016 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