Coder Social home page Coder Social logo

dbix-class-migration's Introduction

NAME

DBIx::Class::Migration - Use the best tools together for sane database migrations

SYNOPSIS

use DBIx::Class::Migration;

my $migration = DBIx::Class::Migration->new(
  schema_class => 'MyApp::Schema',
  schema_args => \@connect_opts);

Alternatively:

use DBIx::Class::Migration;
use MyApp::Schema;

my $migration = DBIx::Class::Migration->new(
  schema => MyApp::Schema->connect(@connect_opts));

Informational Commands:

$migration->status;

Preparing and using Migrations:

$migration->prepare;
$migration->install;
$migration->upgrade;
$migration->downgrade;

Commands for working with Fixtures:

$migration->dump_named_sets;
$migration->dump_all_sets;
$migration->populate;

Utility Commands:

$migration->drop_tables;
$migration->delete_table_rows;
$migration->make_schema;
$migration->install_if_needed;
$migration->install_version_storage;
$migration->diagram;

DESCRIPTION

DBIx::Class::DeploymentHandler is a state of the art solution to the problem of creating sane workflows for versioning DBIx::Class managed database projects. However, since it is more of a toolkit for building custom versioning and migration workflows than an expression of a particular migration practice, it might not always be the most approachable tool. If you are starting a new DBIx::Class project and you don't have a particular custom workflow need, you might prefer to simply be given a reasonable clear and standard practice, rather than a toolkit with a set of example scripts.

DBIx::Class::Migration defines some logic which combines both DBIx::Class::DeploymentHandler and DBIx::Class::Fixtures, along with a standard tutorial, to give you a simple and straightforward approach to solving the problem of how to best create database versions, migrations and testing data. Additionally it builds on tools like Test::mysqld and Test::Postgresql58 along with DBD::Sqlite in order to assist you in quickly creating a local development database sandbox. It offers some integration points to testing your database, via tools like Test::DBIx::Class in order to make testing your database driven logic less painful. Lastly, we offer some thoughts on good development patterns in using databases with application frameworks like Catalyst.

DBIx::Class::Migration offers code and advice based on my experience of using DBIx::Class for several years, which hopefully can help you bootstrap a new project. The solutions given should work for you if you want to use DBIx::Class and have database migrations, but don't really know what to do next. These solutions should scale upward from a small project to a medium project involving many developers and more than one target environment (DEV -> QA -> Production.) If you have very complex database versioning requirements, huge teams and difficult architectual issues, you might be better off building something on top of DBIx::Class::DeploymentHandler directly.

DBIx::Class::Migration is a base class upon which interfaces like DBIx::Class::Migration::Script are built.

Please see DBIx::Class::Migration::Tutorial for more approachable documentation. If you want to read a high level feature overview, see DBIx::Class::Migration::Features. The remainder of this POD is API level documentation on the various internals.

ATTRIBUTES

This class defines the following attributes.

db_sandbox_builder_class

Accept Str. Defaults to 'DBIx::Class::Migration::TargetDirSandboxBuilder'

The name of the helper class which builds the class that builds database sandboxs. By default we build database sandboxes in the "target_dir", which is what DBIx::Class::Migration::TargetDirSandboxBuilder does. We can also build database sandboxes in a temporary directory using DBIx::Class::Migration::TempDirSandboxBuilder. You might prefer that for running tests, for example.

db_sandbox_class

Accepts Str. Not Required (defaults to 'DBIx::Class::Migration::SqliteSandbox').

Unless you already have a database setup and running (as you probably do in production) we need to auto create a database 'sandbox' that is isolated to your development local. This class is a delegate that performs this job if you don't want to go to the trouble of installing and setting up a local database yourself.

This must point to a class that expects target_dir and schema_class for initialization arguments and must define a method make_sandbox that returns an array which can be sent to "connect" in DBIx::Class::Schema.

This defaults to DBIx::Class::Migration::SqliteSandbox. Currently we have support for MySQL and Postgresql via DBIx::Class::Migration::MySQLSandbox and DBIx::Class::Migration::PgSandbox, but you will need to side install Test::mysqld and Test::Postgresql58 (In other words you'd need to add these Test::* namespace modules to your Makefile.PL or dist.ini).

db_sandbox

Accepts: Object. Not required.

This is an instantiated object as defined by "db_sandbox_class". It is a delegate for the work of automatically creating a local database sandbox that is useful for developers and for quickly bootstrapping a project.

schema_class

Accepts Str. Not Required (but if missing, you need to populate "schema").

This is the schema we use as the basis for creating, managing and running your deployments. This should be the full package namespace defining your subclass of DBIx::Class::Schema. For example MyApp::Schema.

If the "schema_class" cannot be loaded, a hard exception will be thrown.

schema_args

Accepts ArrayRef. Required but lazily builds from defaults

Provides arguments passed to connect on your "schema_class". Should connect to a database.

This is an arrayref that would work the same as "connect" in DBIx::Class::Schema. If you choose to create an instance of DBIx::Class::Migration by providing a schema_class, you can use this to customize how we connect to a database.

If you don't provide a value, we will automatically create a SQLite based database connection with the following DSN:

DBD:SQLite:[path to target_dir]/[db_file_name].db

Where [path to target_dir] is "target_dir" and [db_file_name] is a converted version of "schema_class". For example if you set schema_class to:

MyApp::Schema

Then [db_file_name] would be myapp-schema.

Basically, this means you can start testing your database designs right off without a lot of effort, just point at a schema_class and get deploying!

schema

Accepts: Object of DBIx::Class::Schema. Not required.

If you already have a connected schema (subclass of DBIx::Class::Schema) you can simple point to it, skipping schema_class and schema_args. You might for example be using Catalyst and want to build deployments for a database that is listed in configuration:

use MyCatalyst::App;
use DBIx::Class::Migration;

my $migration = DBIx::Class::Migration->new(
  schema => MyCatalyst::App->model('Schema')->schema,
  %{MyCatalyst::App->config->{extra_migration_init_args}};
);

target_dir_builder_class

Accepts: Str, Defaults to 'DBIx::Class::Migration::ShareDirBuilder' This is a class that is used as a helper to build "target_dir" should the user not provide a value. Default is DBIx::Class::Migration::ShareDirBuilder

target_dir_builder

An instance of whatever is in "target_dir_builder_class". Used by the lazy build method of "target_dir" to default a directory where the migrations are actually placed.

target_dir

Accepts Str. Required (lazy builds to your distribution /share directory).

This is the directory we store our migration and fixture files. Inside this directory we will create a fixtures and migrations sub-directory.

Although you can specify the directory, if you leave it undefined, we will use File::ShareDir::ProjectDistDir to locate the /share directory for your project and place the files there. This is the recommended approach, and is considered a community practice in regards to where to store your distribution non code files. Please see File::ShareDir::ProjectDistDir as well as File::ShareDir for more information.

This uses whatever is in "schema_class" to determine your project (and look for a share directory, which you'll need to create in your project root). If you don't have a "schema_class" defined, you must have a "schema", and we'll infer the class via ref($self->schema).

NOTE: You'll need to make the /share directory if you are going to use the default option. We don't automatically create it for you.

schema_loader_class

Accepts Str. Required

Because your application subclass of DBIx::Class::Schema is going to change a lot, sometimes we need to generate our own schema and get one that is in a known, good state. Mostly this is used by the commands to drop tables and clear tables.

Defaults to DBIx::Class::Migration::SchemaLoader. You'll probably only need to change this if your database is crazy and you need to massage the init arguments to DBIx::Class::Schema::Loader.

schema_loader

Accepts Object. Required but lazy builds.

This is a factory that provider autoloaded schema based on the current schema's database. It is automatically created and you are unlikely to need to set this manually.

dbic_fixture_class

Accepts Str. Required

This is the class we use when creating instances of DBIx::Class::Fixtures. You'll probably need to review the docs for that and understand how configuration rules work in order to best take advantage of the system.

Defaults to DBIx::Class::Fixtures. You'll probably not need to change this unless you have some unusual needs regarding fixtures.

dbic_fixtures_extra_args

Accepts HashRef. Required, but Defaults to Empty Hashref

Allows you to pass some additional arguments when creating instances of "dbic_fixture_class". These arguments can be used to override the default initial arguments.

deployment_handler_class

Accepts Str. Required

This is the class we use when creating instances of DBIx::Class::DeploymentHandler. It would be ideal that you review those docs in order to better understand the overall architecture of the system.

Defaults to DBIx::Class::DeploymentHandler. You'll probably not need to change this unless you need a custom deployment handler, and if you do, I can't be sure this framework will work correctly, particularly if you are not using monotonic versioning.

dbic_dh_args

Accepts HashRef. Required and defaults to a hashref setting sql_translator_args's quote_identifiers to a true value, which despite being documented as the default, is not the case in practice.

Used to pass custom args when building a DBIx::Class::DeploymentHandler. Please see the docs for that class for more. Useful args might be databases, to_version and force_overwrite.

dbic_dh

Accepts Instance of DBIx::Class::DeploymentHandler. Required but lazily built from default data and dbic_dh_args.

You probably won't need to build your own deployment handler and pass it in (unlike schema, where it might actually be useful). Be careful it you do since this framework makes some assumptions about your deployment handler (for example we assume you are using the monotonic versioning).

When this attribute is lazily built, we merge "dbic_dh_args" with the following defaults:

  schema => Points to $self->schema
  script_directory => Points to catdir($self->target_dir, 'migrations')
  databases => Inferred from your connected schema, defaults to SQLite

"dbic_dh_args" will overwrite the defaults, if you pass them.

extra_schemaloader_args

Optional. Accepts a HashRef of arguments you can use to influence how DBIx::Class::Schema::Loader works. This HashRef would get passed as loader_options (see "make_schema_at" in DBIx::Class::Schema::Loader.

Meaningful options are described at DBIx::Class::Schema::Loader::Base.

METHODS

This class defines the following methods for public use

new

Used to create an new instance of DBIx::Class::Migration. There's a couple of paths to creating this instance.

Specify a schema_class and optionally schema_args

use DBIx::Class::Migration;
my $migration = DBIx::Class::Migration->new(
  schema_class => 'MyApp::Schema',
  schema_args => [@connect_info],
);

This is probably the most general approach, and is recommended unless you already have a connected instance of your DBIx::Class::Schema subclass.

"schema_args" would be anything you'd pass to "connect" in DBIx::Class::Schema. see "schema_args" for how we construct default connect information if you choose to leave this undefined.

Specify a schema

There may be some cases when you already have a schema object constructed and would prefer to just use that. For example, you may be using Catalyst and wish to build custom scripts using the built-in dependency and service lookup:

use MyCatalyst::App;
use DBIx::Class::Migration;

my $migration = DBIx::Class::Migration->new(
  schema => MyCatalyst::App->model('Schema')->schema,
  %{MyCatalyst::App->config->{extra_migration_init_args}};
);

Be careful of potential locking issues when using some databases like SQLite.

OPTIONAL: Specify a target_dir

Optionally, you can specify your migrations target directory (where your migrations get created), in your init arguments. This option can be combined with either approach listed above.

use DBIx::Class::Migration;
my $migration = DBIx::Class::Migration->new(
  schema_class => 'MyApp::Schema',
  schema_args => [@connect_info],
  target_dir => '/opt/database-migrations',
);

If you leave this undefined we default to using the share directory in your distribution root. This is generally the community supported place for non code data, but if you have huge fixture sets you might wish to place them in an alternative location.

OPTIONAL: Specify a db_sandbox_dir

Be default if you allow for a local database sandbox (as you might during early development and you don't want to work to make a database) that sandbox gets built in the 'target_dir'. Since other bits in the target_dir are probably going to be in your project repository and the sandbox generally isnt, you might wish to build the sandbox in an alternative location. This setting allows that:

use DBIx::Class::Migration;
my $migration = DBIx::Class::Migration->new(
  schema_class => 'MyApp::Schema',
  schema_args => [@connect_info],
  db_sandbox_dir => '~/opt/database-sandbox',
);

This then gives you a nice totally standalone database sandbox which you can reuse for other projects, etc.

OPTIONAL: Specify dbic_dh_args

Optionally, you can specify additional arguments to the constructor for the "dbic_dh" attribute. Useful arguments might include additional databases we should build fixtures for, to_version and force_overwrite.

See "" in DBIx::Class::DeploymentHandler for more information on supported init arguments. See "dbic_dh" for how we merge default arguments with your custom arguments.

Other Initial Arguments

For normal usage the remaining init args are probably not particularly useful and reflect a desire for long term code flexibility and clean design.

version

Prints to STDOUT a message regarding the version of DBIC:Migration that you are currently running.

status

Returns the state of the deployed database (if it is deployed) and the state of the current schema version. Sends this as a string to STDOUT

prepare

Creates a fixtures and migrations directory under "target_dir" (if they don't already exist) and makes deployment files for the current schema. If deployment files exist, will fail unless you "overwrite_migrations".

The migrations directory reflects a directory structure as documented in DBIx::Class::DeploymentHandler.

If this is the first version, we create directories and initial DLL, etc. For versions greater than 1, we will also generate diffs and copy any fixture configs etc (as well as generating a fresh 'all_table.json' fixture config). For safety reasons, we never overwrite any fixture configs.

install

Installs either the current schema version (if already prepared) or the target version specified via any to_version flags sent as an dbic_dh_args to the database which is connected via "schema".

If you try to install to a database that has already been installed, you'll get an error. See "drop_tables".

upgrade

Run upgrade files to bring the database into sync with the current schema version.

downgrade

Run down files to bring the database down to the previous version from what is installed to the database

drop_tables

Drops all the tables in the connected database with no backup or recovery. For real! (Make sure you are not connected to Prod, for example).

delete_table_rows

Does a delete on each table in the database, which clears out all your data but preserves tables. For Real! You might want this if you need to load and unload fixture sets during testing, or perhaps to get rid of data that accumulated in the database while running an app in development, before dumping fixtures.

dump_named_sets

Given an array of fixture set names, dump them for the current database version.

dump_all_sets

Takes no arguments just dumps all the sets we can find for the current database version.

make_schema

Given an existing database, reverse engineer a DBIx::Class Schema in the "target_dir" (under dumped_db). You can use this if you need to bootstrap your DBIC files.

populate

Given an array of fixture set names, populate the current database version with the matching sets for that version.

Skips the table dbix_class_deploymenthandler_versions, so you don't lose deployment info (this is different from "drop_tables" which does delete it.)

diagram

Experimental feature. Although not specifically a migration task, I find it useful to output visuals of my databases. This command will place a file in your "target_dir" called db-diagram-vXXX.png where XXX is he current schema version.

This is using the Graphviz producer (SQL::Translator::Producer::GraphViz) which in turn requires Graphviz. Since this is not always trivial to install, I do not require it. You will need to add it manually to your Makefile.PL or dist.ini and manage it yourself.

This feature is experimental and currently does not offer any options, as I am still determining the best way to meet the need without exceeding the scope of DBIx::Class::Migration. Consider this command a 'freebee' and please don't depend on it in your custom code.

install_if_needed

If the database is not installed, do so. Accepts a hash of callbacks or instructions to perform should installation be needed/

$migration->install_if_needed(
  on_install => sub {
    my ($schema, $local_migration) = @_;
    DBIx::Class::Migration::Population->new(
      schema=>shift)->populate('all_tables');
  });

The following callbacks / instructions are permitted

  • on_install

    Accepts: Coderef

    Given a coderef, execute it after the database is installed. The coderef gets passed two arguments: $schema and $self (the current migration object).

  • default_fixture_sets

    Accepts: Arrayref of fixture sets

      $migration->install_if_needed(
        default_fixture_sets => ['all_tables']);
    

    After database installation, populate the fixtures in order.

install_version_storage

If the targeted (connected) database does not have the versioning tables installed, this will install them. The version is set to whatever your schema version currently is.

You will only need to use this command in the case where you have an existing database that you are reverse engineering and you need to setup versioning storage since you can't rebuild the database from scratch (such as if you have a huge production database that you now want to start versioning).

delete_named_sets

Given a (or a list) of fixture sets, delete them if the exist in the current schema version.

Yes, this really deletes, you've been warned (check in your code to a source control repository).

ENVIRONMENT

When running DBIx::Class::Migration we set some %ENV variables during installation, up / downgrading, so that your Perl run scripts (see "DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator\'PERL SCRIPTS'") can receive some useful information. The Following %ENV variables are set:

DBIC_MIGRATION_SCHEMA_CLASS => $self->schema_class
DBIC_MIGRATION_TARGET_DIR => $self->target_dir
DBIC_MIGRATION_FIXTURE_DIR => catdir($self->target_dir, 'fixtures', $self->dbic_dh->schema_version),
DBIC_MIGRATION_SCHEMA_VERSION => $self->dbic_dh->schema_version
DBIC_MIGRATION_TO_VERSION => $self->dbic_dh->to_version
DBIC_MIGRATION_DATABASE_VERSION => $self->dbic_dh->schema_version || 0

You might find having these available in your migration scripts useful for doing things like 'populate a database from a fixture set, if it exists, but if not run a bunch of inserts.

THANKS

Because of the awesomeness of CPAN and the work of many others, all this functionality is provided with a few hundred lines of code. In fact, I spent a lot more time writing docs and tests than anything else. Here are some particular projects / people I'd like to thank:

First, thanks to mst for providing me a big chunk of code that served to kickstart my work, and served as an valuable prototype.

Thanks to frew for the awesome DBIx::Class::DeploymentHandler which gives us such a powerful base for organizing database versions. Thanks to all the authors of DBIx::Class::Fixtures for giving me a foundation for managing sets of data. Lastly, thanks to the DBIx::Class cabal for all the work done in making the DBIx::Class ORM so amazingly powerful.

Additionally thanks to the creators / maintainers for Test::mysqld and Test::Postgresql58, which made it easy to create developer level sandboxes for these popular open source databases.

As usual, thanks to the Moose cabal for making Perl programming fun and beautiful. Lastly, a shout-out to the Dist::Zilla cabal for making it so I don't need to write my own build and deployment tools.

AUTHOR

John Napiorkowski email:[email protected]

CONTRIBUTORS

The following is a list of identified contributors. Please let me know if I missed you.

https://github.com/pjcj
https://github.com/chromatic
https://github.com/bentglasstube
https://github.com/logie17
https://github.com/RsrchBoy
https://github.com/vkroll
https://github.com/felliott
https://github.com/mkrull
https://github.com/moltar
https://github.com/andyjones
https://github.com/pnu
https://github.com/n7st
https://github.com/willsheppard
https://github.com/mulletboy2
https://github.com/mohawk2
https://github.com/manwar
https://github.com/upasana-me
https://github.com/rabbiveesh

SEE ALSO

DBIx::Class::DeploymentHandler, DBIx::Class::Fixtures, DBIx::Class, DBIx::Class::Schema::Loader, Moo, DBIx::Class::Migration::Script, DBIx::Class::Migration::Population, dbic-migration, SQL::Translator, Test::mysqld, Test::Postgresql58.

COPYRIGHT & LICENSE

Copyright 2013-2015, John Napiorkowski email:[email protected]

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

dbix-class-migration's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

dbix-class-migration's Issues

Wrong Fixture configuration file is read

$ make dbdeploy 
$(which dbic-migration) --schema_class XXX::Schema --database PostgreSQL -Ilib -V 14 install
Since this database is not versioned, we will assume version 19
Reading configurations from /home/kes/xxx/share/fixtures/19/conf
$ make dbstatus 
$(which dbic-migration) --schema_class XXX::Schema --database PostgreSQL -Ilib status
Schema is 19
Deployed database is 14

My current schema version in code is 19. I want manually to test code and deploy schema version 14.
While I do this wrong version is read for fixtures

Can't pass schema options in a Runscript script

Hey @jjn1056,

I'm using DBICM with Postgres and making use of Pg's schemas. When I write migration scripts in perl using DBICM::Runscript I'm unable to access my resultsets because they are not in a public schema. To get around this, I need to pass the db_schema and moniker_parts options to the call to DBIx::Class::Schema::Loader::make_schema_at in DBICM::RunScript::Trait::SchemaLoader, but the options are hardcoded in DBICM::SchemaLoader::opts.

I wasn't able to figure out a way to pass these options, so for now I've settled for monkeypatching the call to opts like so:

no warnings redefine;                                                                                                                                                                                    
my @orig_opts = DBIx::Class::Migration::SchemaLoader::opts();                                                                                                                                               
*DBIx::Class::Migration::SchemaLoader::opts                                                                                                                                                                 
    = sub { (@orig_opts, 'db_schema', ['public','study_design', 'bioware'],                                                                                                                                 
             'moniker_parts', ['schema', 'name']) };     

Is there a better way to do this? If not, would you like a doc patch for the FAQ showing how to do this? Thank you!

Cheers,
Fitz

Upgrade script generated with errors

-- Convert schema '/home/kes/work/projects/tucha/monkeyman/share/migrations/_source/deploy/1/001-auto.yml' to '/home/kes/work/projects/tucha/monkeyman/share/migrations/_source/deploy/2/001-auto.yml':;

;
BEGIN;

;
ALTER TABLE writeoff DROP FOREIGN KEY writeoff_fk_provisioning_obligation_id;

;
ALTER TABLE writeoff ADD CONSTRAINT writeoff_fk_provisioning_obligation_id FOREIGN KEY (provisioning_obligation_id) REFERENCES provisioning_obligation (provisioning_obligation_id) ON DELETE RESTRICT ON UPDATE CASCADE;

;

COMMIT;

Trying to apply this migration I get the error:

Reading configurations from /home/kes/work/projects/tucha/monkeyman/share/fixtures/1/conf
failed to run SQL in /home/kes/work/projects/tucha/monkeyman/share/migrations/MySQL/upgrade/1-2/001-auto.sql: DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator::try {...} (): DBI Exception: DBD::mysql::db do failed: Can't DROP 'writeoff_fk_provisioning_obligation_id'; check that column/key exists [for Statement "ALTER TABLE writeoff DROP FOREIGN KEY writeoff_fk_provisioning_obligation_id"] at inline delegation in DBIx::Class::DeploymentHandler for deploy_method->upgrade_single_step (attribute declared in /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/DBIx/Class/DeploymentHandler/WithApplicatorDumple.pm at line 51) line 18
 (running line 'ALTER TABLE writeoff DROP FOREIGN KEY writeoff_fk_provisioning_obligation_id') at /home/kes/work/projects/tucha/monkeyman/local/lib/perl5/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm line 248.
DBIx::Class::Storage::TxnScopeGuard::DESTROY(): A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back. at /home/kes/work/projects/tucha/monkeyman/local/bin/dbic-migration line 0
DBIx::Class::Storage::TxnScopeGuard::DESTROY(): A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back. at /home/kes/work/projects/tucha/monkeyman/local/bin/dbic-migration line 0
Makefile:142: recipe for target 'dbup' failed
make: *** [dbup] Error 255

As you can see this is the first upgrade migration.
The underlying database is manually created. And constrains has its own naming.
Here is how writeoff was created:

| writeoff | CREATE TABLE `writeoff` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  ....
  `provisioning_obligation_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`) USING BTREE,
  ...
  KEY `provisioning_obligation_id` (`provisioning_obligation_id`),
  ...
  CONSTRAINT `writeoff_ibfk_4` FOREIGN KEY (`provisioning_obligation_id`) REFERENCES `provisioning_occurrence` (`provisioning_occurrence_id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

As you can see the underlaid database uses its own naming and upgrade script should use index names that are in the database for DROP statement

The name autogeneration should be used only for ADD CONSTRAINT

seem to be unable to generate anything other than SQLite schema

It looks like the method dbic_dh has side effects by deleting the list of databases - the list is correct first time through, but then defaults to "[SQLite]'. I don't fully understand the implications of what this will mean for the distribution, but this fix works for me ....

our $VERSION = "0.036";


sub dbic_dh {
  my ($self, @args) = @_;
  my $databases = $self->dbic_dh_args->{databases} ?
    delete($self->dbic_dh_args->{databases}) :
    [_infer_database_from_schema($self->schema)];

probably should be

sub dbic_dh {
  my ($self, @args) = @_;
  my $databases = $self->dbic_dh_args->{databases} ?
    ($self->dbic_dh_args->{databases}) :
    [_infer_database_from_schema($self->schema)];

157c157

< delete($self->dbic_dh_args->{databases}) :

($self->dbic_dh_args->{databases}) :

dump_named_sets fails

Hello, I tried to use "dump_named_sets" with my schema, but it fails:

my $migration = DBIx::Class::Migration->new(
    schema          => $schema,
    dbic_dh_args    => { databases => [ 'Oracle', 'PostgreSQL', 'SQLite' ] },
    force_overwrite => 1
);

$migration->dump_named_sets( 'static_tables' );

Here is the relevant part of the error's stack trace:

Can't find source for Testtable at /opt/perl5/20.2/lib/site_perl/5.20.2/DBIx/Class/Schema.pm line 1077.
    DBIx::Class::Schema::throw_exception("MyApp::Schema0", "Can't find source for Testtable") called at /opt/perl5/20.2/lib/site_perl/5.20.2/DBIx/Class/Schema.pm line 596
    DBIx::Class::Schema::source("MyApp::Schema0", "Testtable") called at /opt/perl5/20.2/lib/site_perl/5.20.2/DBIx/Class/Schema.pm line 547
    DBIx::Class::Schema::resultset("MyApp::Schema0", "Testtable") called at /opt/perl5/20.2/lib/site_perl/5.20.2/DBIx/Class/Fixtures.pm line 661
    DBIx::Class::Fixtures::dump(DBIx::Class::Fixtures=HASH(0x874a968), HASH(0x874a998)) called at /opt/perl5/20.2/lib/site_perl/5.20.2/DBIx/Class/Fixtures.pm line 1120
    DBIx::Class::Fixtures::dump_config_sets(DBIx::Class::Fixtures=HASH(0x874a968), HASH(0x874a998)) called at /opt/perl5/20.2/lib/site_perl/5.20.2/DBIx/Class/Migration.pm line 415
    DBIx::Class::Migration::dump_named_sets(DBIx::Class::Migration=HASH(0x6a34448), "static_tables") called at lib/MyApp/MigrationTest.pm line 114
    MyApp::MigrationTest::__ANON__() called at lib/MyApp/MigrationTest.pm line 116
    MyApp::MigrationTest::main(MyApp::MigrationTest=HASH(0x4b2b1b8)) called at lib/MyApp.pm line 1574
    eval {...} called at lib/MyApp.pm line 1570
    MyApp::run(MyApp::MigrationTest=HASH(0x4b2b1b8)) called at script/appstarter line 24

I noticed that schema_from_database in DBIx::Class::Migration::SchemaLoader adds a counter to the schema name (as you can see in the stack trace snippet). Things seem to work if I remove this number by replacing line 40 in $LIB/DBIx/Class/Migration/SchemaLoader.pm like this:

# $self->_make_schema_at(_as_unique_ns($ns), %extra_opts);
$self->_make_schema_at( $ns, %extra_opts);

My problem is, that I can't estimate the side affects of this change. Is there a better way to solve this?

Can't find source for XXX

When trying to dump data I get error: Can't find source for

I dig a bit and think you should pass whole $shema instead of just $name

More info here on SO

Incompatible with the latest version (0.37) of MooseX::Types

Hello! DBIC-Migration fails to install with the latest version of MooseX::Types.

The tests fail with an "Can't locate DBIx/Class/Migration/_Types.pm" error when they try to load DBIx::Class::Migration::Types.

MooseX::Types has switched to Module::Runtime instead of Class::MOP which means it doesn't work with inlined packages like DBIx::Class::Migration::_Types. Module::Runtime is trying to load it from disk. The module isn't there so it dies.

I raised https://rt.cpan.org/Public/Bug/Display.html?id=88650 on MooseX::Types so hopefully this is just an fyi

DBIx::Class::Migration::Tutorial::FirstMigration version action

The version action of dbic-migration prints the $VERSION of DBIx::Class::Migration (see its version() method), not the version of the schema. I'm not sure what you want to do there, but that part of the tutorial is slightly incorrect.

Fixing it is easy, but you'll have to revise the tutorial to recommend to create a share directory before calling version.

Deprecation of Class::MOP::load_class dumping stack traces for all invocations

Whenever you invoke dbic-migration now, you get a page long stack trace starting with this:

Class::MOP::load_class is deprecated at /usr/perl5/site_perl/5.18.1/sun4-solaris-thread-multi-64/Class/MOP.pm line 71.
        Class::MOP::load_class('DBIx::Class::Migration::RunScript::Trait::TargetPath') called at /usr/perl5/site_perl/5.18.1/MooseX/Traits/Pluggable.pm line 46
        eval {...} called at /usr/perl5/site_perl/5.18.1/MooseX/Traits/Pluggable.pm line 46

I see several other modules have had to update themselves to eliminate this annoyance.

Typos/bad links

DBIx::Class::Migrations does not exist but it is mentioned (and linked to) twice in the FAQ ('see "make_schema" in DBIx::Class::Migrations and "make_schema" in DBIx::Class::Migrations::Script') and twice in DBIx::Class::Migration::Population ('that is just aware of DBIx::Class::Migrations conventions' and 'You create an instance of this similarly to DBIx::Class::Migrations').

There are other usages of the word "migrations" but those all look and sound correct to me.

Poor error message when passing --database without --dsn to `dbicm install`

After preparing a migration for PostgreSQL with --database=PostgreSQL, I tried to run

$ dbic-migration -Ilib install --database=PostgreSQL

This gives the error:

Reading configurations from /home/vagrant/MyApp/share/fixtures/1/conf/home/vagrant/MyApp/share/migrations/SQLite does not exist; please write/generate some SQL

Obviously my command can't work (I didn't give it any connection info) but it's very surprising that it ignores the --database flag entirely and complains about the default DB not having a prepared migration.

Perl migrations are broken on 5.26

Just tried setting up a migration with a Perl script, under Perl 5.26.2. This fails noisily:

Can't locate sql/migrations/PostgreSQL/upgrade/3-4/002-set-full-name.pl in @INC (@INC contains: lib /home/vagrant/.perlbrew/libs/perl-5.26.1@greeter/lib/perl5/x86_64-linux /home/vagrant/.perlbrew/libs/perl-5.26.1@greeter/lib/perl5 /home/vagrant/perl5/perlbrew/perls/perl-5.26.1/lib/site_perl/5.26.1/x86_64-linux /home/vagrant/perl5/perlbrew/perls/perl-5.26.1/lib/site_perl/5.26.1 /home/vagrant/perl5/perlbrew/perls/perl-5.26.1/lib/5.26.1/x86_64-linux /home/vagrant/perl5/perlbrew/perls/perl-5.26.1/lib/5.26.1) at (eval 1315) line 4.
 at /home/vagrant/.perlbrew/libs/perl-5.26.1@greeter/lib/perl5/Context/Preserve.pm line 43.

Adding PERL_USE_UNSAFE_INC=1 to the command-line fixed the issue.

The solution is almost certainly just to find the relevant do call and add a ./ to the front of the file name involved.

Can't run

failed to run Perl in /Users/daveh/workspace/DBIx-Class-Migration/t/share/migrations/MySQL/deploy/1/002-artists.pl: Can't locate object method "dump_config_sets" via package "DBIx::Class::Fixtures=HASH(0x7f89793ae1d0)" (perhaps you forgot to load "DBIx::Class::Fixtures=HASH(0x7f89793ae1d0)"?) at lib/DBIx/Class/Migration/RunScript/Trait/Dump.pm line 22.

$ cpanm DBIx::Class::Fixtures
DBIx::Class::Fixtures is up to date. (1.001032)

Adding use DBIx::Class::Fixtures; to t/migration-mysql.t fixes this error.

unexpected error "Use of uninitialized value $sharedir in concatenation"

In the doc on the page you say:

Before we move on, let's see the status of your schema and database:
dbic-migration -Ilib status

After running this command I got this instead:

Use of uninitialized value $sharedir in concatenation (.) or string at /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/DBIx/Class/Migration/ShareDirBuilder.pm line 33.
Can't find a share () for ArtCoin at /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/DBIx/Class/Migration/ShareDirBuilder.pm line 33.

MySQL test fails

ok 3 - can correctly infer a database DBD
Cannot overwrite '/Users/daveh/workspace/DBIx-Class-Migration/t/share/migrations/_source/deploy/1/001-auto.yml', either enable force_overwrite or delete it at /Users/daveh/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm line 731.

Even if I delete that file before running the test.

The order of columns for deploy SQL is wrong

I have next table in my database:

\d tariff_details;
                                  Table "public.tariff_details"
  Column   |         Type          |                          Modifiers                          
-----------+-----------------------+-------------------------------------------------------------
 id        | integer               | not null default nextval('tariff_details_id_seq'::regclass)
 tariff_id | integer               | not null
 name      | character varying(64) | not null
 price     | tmoney                | not null
 option    | character varying(16) | 
 periodic  | boolean               | not null default false
 value     | text                  | 
 sorder    | integer               | not null default 0

It is defined as:

$T->add_columns(
	id =>  {
		data_type         =>  'integer',
		is_auto_increment =>  1,
	},
	tariff_id =>  {
		data_type => 'integer',
	},
	name => {
		data_type =>  'varchar',
		size      =>  64,
	},
	price => {
		data_type =>  'tmoney',
	},
	periodic => {
		data_type   =>  'boolean',
		default_value =>  'no',
	},
	option => {
		data_type   =>  'varchar',
		size        =>  16,
		is_nullable =>  1,
	},
	value => {
		data_type   =>  'text',
		is_nullable =>  1,
	},
	sorder => {
		data_type     =>  'int',
		default_value =>  0,
	},
);

The history of this file is:

git log --topo-order -u -L 10,43:"lib/App/Schema/Result/Tariff_details.pm"
commit 777d02ac947f1aec00148d631c5e89bff01be8e7
Author: Eugen Konkov <[email protected]>
Date:   Sun Jan 28 13:38:54 2018 +0200

    SCHEMA 72: Implement tariff features

diff --git a/lib/App/Schema/Result/Tariff_details.pm b/lib/App/Schema/Result/Tariff_details.pm
--- a/lib/App/Schema/Result/Tariff_details.pm
+++ b/lib/App/Schema/Result/Tariff_details.pm
@@ -10,26 +10,34 @@
 
 $T->add_columns(
 	id =>  {
 		data_type         =>  'integer',
 		is_auto_increment =>  1,
 	},
 	tariff_id =>  {
 		data_type => 'integer',
 	},
 	name => {
 		data_type =>  'varchar',
 		size      =>  64,
 	},
 	price => {
 		data_type =>  'tmoney',
 	},
 	periodic => {
 		data_type   =>  'boolean',
 		default_value =>  'no',
 	},
 	option => {
 		data_type   =>  'varchar',
 		size        =>  16,
 		is_nullable =>  1,
 	},
+	value => {
+		data_type   =>  'text',
+		is_nullable =>  1,
+	},
+	sorder => {
+		data_type     =>  'int',
+		default_value =>  0,
+	},
 );

commit 4475d1f8bab6fe08b5efab9e421b6d26ab8a4954
Author: Eugen Konkov <[email protected]>
Date:   Thu Oct 5 19:12:10 2017 +0300

    SCHEMA 50: Split 'period' and 'periodic'

diff --git a/lib/App/Schema/Result/Tariff_details.pm b/lib/App/Schema/Result/Tariff_details.pm
--- a/lib/App/Schema/Result/Tariff_details.pm
+++ b/lib/App/Schema/Result/Tariff_details.pm
@@ -10,27 +10,26 @@
 
 $T->add_columns(
 	id =>  {
 		data_type         =>  'integer',
 		is_auto_increment =>  1,
 	},
 	tariff_id =>  {
 		data_type => 'integer',
 	},
 	name => {
 		data_type =>  'varchar',
 		size      =>  64,
 	},
 	price => {
 		data_type =>  'tmoney',
 	},
-	period => {
-		data_type   =>  'varchar',
-		size        =>  16,
-		is_nullable =>  1,
+	periodic => {
+		data_type   =>  'boolean',
+		default_value =>  'no',
 	},
 	option => {
 		data_type   =>  'varchar',
 		size        =>  16,
 		is_nullable =>  1,
 	},
 );

commit cee7ea9d2c41b5edcade5d68085f05a96f0c0a7c
Author: Eugen Konkov <[email protected]>
Date:   Tue Oct 3 16:37:53 2017 +0300

    SCHEMA 46: Implement Tariff option

diff --git a/lib/App/Schema/Result/Tariff_details.pm b/lib/App/Schema/Result/Tariff_details.pm
--- a/lib/App/Schema/Result/Tariff_details.pm
+++ b/lib/App/Schema/Result/Tariff_details.pm
@@ -10,22 +10,27 @@
 
 $T->add_columns(
 	id =>  {
 		data_type         =>  'integer',
 		is_auto_increment =>  1,
 	},
 	tariff_id =>  {
 		data_type => 'integer',
 	},
 	name => {
 		data_type =>  'varchar',
 		size      =>  64,
 	},
 	price => {
 		data_type =>  'tmoney',
 	},
 	period => {
 		data_type   =>  'varchar',
 		size        =>  16,
 		is_nullable =>  1,
 	},
+	option => {
+		data_type   =>  'varchar',
+		size        =>  16,
+		is_nullable =>  1,
+	},
 );

commit 4b5609bdad9eae805bb2eafbda0c1048f7b6f6d8
Author: Eugen Konkov <[email protected]>
Date:   Thu Sep 14 16:48:44 2017 +0300

    SCHEMA 41: Implement 'tariff_details' table

diff --git a/lib/App/Schema/Result/Tariff_details.pm b/lib/App/Schema/Result/Tariff_details.pm
--- /dev/null
+++ b/lib/App/Schema/Result/Tariff_details.pm
@@ -0,0 +10,22 @@
+
+$T->add_columns(
+	id =>  {
+		data_type         =>  'integer',
+		is_auto_increment =>  1,
+	},
+	tariff_id =>  {
+		data_type => 'integer',
+	},
+	name => {
+		data_type =>  'varchar',
+		size      =>  64,
+	},
+	price => {
+		data_type =>  'tmoney',
+	},
+	period => {
+		data_type   =>  'varchar',
+		size        =>  16,
+		is_nullable =>  1,
+	},
+);

But the produced sql for database deployment is:

CREATE TABLE "tariff_details" (
  "id" serial NOT NULL,
  "tariff_id" integer NOT NULL,
  "name" character varying(64) NOT NULL,
  "price" tmoney NOT NULL,
  "periodic" boolean DEFAULT 'no' NOT NULL,
  "option" character varying(16),
  "value" text,
  "sorder" integer DEFAULT 0 NOT NULL,
  PRIMARY KEY ("id")
);

As you can see column price and option is flipped. This cause problems when you can try to restore data on production which is dumped on developer machine:

1	L2TP/PPTP VPN Monthly	7.000000000000000000	0	\N	1m	pptp - Personal usage	\N
ERROR:  null value in column "periodic" violates not-null constraint
DETAIL:  Failing row contains (17, 1, Setup fee, 5.000000000000000000, null, f, null, 0).
CONTEXT:  COPY tariff_details, line 1: "17	1	Setup fee	5.000000000000000000	\N	f\N	0"

Test::PostgreSQL 1.20 breaks DBIx::Class::Migration

Had to back off to Test::PostgreSQL 1.06 to escape from this problem that appears in Test::PostgreSQL 1.20:

$ dbic-migration -Ilib status

WARNING: using $Test::PostgreSQL::Defaults is DEPRECATED. Use Test::PostgreSQL->new( extra_initdb_args => ... ) instead. at /usr/perl5/site_perl/5.22.0/Test/PostgreSQL.pm line 25.

WARNING: using $Test::PostgreSQL::Defaults is DEPRECATED. Use Test::PostgreSQL->new( extra_postmaster_args => ... ) instead. at /usr/perl5/site_perl/5.22.0/Test/PostgreSQL.pm line 25.
Value "15432\n" did not pass type constraint "Maybe[Int]" (in $args->{"port"}) at (eval 1227) line 406
Value "15432\n" did not pass type constraint "Maybe[Int]" (in $args->{"port"})
Value "15432\n" is defined
"Maybe[Int]" constrains the value with "Int" if it is defined
Value "15432\n" did not pass type constraint "Int" (in $args->{"port"})

when not passed '--dsn' dbic-migration should print a line saying "no --dsn,

<@mst> jnap: idea: when not passed '--dsn' dbic-migration should print a line saying "no --dsn, using DBD:SQLite:[path to target_dir]/[db_file_name].db"
5:01 PM J John Napiorkowski mst: good idea
5:02 PM M<@mst> just had a v. confued user in f#perl who'd found --databases and couldn't work out why SQLite was still involved
5:02 PM J John Napiorkowski I'll add a note in the repo. Make it easier when you just want to do quick prototypes (half the reason I wrote this thing).
5:03 PM M<@mst> oh, yeah, the defaulting thing is not at all a bad feature
5:03 PM hence suggesting it saying "hey, I'm doing this helpful thing"
5:03 PM and keep the feature as-is otherwise :)

Deploy script ran in not transaction

I have two deploy scripts:

001-auto-__VERSION.sql
001-auto.sql

When I ran deploy the second script failed. I fix the problem and ran deployment again, but now first script failed with error that dbix_class_deploymenthandler_versions table already exists.

Deployment scripts should be run in transaction, thus if one of them fail everything is rolledback

Using a sandbox within Test::DBIx::Class

Not sure if I am missing some clue in the documentation, but I can't seem to get the DBIx::Class::Migration::(MySQL,Postgresql)Sandbox to work with Test::DBIx::Class.

For SQLite, the following (default) parameters work just fine:

use Test::DBIx::Class
-schema_class => 'My::Module::Schema',
-fixture_class => '::Population',
qw(SomeResult SomeOtherResult);

However, it seems to require a DSN from connect_info. This is what ::Migration::PostgresqlSandbox::make_sandbox returns, but is there a helper to connect these two?

I've tried creating a DBIx::Class::Migration object beforehand and calling Test::DBIx::Class with:

-connect_info => $migration->db_sandbox_class->make_sandbox,

but that doesn't seem to work.

I'll gladly submit a pull request with more extended documentation on the matter, should I find out the solution.

Configuration is read from different version

$make dbdeploy 
$(which dbic-migration) --schema_class App::Schema --database PostgreSQL -Ilib install --to_version 20
Since this database is not versioned, we will assume version 21
Reading configurations from /home/kes/work/projects/safevpn/repo2/share/fixtures/21/conf
$ make dbstatus
$(which dbic-migration) --schema_class App::Schema --database PostgreSQL -Ilib status
Schema is 21
Deployed database is 20

Because I provide --to_version parameter I expect that configurations are read from version 20
But deployed database version is 20.

That is ambiguous to see the warning message:

Since this database is not versioned, we will assume version 21
Reading configurations from /home/kes/work/projects/safevpn/repo2/share/fixtures/21/conf

What is coming on here? please fix messages

Tests fail with File::ShareDir::ProjectDistDir 0.5.2

Tests run with this error: Can't find a share () for Local

The new version of ProjectDistDir no longer looks for a lib/ directory to dictate the project root/ so the share/ directory is not being correctly located in t/

File::ShareDir::ProjectDistDir 0.5.2 searches upwards of the given module and looks for any of the following

META.json
META.yml
Change(s|log)(|[.][^.\s]+)
GNUmakefile
makefile
Makefile
.devdir
t/
xt/
MYMETA.json
MYMETA.yml
dist.ini
Makefile.PL
Build.PL

cygwin failure (v0.057)

I have experienced the following failure on cygwin (32bit) - perl 5.22.0

PERL_DL_NONLAZY=1 "/usr/bin/perl.exe" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-clean.t .................. ok
t/help.t ...................... skipped: DBICM_TEST_HELP not set
t/install-version-storage.t ... ok
t/migration-mysql.t ........... skipped: DBICM_TEST_MYSQL not set
t/migration-postgresql.t ...... skipped: DBICM_TEST_PG not set
t/migration-sqlite.t .......... 11/? Operation "eq": no method found,
        left argument in overloaded package IO::All::Dir,
        right argument has no overloaded magic at /usr/lib/perl5/5.22/i686-cygwin-threads-64int/File/Spec/Cygwin.pm line 60.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 255 just after 11.
t/migration-sqlite.t .......... Dubious, test returned 255 (wstat 65280, 0xff00)
All 11 subtests passed
t/missing-schema-version.t .... ok
t/ordering.t .................. skipped: DBICM_TEST_PG not set
t/runscript.t ................. 1/? DBIx::Class::DeploymentHandler::Dad::install(): Install not possible as versions table already exists in database at /home/kmx/.cpanm/work/1439280277.14056/DBIx-Class-Migration-0.057/blib/lib/DBIx/Class/Migration.pm line 198
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 255 just after 1.
t/runscript.t ................. Dubious, test returned 255 (wstat 65280, 0xff00)
All 1 subtests passed
t/script.t .................... ok
t/upgrade-downgrade-sqlite.t .. 5/? Operation "eq": no method found,
        left argument in overloaded package IO::All::Dir,
        right argument has no overloaded magic at /usr/lib/perl5/5.22/i686-cygwin-threads-64int/File/Spec/Cygwin.pm line 60.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 255 just after 8.
t/upgrade-downgrade-sqlite.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
All 8 subtests passed
t/use.t ....................... ok

Test Summary Report
-------------------
t/migration-sqlite.t        (Wstat: 65280 Tests: 11 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output
t/runscript.t               (Wstat: 65280 Tests: 1 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output
t/upgrade-downgrade-sqlite.t (Wstat: 65280 Tests: 8 Failed: 0)
  Non-zero exit status: 255
  Parse errors: No plan found in TAP output
Files=12, Tests=47, 23 wallclock secs ( 1.42 usr  0.03 sys + 13.66 cusr  5.04 csys = 20.16 CPU)
Result: FAIL
Failed 3/12 test programs. 0/47 subtests failed.
Makefile:1103: recipe for target 'test_dynamic' failed
make: *** [test_dynamic] Error 255

It might be a problem in another module like: File::Spec (my version is 3.47) or IO::All (my version is 0.86)

Can't add [MetaYAML] to dist.ini

(I've picked up D::C::M as part of the CPAN PR challenge)

One of the whinges on cpants is that there's no META.YML file. Allegedly, this is as simple as adding [MetaYAML] to dist.ini. Doing this means dzil build throws a:

[DZ] attempt to add META.yml multiple times; added by: text from coderef added by @ConfigSlicer/MetaYAML (Dist::Zilla::Plugin::MetaYAML line 86); text from coderef added by MetaYAML (Dist::Zilla::Plugin::MetaYAML line 86)
aborting; duplicate files would be produced at /Users/daveh/perl5/perlbrew/perls/perl-5.18.2/lib/site_perl/5.18.2/Dist/Zilla/App/Command/build.pm line 71.

dist.ini looks otherwise innocuous. Google, nor the error messages really help me.

Any ideas?

Table names quoting when preparing a migration

I have a field in my MySQL database named order, when the migration is generated the table name isn't quoted, which unsurprisingly causes a SQL syntax error when applying this migration.

I've tried adding quote_names parameter, but it seems to have no effect:

dbic-migration prepare --dsn=dbi:mysql:database=database -U user -P password --dbic_connect_attrs quote_names=1

Is there some other way to enable quoting? I guess it would have made sense if it was enabled by default. Otherwise it seems to be related to #63.

Test fails on a Mac

Running cpanm DBIx::Class::Migration fails on a Mac computer.

Here's the relevant parts from log file:

t/00-clean.t .................. ok

#   Failed test 'help command produces expected output'
#   at t/help.t line 11.
#                   'HELP(1)               User Contributed Perl Documentation              HELP(1)
# 
# 
# 
# N�NA�AM�ME�E
#        DBIx::Class::Migration::Script::Help − Summary of the commands
# 
# U�US�SA�AG�GE�E
#          dbic−migration [options] Command
# 
# C�CO�OM�MM�MA�AN�ND�DS�S
#        The following is a summary of available commands
# 
#    I�In�nf�fo�or�rm�ma�at�ti�io�on�na�al�l C�Co�om�mm�ma�an�nd�ds�s
#          help                : Summary of commandline Help.
#          help [word]         : Detailed help for [command] or [option].
#          version             : The version of DBIx::Class::Migration you are using.
#          status              : Current database and schema version
# 
#    P�Pr�re�ep�pa�ar�ri�in�ng�g a�an�nd�d u�us�si�in�ng�g M�Mi�ig�gr�ra�at�ti�io�on�ns�s
#          prepare             : Makes deployment files for your schema_class
#          install             : Install a version to the database.
#          upgrade             : Upgrade the database.
#          downgrade           : Downgrade the database.
#          install_if_needed   : Install the database if its not installed
#          install_version_storage : populate the DBIC:DH metadata tables
# 
#    C�Co�om�mm�ma�an�nd�ds�s f�fo�or�r w�wo�or�rk�ki�in�ng�g w�wi�it�th�h F�Fi�ix�xt�tu�ur�re�es�s:�:
#          dump_named_sets     : Created fixture sets for the named sets
#          dump_all_sets       : Dump all available fxture sets
#          populate            : Deploy the current database from fixtures
# 
#    U�Ut�ti�il�li�it�ty�y C�Co�om�mm�ma�an�nd�ds�s
#          drop_tables         : drops all tables in the target database.  CAREFUL!
#          delete_table_rows   : truncate all the tables (no data, keep structure).
#          make_schema         : Reverse engineer your database into DBIx::Class
#          diagram             : Create an image schematic of your schema
# 
#    C�Co�om�mm�ma�an�nd�d o�op�pt�ti�io�on�ns�s
#          include/s (I,lib/s) : Adds the listed paths to @INC.
#          schema_class (S)    : The DBIx::Class::Schema subclass you are migrating
#          target_dir (D)      : Where to put (or find) your migration files
#          username (U)
#          password (P)
#          dsn                 : connection info to the database you are migrating
#          force_overwrite (O) : Allow overwriting of existing migration files
#          to_version (V)      : Use the given migration version
#          database/s          : The type of database we are preparing migrations for.
#          fixture_set/s       : Control the fixture sets used for dumping or populating
#          sandbox_class (T)   : Make any of SqliteSandbox, MySQLSandbox, PostgresqlSandbox
#          dbic_fixture_class  : Name an alternative subclass of DBIx::Class::Fixtures
#          dbic_connect_attrs  : Pass custom args to DBIx::Class::Schema−>connect
#          dbi_connect_attrs   : Pass custom args to DBI via DBIx::Class::Schema−>connect
#          extra_schemaloader_args  : Pass custom args to DBIx::Class::Migration::SchemaLoader
#          dbic_fixtures_extra_args : Pass custom args to DBIx::Class::Fixtures
# 
# E�EX�XA�AM�MP�PL�LE�E
#            dbic−migration status \
#              −−libs="lib" \
#              −−schema_class='MyApp::Schema' \
#              −−dsn='DBI:SQLite:myapp.db'
# 
# S�SE�EE�E A�AL�LS�SO�O
#        DBIx::Class::Migration, DBIx::Class::Migration::Script,
#        DBIx::Class::Migration::Features, DBIx::Class::Migration::Tutorial
# 
# A�AU�UT�TH�HO�OR�R
#        See DBIx::Class::Migration for author information
# 
# C�CO�OP�PY�YR�RI�IG�GH�HT�T &�& L�LI�IC�CE�EN�NS�SE�E
#        See DBIx::Class::Migration for copyright and license information
# 
# 
# 
# perl v5.14.2                      2013‐01‐10                           HELP(1)
# '
#     doesn't match '(?^ms:DBIx::Class::Migration::Script::Help - Summary of the commands)'
# Looks like you failed 1 test of 5.
t/help.t ...................... 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/5 subtests 
SV = IV(0x102637510) at 0x102637520
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x102641258
    SV = PVHV(0x102578660) at 0x102641258
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e24368   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x102624418) at 0x102624428
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x102629c88
    SV = PVHV(0x1025bc240) at 0x102629c88
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e24368   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
t/install-version-storage.t ... ok
t/migration-mysql.t ........... skipped: DBICM_TEST_MYSQL not set
t/migration-postgresql.t ...... skipped: DBICM_TEST_PG not set
SV = IV(0x1025db758) at 0x1025db768
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1025c5720
    SV = PVHV(0x102532aa0) at 0x1025c5720
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e25b68   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x1025cad90) at 0x1025cada0
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1025d1b10
    SV = PVHV(0x1025637e0) at 0x1025d1b10
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e25b68   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
t/migration-sqlite.t .......... ok
t/ordering.t .................. skipped: DBICM_TEST_PG not set
SV = IV(0x102606e58) at 0x102606e68
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1026007b0
    SV = PVHV(0x102558aa0) at 0x1026007b0
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e25568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x1025ed520) at 0x1025ed530
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1025f36c0
    SV = PVHV(0x1025ae3e0) at 0x1025f36c0
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e25568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
t/runscript.t ................. ok
No to_version is specified, downgrading to version 1 at /Users/ynonperek/.cpanm/work/1365015526.11132/DBIx-Class-Migration-0.037/blib/lib/DBIx/Class/Migration.pm line 195.
SV = IV(0x10465f2e8) at 0x10465f2f8
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1045e7c18
    SV = PVHV(0x10556a260) at 0x1045e7c18
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x104550d28) at 0x104550d38
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1045c89c8
    SV = PVHV(0x105575d20) at 0x1045c89c8
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x1045c4828) at 0x1045c4838
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1045101e0
    SV = PVHV(0x1055343a0) at 0x1045101e0
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x1045b4908) at 0x1045b4918
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x104541e78
    SV = PVHV(0x1055763c0) at 0x104541e78
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x104509888) at 0x104509898
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1045440d0
    SV = PVHV(0x10556b180) at 0x1045440d0
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x1045100b0) at 0x1045100c0
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x10450d4a8
    SV = PVHV(0x10553f0a0) at 0x10450d4a8
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x1025c3bb0) at 0x1025c3bc0
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1025e01e0
    SV = PVHV(0x102527c40) at 0x1025e01e0
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
SV = IV(0x1025c91a8) at 0x1025c91b8
  REFCNT = 1
  FLAGS = (ROK,READONLY)
  RV = 0x1025cff28
    SV = PVHV(0x102582f80) at 0x1025cff28
      REFCNT = 1
      FLAGS = (OBJECT,SHAREKEYS)
      STASH = 0x100e26568   "DBI::db"
      ARRAY = 0x0
      KEYS = 0
      FILL = 0
      MAX = 7
      RITER = -1
      EITER = 0x0
t/upgrade-downgrade-sqlite.t .. ok
t/use.t ....................... ok

Test Summary Report
-------------------
t/help.t                    (Wstat: 256 Tests: 5 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
Files=10, Tests=70, 10 wallclock secs ( 0.05 usr  0.02 sys +  8.45 cusr  0.49 csys =  9.01 CPU)
Result: FAIL
Failed 1/10 test programs. 1/70 subtests failed.
make: *** [test_dynamic] Error 255
-> FAIL Installing DBIx::Class::Migration failed. See /Users/ynonperek/.cpanm/build.log for details.

Can't get dbic_connect_attrs to work

Firstly, thanks for this wonderful module! Exactly what I was looking for.

I need to quote my table and column names (one is called "from"), so I am trying to pass the quote_names option to DBIC:

dbic-migration --schema_class MyApp::Schema -Ilib --dbic_connect_attrs quote_names=1 install

However, the option seemingly gets ignored. I've put some debugging in DBIx/Class/Storage/DBI.pm and the option is not being passed, so appears to being lost somewhere. Or have I got the syntax wrong?

I then tried hacking DBIx/Class/Storage/DBI.pm to force the option, but the table names still weren't quoted (this could be an error in another module of course).

I'll do some more debugging, but just wanted to annotate here and see if I'm doing something stupid.

can't install with option --to_version

I recently upgraded to version 0.044.

Now I don't seem to be able to wipe out a database and re-install it to a specific version like this any more:

dbic-migration -Ilib --schema_class My::Schema --dsn DSN --database MySQL drop_tables
dbic-migration -Ilib --schema_class My::Schema --dsn DSN --database MySQL install --to_version 45

When I do this now, I get this message:

Since this database is not versioned, we will assume version 46

46 is the current $VERSION of my schema. Of course the database isn't versioned because the version table has been deleted but it just used to work like this and I can't see how else to do this other then by changing the $VERSION of my schema all the time.
Thanks for your help!

all_tables Fixture includes Views

I can't think of a sensible reason for the default behaviour, but I'm not convinced that one doesn't exist.

The 'all_tables' Fixture includes DBIx::Class::ResultSource::Views. These views aren't tables in the DB, so dump_all_sets fails - which necessitates editing all_tables config each time it's generated. There may be some config option I've missed that can get around this?

Looks like adding a check for table_class DBIx::Class::ResultSource::View in _sets_data_from_sources might fix it?

Can't open dir error when stick to `PostgreSQL` database

I follow the guide and use --database PostgreSQL options in all commands

After this one I got error:

$ dbic-migration --schema_class MyApp::Schema --database PostgreSQL -Ilib install
Since this database is not versioned, we will assume version 1
Reading configurations from /home/kes/work/projects/myapp.io/myapp/share/fixtures/1/conf
Can't opendir($fh, '/home/kes/work/projects/myapp.io/myapp/share/migrations/SQLite/deploy/1'): No such file or directory at /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/DBIx/Class/DeploymentHandler/DeployMethod/SQL/Translator.pm line 109
DBIx::Class::Storage::TxnScopeGuard::DESTROY(): A DBIx::Class::Storage::TxnScopeGuard went out of scope without explicit commit or error. Rolling back. at /home/kes/perl5/perlbrew/perls/perl-5.24.0/bin/dbic-migration line 0

Here DBIx::Class::Migration tries to process SQLite despite on --database PostgreSQL

File::Copy minimum version too high

Currently the minimum File::Copy version is 2.30, see https://metacpan.org/source/JJNAPIORK/DBIx-Class-Migration-0.055/Makefile.PL#L29
But this module version is not available before perl 5.20.1, and is not a core module. So effectively you restrict your module to perl 5.20.1 and 5.20.2.

BTW, I think the problem with the "massive failure reports" is not the minimum versions, but something different. There was not a single pass on cpantesters since 0.048 (see http://matrix.cpantesters.org/?dist=DBIx-Class-Migration%200.055;maxver=1 ), and there are testers who install all new module versions on their systems.

extra_schemaloader_args not passed through in RunScript::Trait::SchemaLoader::schema()

I am passing in the schema loader option 'moniker_map' using the extra_schemaloader_args attribute, but my migration script fails to run because the moniker_map option is not used when creating the schema in the script

my $migration = DBIx::Class::Migration->new( schema => $schema, extra_schemaloader_args => { moniker_map => { pos => 'POs' } }, );

migration { shift->schema->storage->dbh_do( ... ) }

throws error:

failed to run Perl in /vagrant/goldenaxe/share/migrations/PostgreSQL/upgrade/18-19/001-update_functions.pl: Unable to load schema - chosen moniker/class naming style results in moniker clashes. Change the naming style, or supply an explicit moniker_map: tables "public"."po", "public"."pos" reduced to the same source moniker 'Po'

DBIx::Class::Migration::Script not fully honoring target_dir

I don't know if this is desired behaviour but I expected I would not need /share if target_dir is set to something different.

Running

PERL5LIB=./lib DBIC_MIGRATION_TARGET_DIR=./db/development DBIC_MIGRATION_SCHEMA_CLASS='MyTestApp::DB' dbic-migration prepare

against a test dbic fails with

Can't find a /share for MyTestApp

If /share is created the same command will create the _source and database specific dirs in the target dir but will create the fixtures in /share.
It was my understanding the fixtures dir was dependent on the target_dir. This applies to other commands too.

What I am actually trying to do is managing migrations for different environments in different directories. Those should go to /share/$environment, I just went off course for testing purpose.

I used perl 5.14.4 and the latest DBIx::Class::Migration version from CPAN that is 0.037 at the moment.

dbic_connect_attrs is ignored when populating data in DBIx::Class::Migration::RunScript

I am seeding data in my database as per this: https://metacpan.org/pod/distribution/DBIx-Class-Migration/lib/DBIx/Class/Migration/Tutorial/FirstMigration.pod#Customizing-the-Migration

However, dbic_connect_attrs is not being used when autogenerating the DBIx::Class::Schema::Loader schema, which means it is not possible to seed data for table names that require quoting (quote_names is dropped).

For info, I am using the following as a workaround:

use DBIx::Class::Migration::RunScript;
migrate {
    my $schema = shift->schema;
    $schema->storage->connect_info([sub {$schema->storage->dbh}, { quote_names => 1 }]);
    ...
}

FR: implement hook to drop other things

When we want to deploy clean database we clear current one: by drop_tables command, but it do not clear things which are manually added into migration scripts.

Example:

CREATE DOMAIN tkol AS NUMERIC(10,3)

Implement hook which will allow us to drop such thing

Documentation/better inference missing for what options are supported by --database

$ dbic-migration -Ilib prepare --database=Pg
Can't locate SQL/Translator/Producer/Pg.pm in @INC
....
$ postgres?
Can't locate...
$ postgresql? FFS!
Can't locate...
# open web-browser, look on metacpan for what the actual plugin is called...

Perhaps a "Did you mean PostgreSQL?" functionality. Otherwise a list of plugins, or a link to the SQLT list of said plugins would be useful.

Use a logging mechanism instead of warns and prints

I suggest using a logging mechanism, instead of warns and prints. My recommendation would be Log::Any.

However, one caveat is that it does not produce any output by default and needs logging enabled, which maybe not a good idea given that it is a cli tool and might need to communicate with the user.

DH uses Log::Contextual, I am assuming because frew also wrote that. We could use that as well. But I am not understanding it that well. I can't figure out if it is possible to redirect logs elsewhere, if a user chooses to do so. Or turn off completely. Or set different levels at run time.

FR: map database driver to database type or viceversa

In my config I can provide the database we are using: PostgreSQL, MySQL
But I can not use this type without mapping, because I get errors in different places:

$(which dbic-migration) —schema_class MyApp::Schema —database mysql -Ilib status
Can't locate SQL/Translator/Producer/mysql.pm in @INC (you may need to install the SQL::Translator::Producer::mysql module) (@INC contains: lib /home/sanek/work/projects/authdb/lib /home/sanek/work/projects/authdb/local/lib/perl5/x86_64-linux /home/sanek/work/projects/authdb/local/lib/perl5 /home/sanek/perl5/perlbrew/perls/perl-5.24.3/lib/site_perl/5.24.3/x86_64-linux /home/sanek/perl5/perlbrew/perls/perl-5.24.3/lib/site_perl/5.24.3 /home/sanek/perl5/perlbrew/perls/perl-5.24.3/lib/5.24.3/x86_64-linux /home/sanek/perl5/perlbrew/perls/perl-5.24.3/lib/5.24.3 .) at /home/sanek/work/projects/authdb/local/lib/perl5/DBIx/Class/Migration/Script.pm line 234.
Makefile:41: recipe for target 'dbstatus' failed
make: *** [dbstatus] Error 2
$(which dbic-migration) —schema_class MyApp::Schema —database MySQL -Ilib status
Schema is 1
DBIx::Class::Storage::DBI::_warn_undetermined_driver(): This version of DBIC does not yet seem to supply a driver for your particular RDBMS and/or connection method ('MySQL'). While we will attempt to continue anyway, the results are likely to be underwhelming. Please upgrade DBIC, and if this message does not go away, file a bugreport including the following info:
{
  DBD => "DBD::MySQL",
  DBD_VER => undef,
  DBIC_DRIVER => "DBIx::Class::Storage::DBI",
  DBIC_DSN => "dbi:MySQL:dbname=forexp;host=databases;port=3306",
  DBIC_VER => "0.082841",
  DBI_VER => "1.641",
}
DBIx::Class::Storage::DBI::sql_maker(): Your storage class (DBIx::Class::Storage::DBI) does not set sql_limit_dialect and you have not supplied an explicit limit_dialect in your connection_info. DBIC will attempt to use the GenericSubQ dialect, which works on most databases but can be (and often is) painfully slow. Please file an RT ticket against 'DBIx::Class::Storage::DBI' at inline delegation in DBIx::Class::DeploymentHandler::VersionStorage::Standard for version_rs->version_storage_is_installed (attribute declared in /home/sanek/work/projects/authdb/local/lib/perl5/DBIx/Class/DeploymentHandler/VersionStorage/Standard.pm at line 26) line 18
Database is not currently installed

It will be good if DBIx::Class::Migration will recognize database type by driver name or viceversa

Implement Upgrade/Downgrade scripts for first migration

When database is not versioned yet, but already exists it looks reasonable to generate upgrade/downgrade scripts which add/drop table for versioning:

MySQL/upgrade/0-1/001-auto.sql

CREATE TABLE `dbix_class_deploymenthandler_versions` (
  `id` integer NOT NULL auto_increment,
  `version` varchar(50) NOT NULL,
  `ddl` text NULL,
  `upgrade_sql` text NULL,
  PRIMARY KEY (`id`),
  UNIQUE `dbix_class_deploymenthandler_versions_version` (`version`)
);
SET foreign_key_checks=1;

MySQL/downgrade/1-0/001-auto.sql

DROP TABLE dbix_class_deploymenthandler_versions;

This will allow us to start versioning without deploying database from scratch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.