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
DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers(3) User Contributed Perl Documentation DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers(3)

DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers - CodeRef Transforms for common use-cases in DBICDH Migrations

 use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers
   'schema_from_schema_loader';

   schema_from_schema_loader({ naming => 'v4' }, sub {
      my ($schema, $version_set) = @_;

      ...
   });

This package is a set of coderef transforms for common use-cases in migrations. The subroutines are simply helpers for creating coderefs that will work for "PERL SCRIPTS" in DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator, yet have some argument other than the current schema that you as a user might prefer.

 dbh(sub {
   my ($dbh, $version_set) = @_;

   ...
 });

For those times when you almost exclusively need access to "the bare metal". Simply gives you the correct database handle and the expected version set.

 schema_from_schema_loader({ naming => 'v4' }, sub {
   my ($schema, $version_set) = @_;

   ...
 });

Any time you write a perl migration script that uses a DBIx::Class::Schema you should probably use this. Otherwise you'll run into problems if you remove a column from your schema yet still populate to it in an older population script.

Note that $sl_opts requires that you specify something for the "naming" option.

If you find that in your scripts you need to always pass the same arguments to your script helpers, you may want to define a custom set of script helpers. I am not sure that there is a better way than just using Perl and other modules that are already installed when you install DBIx::Class::DeploymentHandler.

The following is a pattern that will get you started; if anyone has ideas on how to make this even easier let me know.

 package MyApp::DBICDH::ScriptHelpers;

 use strict;
 use warnings;

 use DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::ScriptHelpers
    dbh => { -as => '_old_dbh' },
    schema_from_schema_loader => { -as => '_old_sfsl' };

 use Sub::Exporter::Progressive -setup => {
    exports => [qw(dbh schema_from_schema_loader)],
 };

 sub dbh {
    my $coderef = shift;

    _old_dbh(sub {
       my ($dbh) = @_;
       $dbh->do(q(SET search_path TO 'myapp_db'));

       $coderef->(@_);
    });
 }

 sub schema_from_schema_loader {
    my ($config, $coderef) = @_;

    $config->{naming} ||= 'v7';

    _old_sfsl(sub {
       my ($schema) = @_;
       $schema->storage->dbh->do(q(SET search_path TO 'myapp_db'));

       $coderef->(@_);
    });

 }

The above will default the naming to "v7" when using "schema_from_schema_loader". And in both cases it will set the schema for PostgreSQL. Of course if you do that you will not be able to switch to MySQL or something else, so I recommended looking into my DBIx::Introspector to only do that for the database in question.

Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>

This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2019-09-25 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.