The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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

attrs

Hash ref which defaults to { add_drop_table => TRUE, no_comments => TRUE, }. It has an initialisation argument of dbattrs

database

String which is required

db_admin_ids

Hash ref which defaults to { mysql => 'root', pg => 'postgres', }

paragraph

Hash ref which defaults to { cl => TRUE, fill => TRUE, nl => TRUE }

preversion

String which defaults to null

rdbms

Array ref which defaults to [ qw(MySQL PostgreSQL) ]

schema_classes

Hash ref which defaults to {}

schema_version

String which defaults to 0.1

Boolean which defaults to false

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

dbattrs

   $self->dbattrs;

Merges the attrs attribute with the database attributes returned by the get_connect_info method

deploy_and_populate - Create tables and populates them with initial data

   $self->deploy_and_populate;

Called as part of the application install

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

Class::Usul::TraitFor::ConnectInfo
Class::Usul::Programs

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, <Support at RoxSoft.co.uk>

License and Copyright

Copyright (c) 2014 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