8 #warn "$dsn $user $pass";
9 my ($dsn, $user, $pass);
12 ($dsn, $user, $pass) = @ENV{map { "DBICTEST_MYSQL_${_}" } qw/DSN USER PASS/};
14 plan skip_all => 'Set $ENV{DBICTEST_MYSQL_DSN}, _USER and _PASS to run this test'
18 eval "use DBD::mysql; use SQL::Translator 0.08;";
20 ? ( skip_all => 'needs DBD::mysql and SQL::Translator 0.08 for testing' )
24 my $version_table_name = 'dbix_class_schema_versions';
25 my $old_table_name = 'SchemaVersions';
28 use_ok('DBICVersionOrig');
30 my $schema_orig = DBICVersion::Schema->connect($dsn, $user, $pass);
31 eval { $schema_orig->storage->dbh->do('drop table ' . $version_table_name) };
32 eval { $schema_orig->storage->dbh->do('drop table ' . $old_table_name) };
34 is($schema_orig->ddl_filename('MySQL', 't/var', '1.0'), File::Spec->catfile('t', 'var', 'DBICVersion-Schema-1.0-MySQL.sql'), 'Filename creation working');
35 unlink('t/var/DBICVersion-Schema-1.0-MySQL.sql') if (-e 't/var/DBICVersion-Schema-1.0-MySQL.sql');
36 $schema_orig->create_ddl_dir('MySQL', undef, 't/var');
38 ok(-f 't/var/DBICVersion-Schema-1.0-MySQL.sql', 'Created DDL file');
39 $schema_orig->deploy({ add_drop_table => 1 });
40 $schema_orig->upgrade();
42 my $tvrs = $schema_orig->{vschema}->resultset('Table');
43 is($schema_orig->_source_exists($tvrs), 1, 'Created schema from DDL file');
45 eval "use DBICVersionNew";
47 unlink('t/var/DBICVersion-Schema-2.0-MySQL.sql');
48 unlink('t/var/DBICVersion-Schema-1.0-2.0-MySQL.sql');
50 my $schema_upgrade = DBICVersion::Schema->connect($dsn, $user, $pass);
51 is($schema_upgrade->get_db_version(), '1.0', 'get_db_version ok');
52 is($schema_upgrade->schema_version, '2.0', 'schema version ok');
53 $schema_upgrade->create_ddl_dir('MySQL', '2.0', 't/var', '1.0');
54 ok(-f 't/var/DBICVersion-Schema-1.0-2.0-MySQL.sql', 'Created DDL file');
55 $schema_upgrade->upgrade();
56 is($schema_upgrade->get_db_version(), '2.0', 'db version number upgraded');
59 $schema_upgrade->storage->dbh->do('select NewVersionName from TestVersion');
61 is($@, '', 'new column created');
65 my $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
67 $schema_version->storage->dbh->do('select * from ' . $version_table_name);
69 is($@, '', 'version table exists');
72 $schema_version->storage->dbh->do("DROP TABLE IF EXISTS $old_table_name");
73 $schema_version->storage->dbh->do("RENAME TABLE $version_table_name TO $old_table_name");
75 is($@, '', 'versions table renamed to old style table');
77 $schema_version = DBICVersion::Schema->connect($dsn, $user, $pass);
78 is($schema_version->get_db_version, '2.0', 'transition from old table name to new okay');
81 $schema_version->storage->dbh->do('select * from ' . $old_table_name);
83 ok($@, 'old version table gone');