use warnings;
__PACKAGE__->load_components(qw/ Core/);
-__PACKAGE__->table('SchemaVersions');
+__PACKAGE__->table('dbix_class_schema_versions');
__PACKAGE__->add_columns
( 'Version' => {
);
__PACKAGE__->set_primary_key('Version');
+package DBIx::Class::Version::TableCompat;
+use base 'DBIx::Class::Version::Table';
+
+__PACKAGE__->table('SchemaVersions');
+
package DBIx::Class::Version;
use base 'DBIx::Class::Schema';
use strict;
__PACKAGE__->register_class('Table', 'DBIx::Class::Version::Table');
+package DBIx::Class::VersionCompat;
+use base 'DBIx::Class::Schema';
+use strict;
+use warnings;
+
+__PACKAGE__->register_class('TableCompat', 'DBIx::Class::Version::TableCompat');
+
# ---------------------------------------------------------------------------
module, you need to have called C<create_ddl_dir> on your Schema to
create your upgrade files to include with your delivery.
-A table called I<SchemaVersions> is created and maintained by the
+A table called I<dbix_class_schema_versions> is created and maintained by the
module. This contains two fields, 'Version' and 'Installed', which
contain each VERSION of your Schema, and the date+time it was installed.
=head2 get_db_version
Returns the version that your database is currently at. This is determined by the values in the
-SchemaVersions table that $self->upgrade writes to.
+dbix_class_schema_versions table that $self->upgrade writes to.
=cut
# db unversioned
unless ($db_version) {
- # set version in SchemaVersions table, can't actually upgrade as we don 't know what version the DB is at
+ # set version in dbix_class_schema_versions table, can't actually upgrade as we don 't know what version the DB is at
$self->_create_db_to_schema_diff() if ($self->do_diff_on_init);
# create versions table and version row
$self->backup() if($self->do_backup);
$self->txn_do(sub { $self->do_upgrade() });
- # set row in SchemaVersions table
+ # set row in dbix_class_schema_versions table
$self->_set_db_version;
}
{
my ($self) = @_;
$self->{vschema} = DBIx::Class::Version->connect(@{$self->storage->connect_info()});
+ my $vtable = $self->{vschema}->resultset('Table');
+
+ # check for legacy versions table and move to new if exists
+ my $vschema_compat = DBIx::Class::VersionCompat->connect(@{$self->storage->connect_info()});
+ unless ($self->_source_exists($vtable)) {
+ my $vtable_compat = $vschema_compat->resultset('TableCompat');
+ if ($self->_source_exists($vtable_compat)) {
+ $self->{vschema}->deploy;
+ map { $vtable->create({$_->get_columns}) } $vtable_compat->all;
+ $self->storage->dbh->do("DROP TABLE " . $vtable_compat->result_source->from);
+ }
+ }
my $pversion = $self->get_db_version();
eval "use DBD::mysql; use SQL::Translator 0.08;";
plan $@
? ( skip_all => 'needs DBD::mysql and SQL::Translator 0.08 for testing' )
- : ( tests => 9 );
+ : ( tests => 13 );
}
+my $version_table_name = 'dbix_class_schema_versions';
+my $old_table_name = 'SchemaVersions';
+
use lib qw(t/lib);
use_ok('DBICVersionOrig');
my $schema_orig = DBICVersion::Schema->connect($dsn, $user, $pass);
-eval { $schema_orig->storage->dbh->do('drop table SchemaVersions') };
+eval { $schema_orig->storage->dbh->do('drop table ' . $version_table_name) };
+eval { $schema_orig->storage->dbh->do('drop table ' . $old_table_name) };
is($schema_orig->ddl_filename('MySQL', 't/var', '1.0'), File::Spec->catfile('t', 'var', 'DBICVersion-Schema-1.0-MySQL.sql'), 'Filename creation working');
unlink('t/var/DBICVersion-Schema-1.0-MySQL.sql') if (-e 't/var/DBICVersion-Schema-1.0-MySQL.sql');
};
is($@, '', 'new column created');
}
+
+{
+ my $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
+ eval {
+ $schema_version->storage->dbh->do('select * from ' . $version_table_name);
+ };
+ is($@, '', 'version table exists');
+
+ eval {
+ $schema_version->storage->dbh->do("DROP TABLE IF EXISTS $old_table_name");
+ $schema_version->storage->dbh->do("RENAME TABLE $version_table_name TO $old_table_name");
+ };
+ is($@, '', 'versions table renamed to old style table');
+
+ $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
+ is($schema_version->get_db_version, '2.0', 'transition from old table name to new okay');
+
+ eval {
+ $schema_version->storage->dbh->do('select * from ' . $old_table_name);
+ };
+ ok($@, 'old version table gone');
+
+}