- Create the version 1 tables in a postgres schema, then create DBIC classes with
dbicdump.sh
- run
./gen_migration.pl 1
- Drop tables, and create version 2 tables from
db.sql
- run
./gen_migration.pl 2
- Check
sql/PostgreSQL/upgrade/1-2/001-auto.sql
- Should drop the
test_pkey
CONSTRAINT properly (need this for now: https://github.com/dbsrgits/sql-translator/pull/20/files) - Should know to add the new PRIMARY KEY on
test
table before adding the FOREIGN KEY totest2
table
- Should drop the
Created
June 2, 2012 14:55
-
-
Save throughnothing/2858724 to your computer and use it in GitHub Desktop.
DBIx::Class::DeploymentHandler Pkey + Ordering Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Original Tables (Version 1) | |
CREATE TABLE test ( | |
id SERIAL PRIMARY KEY, | |
code VARCHAR(255) UNIQUE NOT NULL, | |
discount INT NOT NULL DEFAULT 0 | |
); | |
CREATE TABLE test2 ( | |
id SERIAL PRIMARY KEY, | |
test_code VARCHAR(255) | |
); | |
# Version 2, after changes | |
CREATE TABLE test ( | |
code VARCHAR(255) PRIMARY KEY, | |
discount INT NOT NULL DEFAULT 0 | |
); | |
CREATE TABLE test2 ( | |
id SERIAL PRIMARY KEY, | |
test_code VARCHAR(255), | |
FOREIGN KEY (test_code) REFERENCES test (code) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
dbicdump Test::Schema 'dbi:Pg:dbname=test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use aliased 'DBIx::Class::DeploymentHandler' => 'DH'; | |
use Test::Schema; | |
my $schema = Test::Schema->connect('dbi:Pg:dbname=test', 'postgres'); | |
my $version = schema->VERSION || $ARGV[0]; | |
print "Version: $version\n"; | |
my $dh = DH->new({ | |
schema => $schema, | |
force_overwrite => 1, | |
databases => [qw/ PostgreSQL /], | |
sql_translator_args => { add_drop_table => 0 }, | |
}); | |
$dh->prepare_install; | |
if( $version > 1 ) { | |
$dh->prepare_upgrade({ | |
from_version => $version - 1, | |
to_version => $version, | |
version_set => [ $version - 1, $version ], | |
}); | |
$dh->prepare_downgrade({ | |
from_version => $version, | |
to_version => $version - 1, | |
version_set => [ $version - 1, $version ], | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment