Skip to content

Instantly share code, notes, and snippets.

@rbo
Created June 8, 2010 18:47
Show Gist options
  • Save rbo/430465 to your computer and use it in GitHub Desktop.
Save rbo/430465 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
# Script from getty:
# http://www.raudssus.de/blog/dbix-class-autoupgrade
use MyApp::Schema;
use SQL::Translator::Diff;
use SQL::Translator;
{
package MyApp::SchemaOld;
use base qw/DBIx::Class::Schema::Loader/;
}
# Connect use :
# http://search.cpan.org/dist/DBI/DBI.pm#DBI_ENVIRONMENT_VARIABLES
my $schema = MyApp::Schema->connect();
my $old_schema = MyApp::SchemaOld->connect();
my $diff = SQL::Translator::Diff::schema_diff(
SQL::Translator->new(
parser => 'SQL::Translator::Parser::DBIx::Class',
parser_args => { package => $old_schema }
)->translate(),
$old_schema->storage->sqlt_type,
SQL::Translator->new(
parser => 'SQL::Translator::Parser::DBIx::Class',
parser_args => { package => $schema }
)->translate(),
$schema->storage->sqlt_type,
{
ignore_constraint_names => 1,
ignore_index_names => 1,
caseopt => 1,
no_comments => 1
}
);
for (@diff) {
next if m/^-- /;
$schema->storage->dbh_do(
sub {
my ( $self, $dbh ) = @_;
$dbh->do($_);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment