GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Catalyst::TraitFor::Model::DBIC::Schema::FromMigration(3) User Contributed Perl Documentation Catalyst::TraitFor::Model::DBIC::Schema::FromMigration(3)

Catalyst::TraitFor::Model::DBIC::Schema::FromMigration - Use your DB Sandbox to run Catalyst

Use the trait in your Catalyst configuration:

    'Model::Schema' => {
      traits => ['FromMigration'],
      schema_class => 'MusicBase::Schema',
      extra_migration_args => {
        db_sandbox_class => 'DBIx::Class::Migration::MySQLSandbox'},
      install_if_needed => {
        on_install => sub {
          my ($schema, $migration) = @_;
          $migration->populate('all_tables')}},
      },

If you are in development and using a database sandbox auto created and managed for you with DBIx::Class::Migration, this is a trait to make it easy to hook that sandbox up to your Catalyst application. The following are roughly the same:

    package MusicBase::Web::Model::Schema;

    use Moose;
    extends 'Catalyst::Model::DBIC::Schema';

    __PACKAGE__->config
    (
        schema_class => 'MusicBase::Schema',
        connect_info => {
          dsn => 'DBI:SQLite:__path_to(share,musicbase-schema.db)__',
          user => '',
          password => '',
        },
    )

    __PACKAGE__->meta->make_immutable;

And using the trait:

    package MusicBase::Web::Model::Schema;

    use Moose;
    extends 'Catalyst::Model::DBIC::Schema';

    __PACKAGE__->config
    (
        traits => ['FromMigration'],
        schema_class => 'MusicBase::Schema',
        extra_migration_args => \%args,
        install_if_needed => {
          default_fixture_sets => ['all_tables']},
    )

    __PACKAGE__->meta->make_immutable;

The biggest reasons to use this trait would be it makes it harder to connect the wrong database and it gives you some easy helpers for automatic database installation and fixture population (as you can see in the above example).

This trait uses the following configuration parameters:

Accepts: Hashref, Optional

A hashref of init arguments that you'd pass to the "new" method of DBIx::Class::Migration. "schema_class" is inferred from the existing config parameter, so you don't need to pass that one. Other arguments of use could be "db_sandbox_class".

    extra_migration_args => {
      db_sandbox_class => 'DBIx::Class::Migration::MySQLSandbox'},

For example would use a MySQL development sandbox instead of the default SQLite.

Accepts Bool|HashRef, Optional

If this is a true value, run the "install_if_needed" in DBIx::Class::Migration method. If the value is a Hashref, we will assume it is a hashref of callbacks as documented, and use it as an argument (after de-reffing it).

This role exposes the following public methods

Returns the DBIx::Class::Migration object created to assist setting up and managing your database.

Installs a database and possibly do some data population, if one does not yet exist.

Catalyst::Model::DBIC::Schema, Catalyst

See DBIx::Class::Migration for author information

See DBIx::Class::Migration for copyright and license information
2020-06-02 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.