From: Eden Cardim Date: Fri, 7 May 2010 16:16:03 +0000 (+0000) Subject: dbicadmin can now install non-versioned schemas X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a03b396bd7cd939f7f70ec42f56761636b8b9f7e;p=dbsrgits%2FDBIx-Class-Historic.git dbicadmin can now install non-versioned schemas --- diff --git a/lib/DBIx/Class/Admin.pm b/lib/DBIx/Class/Admin.pm index 284f72d..20a86b8 100644 --- a/lib/DBIx/Class/Admin.pm +++ b/lib/DBIx/Class/Admin.pm @@ -195,7 +195,7 @@ has 'config_stanza' => ( =head2 config -Instead of loading from a file the configuration can be provided directly as a hash ref. Please note +Instead of loading from a file the configuration can be provided directly as a hash ref. Please note config_stanza will still be required. =cut @@ -296,8 +296,8 @@ has '_confirm' => ( =back -L will generate sql for the supplied schema_class in sql_dir. The flavour of sql to -generate can be controlled by suppling a sqlt_type which should be a L name. +L will generate sql for the supplied schema_class in sql_dir. The flavour of sql to +generate can be controlled by suppling a sqlt_type which should be a L name. Arguments for L can be supplied in the sqlt_args hashref. @@ -352,9 +352,9 @@ sub upgrade { =back -install is here to help when you want to move to L and have an existing -database. install will take a version and add the version tracking tables and 'install' the version. No -further ddl modification takes place. Setting the force attribute to a true value will allow overriding of +install is here to help when you want to move to L and have an existing +database. install will take a version and add the version tracking tables and 'install' the version. No +further ddl modification takes place. Setting the force attribute to a true value will allow overriding of already versioned databases. =cut @@ -391,7 +391,7 @@ sub install { =back -deploy will create the schema at the connected database. C<$args> are passed straight to +deploy will create the schema at the connected database. C<$args> are passed straight to L. =cut @@ -399,13 +399,7 @@ L. sub deploy { my ($self, $args) = @_; my $schema = $self->schema(); - if (!$schema->get_db_version() ) { - # schema is unversioned - $schema->deploy( $args, $self->sql_dir) - or $schema->throw_exception ("Could not deploy schema.\n"); # FIXME deploy() does not return 1/0 on success/fail - } else { - $schema->throw_exception("A versioned schema has already been deployed, try upgrade instead.\n"); - } + $schema->deploy( $args, $self->sql_dir ); } =head2 insert @@ -502,7 +496,7 @@ sub delete { =back -select takes the name of a resultset from the schema_class, a where hashref and a attrs to pass to ->search. +select takes the name of a resultset from the schema_class, a where hashref and a attrs to pass to ->search. The found data is returned in a array ref where the first row will be the columns list. =cut @@ -518,7 +512,7 @@ sub select { my @data; my @columns = $resultset->result_source->columns(); - push @data, [@columns];# + push @data, [@columns];# while (my $row = $resultset->next()) { my @fields; diff --git a/lib/DBIx/Class/Schema/Versioned.pm b/lib/DBIx/Class/Schema/Versioned.pm index aa4f702..70f4ffe 100644 --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@ -225,7 +225,7 @@ sub install # must be called on a fresh database if ($self->get_db_version()) { - carp 'Install not possible as versions table already exists in database'; + $self->throw_exception("A versioned schema has already been deployed, try upgrade instead.\n"); } # default to current version if none passed @@ -681,13 +681,13 @@ sub _set_db_version { # This is necessary since there are legitimate cases when upgrades can happen # back to back within the same second. This breaks things since we relay on the # ability to sort by the 'installed' value. The logical choice of an autoinc - # is not possible, as it will break multiple legacy installations. Also it is + # is not possible, as it will break multiple legacy installations. Also it is # not possible to format the string sanely, as the column is a varchar(20). # The 'v' character is added to the front of the string, so that any version # formatted by this new function will sort _after_ any existing 200... strings. my @tm = gettimeofday(); my @dt = gmtime ($tm[0]); - my $o = $vtable->create({ + my $o = $vtable->create({ version => $version, installed => sprintf("v%04d%02d%02d_%02d%02d%02d.%03.0f", $dt[5] + 1900,