Class::Usul::Schema - Support for database schemas
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 } ); }
Methods used to install and uninstall database applications
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
{ mysql => 'root', pg => 'postgres', }
db_attr
Hash reference which defaults to { add_drop_table => TRUE, no_comments => TRUE, }
{ 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
-d
preversion
String which defaults to null. The previous schema version number
rdbms
Array reference which defaults to [ qw(MySQL PostgreSQL) ]. List of supported RDBMS
[ qw(MySQL PostgreSQL) ]
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
0.1
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
$self->create_database;
Understands how to do this for different RDBMSs, e.g. MySQL and PostgreSQL
$self->create_ddl;
Creates the DDL for multiple RDBMs
$self->create_schema;
Calls edit_credentials, create_database, create_user, and deploy_and_populate
$self->create_user;
Creates a database user
$self->deploy_and_populate;
Called as part of the application install
@paths = $self->ddl_paths( $schema, $version, $dir );
Returns a list of io objects for each of the DDL files
Deprecated in favour of "populate_class"
$self->driver;
The database driver string, derived from the "dsn" method
$self->drop_database;
The database is selected by the database attribute
$self->drop_user;
The user is selected by the user attribute
user
$self->dsn;
Returns the DSN from the call to get_connect_info
$self->edit_credentials;
Encrypts the database connection password before storage
$self->execute_ddl( $ddl, \%connect_opts, \%command_opts );
Executes the DDL
$self->host;
Returns the hostname of the database server derived from the call to "dsn"
$self->password;
The unencrypted password used to connect to the database
$result = $self->populate_class( $schema, $split, $class, $path );
Populates one table from a single file
$self->repopulate_class;
Specify the class to reload on the command line
$self->user;
The user id used to connect to the database
None
There are no known incompatibilities in this module
There are no known bugs in this module. Please report problems to the address below. Patches are welcome
Peter Flanigan, <pjfl@cpan.org>
<pjfl@cpan.org>
Copyright (c) 2018 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
To install Class::Usul, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Usul
CPAN shell
perl -MCPAN -e shell install Class::Usul
For more information on module installation, please visit the detailed CPAN module installation guide.