Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed regression and more docs, + new ENV features

  • Loading branch information...
commit e85a1f3495fcf5608c8528808acd3b0fc4142485 1 parent cb8694a
@jjn1056 authored
View
4 Changes
@@ -1,7 +1,9 @@
Revision history for DBIx-Class-Migration
-0.021 09 April 2012
+0.021 11 April 2012
- Documentation and debug output fixes (RsrchBoy++)
+ - fixed regression when using DBIC:DeploymentHandler v0.002112+
+ (lxp@cpan.org++)
- New Feature: We set %ENV variables for key settings so that
information is passed to install / up-downgrade scripts.
View
123 README.mkdn
@@ -98,18 +98,18 @@ documentation on the various internals.
This class defines the following attributes.
-## db_sandbox_builder_class
+## 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"](#target_dir), which
+sandboxs. By default we build database sandboxes in the ["target\_dir"](#target\_dir), which
is what [DBIx::Class::Migration::TargetDirSandboxBuilder](http://search.cpan.org/perldoc?DBIx::Class::Migration::TargetDirSandboxBuilder) does. We can also
build database sandboxes in a temporary directory using
[DBIx::Class::Migration::TempDirSandboxBuilder](http://search.cpan.org/perldoc?DBIx::Class::Migration::TempDirSandboxBuilder). You might prefer that for
running tests, for example.
-## db_sandbox_class
+## db\_sandbox\_class
Accepts Str. Not Required (defaults to 'DBIx::Class::Migration::SqliteSandbox').
@@ -129,15 +129,15 @@ and [DBIx::Class::Migration::PgSandbox](http://search.cpan.org/perldoc?DBIx::Cla
[Test::mysqld](http://search.cpan.org/perldoc?Test::mysqld) and [Test::postgresql](http://search.cpan.org/perldoc?Test::postgresql) (In other words you'd need to add
these `Test::*` namespace modules to your `Makefile.PL` or `dist.ini`).
-## db_sandbox
+## db\_sandbox
Accepts: Object. Not required.
-This is an instantiated object as defined by ["db_sandbox_class"](#db_sandbox_class). It is a
+This is an instantiated object as defined by ["db\_sandbox\_class"](#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
+## schema\_class
Accepts Str. Not Required (but if missing, you need to populate ["schema"](#schema)).
@@ -145,40 +145,40 @@ 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](http://search.cpan.org/perldoc?DBIx::Class::Schema). For example `MyApp::Schema`.
-If the ["schema_class"](#schema_class) cannot be loaded, a hard exception will be thrown.
+If the ["schema\_class"](#schema\_class) cannot be loaded, a hard exception will be thrown.
-## schema_args
+## schema\_args
Accepts ArrayRef. Required but lazily builds from defaults
-Provides arguments passed to `connect` on your ["schema_class"](#schema_class). Should
+Provides arguments passed to `connect` on your ["schema\_class"](#schema\_class). Should
connect to a database.
This is an arrayref that would work the same as ["connect" in DBIx::Class::Schema](http://search.cpan.org/perldoc?DBIx::Class::Schema#connect).
If you choose to create an instance of [DBIx::Class::Migration](http://search.cpan.org/perldoc?DBIx::Class::Migration) by providing a
-[schema_class](http://search.cpan.org/perldoc?schema_class), you can use this to customize how we connect to a database.
+[schema\_class](http://search.cpan.org/perldoc?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 c<[path to target_dir]> is ["target_dir"](#target_dir) and [db_file_name] is a converted
-version of ["schema_class"](#schema_class). For example if you set [schema_class](http://search.cpan.org/perldoc?schema_class) to:
+Where c<\[path to target\_dir\]> is ["target\_dir"](#target\_dir) and \[db\_file\_name\] is a converted
+version of ["schema\_class"](#schema\_class). For example if you set [schema\_class](http://search.cpan.org/perldoc?schema\_class) to:
MyApp::Schema
-Then [db_file_name] would be `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](http://search.cpan.org/perldoc?schema_class) and get deploying!
+without a lot of effort, just point at a [schema\_class](http://search.cpan.org/perldoc?schema\_class) and get deploying!
## schema
Accepts: Object of [DBIx::Class::Schema](http://search.cpan.org/perldoc?DBIx::Class::Schema). Not required.
If you already have a connected schema (subclass of [DBIx::Class::Schema](http://search.cpan.org/perldoc?DBIx::Class::Schema))
-you can simple point to it, skipping [schema_class](http://search.cpan.org/perldoc?schema_class) and [schema_args](http://search.cpan.org/perldoc?schema_args). You
+you can simple point to it, skipping [schema\_class](http://search.cpan.org/perldoc?schema\_class) and [schema\_args](http://search.cpan.org/perldoc?schema\_args). You
might for example be using [Catalyst](http://search.cpan.org/perldoc?Catalyst) and want to build deployments for a
database that is listed in configuration:
@@ -190,19 +190,19 @@ database that is listed in configuration:
%{MyCatalyst::App->config->{extra_migration_init_args}};
);
-## target_dir_builder_class
+## 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"](#target_dir) should the
+This is a class that is used as a helper to build ["target\_dir"](#target\_dir) should the
user not provide a value. Default is [DBIx::Class::Migration::ShareDirBuilder](http://search.cpan.org/perldoc?DBIx::Class::Migration::ShareDirBuilder)
-## target_dir_builder
+## target\_dir\_builder
-An instance of whatever is in ["target_dir_builder_class"](#target_dir_builder_class). Used by the lazy
-build method of ["target_dir"](#target_dir) to default a directory where the migrations are
+An instance of whatever is in ["target\_dir\_builder\_class"](#target\_dir\_builder\_class). Used by the lazy
+build method of ["target\_dir"](#target\_dir) to default a directory where the migrations are
actually placed.
-## target_dir
+## target\_dir
Accepts Str. Required (lazy builds to your distribution `/share` directory).
@@ -216,15 +216,15 @@ considered a community practice in regards to where to store your distribution
non code files. Please see [File::ShareDir::ProjectDistDir](http://search.cpan.org/perldoc?File::ShareDir::ProjectDistDir) as well as
[File::ShareDir](http://search.cpan.org/perldoc?File::ShareDir) for more information.
-This uses whatever is in ["schema_class"](#schema_class) to determine your project (and look
+This uses whatever is in ["schema\_class"](#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"](#schema_class) defined, you must have a ["schema"](#schema),
+If you don't have a ["schema\_class"](#schema\_class) defined, you must have a ["schema"](#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
+## schema\_loader\_class
Accepts Str. Required
@@ -237,7 +237,7 @@ Defaults to [DBIx::Class::Migration::SchemaLoader](http://search.cpan.org/perldo
need to change this if your database is crazy and you need to massage the
init arguments to [DBIx::Class::Schema::Loader](http://search.cpan.org/perldoc?DBIx::Class::Schema::Loader).
-## schema_loader
+## schema\_loader
Accepts Object. Required but lazy builds.
@@ -245,7 +245,7 @@ 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
+## dbic\_fixture\_class
Accepts Str. Required
@@ -256,15 +256,15 @@ rules work in order to best take advantage of the system.
Defaults to [DBIx::Class::Fixtures](http://search.cpan.org/perldoc?DBIx::Class::Fixtures). You'll probably not need to change this
unless you have some unusual needs regarding fixtures.
-## dbic_fixtures_extra_args
+## 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"](#dbic_fixture_class). These arguments can be used to override the default
+["dbic\_fixture\_class"](#dbic\_fixture\_class). These arguments can be used to override the default
initial arguments.
-## deployment_handler_class
+## deployment\_handler\_class
Accepts Str. Required
@@ -277,7 +277,7 @@ 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
useing monotonic versioning.
-## dbic_dh_args
+## dbic\_dh\_args
Accepts HashRef. Required and defaults to an empty hashref.
@@ -285,24 +285,24 @@ Used to pass custom args when building a [DBIx::Class::DeploymentHandler](http:/
Please see the docs for that class for more. Useful args might be `databases`,
`to_version` and `force_overwrite`.
-## dbic_dh
+## dbic\_dh
Accepts Instance of [DBIx::Class::DeploymentHandler](http://search.cpan.org/perldoc?DBIx::Class::DeploymentHandler). Required but lazily
-built from default data and [dbic_dh_args](http://search.cpan.org/perldoc?dbic_dh_args).
+built from default data and [dbic\_dh\_args](http://search.cpan.org/perldoc?dbic\_dh\_args).
You probably won't need to build your own deployment handler and pass it in
(unlike [schema](http://search.cpan.org/perldoc?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"](#dbic_dh_args) with the
+When this attribute is lazily built, we merge ["dbic\_dh\_args"](#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"](#dbic_dh_args) will overwrite the defaults, if you pass them.
+["dbic\_dh\_args"](#dbic\_dh\_args) will overwrite the defaults, if you pass them.
# METHODS
@@ -313,7 +313,7 @@ This class defines the following methods for public use
Used to create an new instance of [DBIx::Class::Migration](http://search.cpan.org/perldoc?DBIx::Class::Migration). There's a couple
of paths to creating this instance.
-### Specify a schema_class and optionally schema_args
+### Specify a schema\_class and optionally schema\_args
use DBIx::Class::Migration;
my $migration = DBIx::Class::Migration->new(
@@ -324,8 +324,8 @@ of paths to creating this instance.
This is probably the most general approach, and is recommended unless you
already have a connected instance of your [DBIx::Class::Schema](http://search.cpan.org/perldoc?DBIx::Class::Schema) subclass.
-["schema_args"](#schema_args) would be anything you'd pass to ["connect" in DBIx::Class::Schema](http://search.cpan.org/perldoc?DBIx::Class::Schema#connect).
-see ["schema_args"](#schema_args) for how we construct default connect information if you
+["schema\_args"](#schema\_args) would be anything you'd pass to ["connect" in DBIx::Class::Schema](http://search.cpan.org/perldoc?DBIx::Class::Schema#connect).
+see ["schema\_args"](#schema\_args) for how we construct default connect information if you
choose to leave this undefined.
### Specify a schema
@@ -344,7 +344,7 @@ wish to build custom scripts using the built-in dependency and service lookup:
Be careful of potential locking issues when using some databases like SQLite.
-### OPTIONAL: Specify a target_dir
+### 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
@@ -362,14 +362,14 @@ 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 dbic_dh_args
+### OPTIONAL: Specify dbic\_dh\_args
Optionally, you can specify additional arguments to the constructor for the
-["dbic_dh"](#dbic_dh) attribute. Useful arguments might include additional `databases`
+["dbic\_dh"](#dbic\_dh) attribute. Useful arguments might include additional `databases`
we should build fixtures for, `to_version` and `force_overwrite`.
See [DBIx::Class::DeploymentHandler](http://search.cpan.org/perldoc?DBIx::Class::DeploymentHandler) for more information on supported init
-arguments. See ["dbic_dh"](#dbic_dh) for how we merge default arguments with your custom
+arguments. See ["dbic\_dh"](#dbic\_dh) for how we merge default arguments with your custom
arguments.
### Other Initial Arguments
@@ -388,23 +388,23 @@ of the current `schema` version. Sends this as a string to STDOUT
## prepare
-Creates a `fixtures` and `migrations` directory under ["target_dir"](#target_dir) (if they
+Creates a `fixtures` and `migrations` directory under ["target\_dir"](#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"](#overwrite_migrations) and
-["overwrite_fixtures"](#overwrite_fixtures).
+deployment files exist, will fail unless you ["overwrite\_migrations"](#overwrite\_migrations) and
+["overwrite\_fixtures"](#overwrite\_fixtures).
The `migrations` directory reflects a directory structure as documented in
[DBIx::Class::DeploymentHandler](http://search.cpan.org/perldoc?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
+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](http://search.cpan.org/perldoc?dbic_dh_args) to the
+version specified via any `to_version` flags sent as an [dbic\_dh\_args](http://search.cpan.org/perldoc?dbic\_dh\_args) to the
database which is connected via ["schema"](#schema)
## upgrade
@@ -417,12 +417,12 @@ version.
Run down files to bring the database down to the previous version from what is
installed to the database
-## drop_tables
+## 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
+## 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
@@ -430,19 +430,19 @@ 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
+## dump\_named\_sets
Given an array of fixture set names, dump them for the current database version.
-## dump_all_sets
+## dump\_all\_sets
Takes no arguments just dumps all the sets we can find for the current database
version.
-## make_schema
+## make\_schema
Given an existing database, reverse engineer a [DBIx::Class](http://search.cpan.org/perldoc?DBIx::Class) Schema in the
-["target_dir"](#target_dir) (under `dumped_db`). You can use this if you need to bootstrap
+["target\_dir"](#target\_dir) (under `dumped_db`). You can use this if you need to bootstrap
your DBIC files.
## populate
@@ -451,11 +451,11 @@ 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"](#drop_tables) which does delete it.)
+deployment info (this is different from ["drop\_tables"](#drop\_tables) which does delete it.)
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"](#target_dir) called `db-diagram-vXXX.png` where `XXX` is he current
+your ["target\_dir"](#target\_dir) called `db-diagram-vXXX.png` where `XXX` is he current
`schema` version.
This is using the Graphviz producer ([SQL::Translator::Producer::GraphViz](http://search.cpan.org/perldoc?SQL::Translator::Producer::GraphViz))
@@ -468,7 +468,7 @@ am still determining the best way to meet the need without exceeding the
scope of [DBIx::Class::Migration](http://search.cpan.org/perldoc?DBIx::Class::Migration). Consider this command a 'freebee' and
please don't depend on it in your custom code.
-## install_if_needed
+## install\_if\_needed
If the database is not installed, do so. Accepts a hash of callbacks or
instructions to perform should installation be needed/
@@ -482,7 +482,7 @@ instructions to perform should installation be needed/
The following callbacks / instructions are permitted
-- on_install
+- on\_install
Accepts: Coderef
@@ -490,7 +490,7 @@ 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
+- default\_fixture\_sets
Accepts: Arrayref of fixture sets
@@ -499,7 +499,7 @@ Accepts: Arrayref of fixture sets
After database installation, populate the fixtures in order.
-## install_version_storage
+## 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
@@ -514,16 +514,19 @@ a huge production database that you now want to start versioning).
When running [DBIx::Class::Migration](http://search.cpan.org/perldoc?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'"](#DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator\'PERL SCRIPTS'))
+["DBIx::Class::DeploymentHandler::DeployMethod::SQL::Translator\\'PERL SCRIPTS'"](#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
View
7 lib/DBIx/Class/Migration.pm
@@ -478,10 +478,11 @@ sub install_version_storage {
before [qw/install upgrade downgrade/], sub {
my ($self, @args) = @_;
- local %ENV = (
+ %ENV = (
%ENV,
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 => (
@@ -1017,10 +1018,14 @@ can receive some useful information. The Following C<%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.
=head1 THANKS
View
6 lib/DBIx/Class/Migration/RunScript/Trait/SchemaLoader.pm
@@ -6,11 +6,7 @@ use DBIx::Class::Migration::SchemaLoader;
requires 'dbh';
-has 'schema' => (
- is=>'ro',
- lazy_build=>1);
-
-sub _build_schema {
+sub schema {
my $dbh = (my $self = shift)->dbh;
my $name = DBIx::Class::Migration::SchemaLoader::_as_unique_ns(
'DBIx::Class::Migration::LoadedSchema');
View
3  t/migration-sqlite.t
@@ -43,6 +43,9 @@ open(
print $perl_run <<'END';
use DBIx::Class::Migration::RunScript;
+use Test::Most;
+
+ok $ENV{DBIC_MIGRATION_TARGET_DIR};
builder {
'SchemaLoader',
Please sign in to comment.
Something went wrong with that request. Please try again.