From: Peter Rabbitson Date: Tue, 19 Jan 2010 12:47:48 +0000 (+0000) Subject: Merge 'trunk' into 'multiple_version_upgrade' X-Git-Tag: v0.08116~31^2~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d40a22fc4ecf7000051b91ffe3fee318f4e85cb4;p=dbsrgits%2FDBIx-Class.git Merge 'trunk' into 'multiple_version_upgrade' r8307@Thesaurus (orig r8295): abraxxa | 2010-01-13 17:28:05 +0100 added the sources parser arg to the example code r8327@Thesaurus (orig r8315): ribasushi | 2010-01-15 01:25:39 +0100 r8167@Thesaurus (orig r8155): ribasushi | 2009-12-19 12:50:13 +0100 New branch for null-only-result fix r8168@Thesaurus (orig r8156): ribasushi | 2009-12-19 12:51:21 +0100 Failing test r8322@Thesaurus (orig r8310): ribasushi | 2010-01-15 00:48:09 +0100 Correct test order r8323@Thesaurus (orig r8311): ribasushi | 2010-01-15 01:15:33 +0100 Generalize the to-node inner-join-er to apply to all related_resultset calls, not just counts r8324@Thesaurus (orig r8312): ribasushi | 2010-01-15 01:16:05 +0100 Adjust sql-emitter tests r8326@Thesaurus (orig r8314): ribasushi | 2010-01-15 01:25:10 +0100 One more sql-test fix and changes r8328@Thesaurus (orig r8316): ribasushi | 2010-01-15 01:31:58 +0100 Strict mysql bugfix r8329@Thesaurus (orig r8317): ribasushi | 2010-01-15 01:38:53 +0100 Better description of mysql strict option r8331@Thesaurus (orig r8319): ribasushi | 2010-01-15 03:12:13 +0100 Update troubleshooting doc r8337@Thesaurus (orig r8325): ribasushi | 2010-01-15 17:13:28 +0100 RT52674 r8346@Thesaurus (orig r8334): ribasushi | 2010-01-17 09:41:49 +0100 No method aliasing in OO code, *ever* r8373@Thesaurus (orig r8360): ribasushi | 2010-01-18 11:54:51 +0100 Adjust my email r8387@Thesaurus (orig r8374): ribasushi | 2010-01-19 13:07:07 +0100 r8340@Thesaurus (orig r8328): abraxxa | 2010-01-15 19:21:20 +0100 added branch no_duplicate_indexes_for_pk_cols with test and fix r8343@Thesaurus (orig r8331): abraxxa | 2010-01-15 19:32:16 +0100 don't use eq_set in test r8344@Thesaurus (orig r8332): abraxxa | 2010-01-15 19:44:04 +0100 don't sort the primary columns because order matters for indexes r8345@Thesaurus (orig r8333): abraxxa | 2010-01-15 19:56:46 +0100 don't sort the key columns because the order of columns is important for indexes r8372@Thesaurus (orig r8359): abraxxa | 2010-01-18 10:22:09 +0100 don't sort the columns in the tests either r8378@Thesaurus (orig r8365): abraxxa | 2010-01-18 15:39:28 +0100 added pod section for parser args r8379@Thesaurus (orig r8366): abraxxa | 2010-01-18 15:53:08 +0100 better pod thanks to ribasushi r8380@Thesaurus (orig r8367): abraxxa | 2010-01-18 16:04:34 +0100 test and pod fixes r8383@Thesaurus (orig r8370): abraxxa | 2010-01-19 12:38:44 +0100 fixed Authors section added License section fixed t/86sqlt.t tests r8384@Thesaurus (orig r8371): ribasushi | 2010-01-19 12:59:52 +0100 Regenaretd under new parser r8385@Thesaurus (orig r8372): ribasushi | 2010-01-19 13:03:51 +0100 Minor style change and white space trim r8386@Thesaurus (orig r8373): ribasushi | 2010-01-19 13:06:54 +0100 Changes abraxxa++ r8390@Thesaurus (orig r8377): ribasushi | 2010-01-19 13:41:03 +0100 Some minor test refactor and tab cleanups --- d40a22fc4ecf7000051b91ffe3fee318f4e85cb4 diff --cc lib/DBIx/Class/Schema/Versioned.pm index c7a89d7,c4daa0d..929e79b --- a/lib/DBIx/Class/Schema/Versioned.pm +++ b/lib/DBIx/Class/Schema/Versioned.pm @@@ -268,46 -268,19 +268,46 @@@ and the schema_version which is retriev =cut sub create_upgrade_path { - ## override this method + ## override this method } +=head2 ordered_schema_versions + +=over 4 + +=item Returns: a list of version numbers, ordered from lowest to highest + +=back + +Virtual method that should be overriden to return an ordered list +of schema versions. This is then used to produce a set of steps to +upgrade through to achieve the required schema version. + +You may want the db_version retrieved via $self->get_db_version +and the schema_version which is retrieved via $self->schema_version + +=cut + +sub ordered_schema_versions { + ## override this method +} + =head2 upgrade -Call this to attempt to upgrade your database from the version it is at to the version -this DBIC schema is at. If they are the same it does nothing. +Call this to attempt to upgrade your database from the version it +is at to the version this DBIC schema is at. If they are the same +it does nothing. -It requires an SQL diff file to exist in you I, normally you will -have created this using L. +It will call L to retrieve an ordered +list of schema versions (if ordered_schema_versions returns nothing +then it is assumed you can do the upgrade as a single step). It +then iterates through the list of versions between the current db +version and the schema version applying one update at a time until +all relvant updates are applied. -If successful the dbix_class_schema_versions table is updated with the current -DBIC schema version. +The individual update steps are performed by using +L, which will apply the update and also +update the dbix_class_schema_versions table. =cut diff --cc t/94versioning.t index 4d3c780,2d286ef..f901965 --- a/t/94versioning.t +++ b/t/94versioning.t @@@ -28,13 -31,11 +31,13 @@@ BEGIN my $version_table_name = 'dbix_class_schema_versions'; my $old_table_name = 'SchemaVersions'; - my $ddl_dir = File::Spec->catdir ('t', 'var'); + my $ddl_dir = dir ('t', 'var'); my $fn = { - v1 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-1.0-MySQL.sql'), - v2 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-2.0-MySQL.sql'), - v3 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-3.0-MySQL.sql'), - trans_v12 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-1.0-2.0-MySQL.sql'), - trans_v23 => File::Spec->catfile($ddl_dir, 'DBICVersion-Schema-2.0-3.0-MySQL.sql'), + v1 => $ddl_dir->file ('DBICVersion-Schema-1.0-MySQL.sql'), + v2 => $ddl_dir->file ('DBICVersion-Schema-2.0-MySQL.sql'), - trans => $ddl_dir->file ('DBICVersion-Schema-1.0-2.0-MySQL.sql'), ++ v3 => $ddl_dir->file ('DBICVersion-Schema-3.0-MySQL.sql'), ++ trans_v12 => $ddl_dir-> ('DBICVersion-Schema-1.0-2.0-MySQL.sql'), ++ trans_v23 => $ddl_dir-> ('DBICVersion-Schema-2.0-3.0-MySQL.sql'), }; use lib qw(t/lib); @@@ -58,48 -59,39 +61,39 @@@ is($schema_v1->_source_exists($tvrs), 1 # loading a new module defining a new version of the same table DBICVersion::Schema->_unregister_source ('Table'); -eval "use DBICVersionNew"; +eval "use DBICVersion_v2"; -my $schema_upgrade = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 }); +my $schema_v2 = DBICVersion::Schema->connect($dsn, $user, $pass, { ignore_version => 1 }); { unlink($fn->{v2}); - unlink($fn->{trans}); + unlink($fn->{trans_v12}); - is($schema_upgrade->get_db_version(), '1.0', 'get_db_version ok'); - is($schema_upgrade->schema_version, '2.0', 'schema version ok'); - $schema_upgrade->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0'); - ok(-f $fn->{trans}, 'Created DDL file'); + is($schema_v2->get_db_version(), '1.0', 'get_db_version ok'); + is($schema_v2->schema_version, '2.0', 'schema version ok'); + $schema_v2->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0'); + ok(-f $fn->{trans_v12}, 'Created DDL file'); - { - my $w; - local $SIG{__WARN__} = sub { $w = shift }; - - $schema_v2->upgrade(); - like ($w, qr/Attempting upgrade\.$/, 'Warn before upgrade'); - } + sleep 1; # remove this when TODO below is completed + warnings_like ( - sub { $schema_upgrade->upgrade() }, ++ sub { $schema_v2->upgrade() }, + qr/DB version .+? is lower than the schema version/, + 'Warn before upgrade', + ); - is($schema_upgrade->get_db_version(), '2.0', 'db version number upgraded'); + is($schema_v2->get_db_version(), '2.0', 'db version number upgraded'); - eval { + lives_ok ( sub { - $schema_upgrade->storage->dbh->do('select NewVersionName from TestVersion'); + $schema_v2->storage->dbh->do('select NewVersionName from TestVersion'); - }; - is($@, '', 'new column created'); - - # should overwrite files and warn about it - my @w; - local $SIG{__WARN__} = sub { - if ($_[0] =~ /Overwriting existing/) { - push @w, $_[0]; - } - else { - warn @_; - } - }; - $schema_v2->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0'); - - is (2, @w, 'A warning generated for both the DDL and the diff'); - like ($w[0], qr/Overwriting existing DDL file - $fn->{v2}/, 'New version DDL overwrite warning'); - like ($w[1], qr/Overwriting existing diff file - $fn->{trans_v12}/, 'Upgrade diff overwrite warning'); + }, 'new column created' ); + + warnings_exist ( - sub { $schema_upgrade->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0') }, ++ sub { $schema_v2->create_ddl_dir('MySQL', '2.0', $ddl_dir, '1.0') }, + [ + qr/Overwriting existing DDL file - $fn->{v2}/, + qr/Overwriting existing diff file - $fn->{trans}/, + ], + 'An overwrite warning generated for both the DDL and the diff', + ); } {