Skip to content

Instantly share code, notes, and snippets.

@rjattrill
Created June 13, 2012 06:01
Show Gist options
  • Save rjattrill/2922152 to your computer and use it in GitHub Desktop.
Save rjattrill/2922152 to your computer and use it in GitHub Desktop.
Create Schema from Database with DBIx::DataModel
use Modern::Perl;
use DBIx::DataModel;
use DBIx::DataModel::Schema::Generator qw(fromDBI);
use FindBin qw($Bin);
my $schema = 'Scratch';
my $schema_name = $schema . "::Schema";
my $generator = DBIx::DataModel::Schema::Generator->new(-schema => $schema_name);
my $dbi_dsn = 'dbi:ODBC:Driver={SQL Server Native Client 10.0};Server=localhost,1433;Database=scratch;';
my $user = 'scratch';
my $password = 'PASSWORD';
my $schema_file = "$Bin/lib/$schema/Schema.pm";
say "Writing schema to file: $schema_file";
open STDOUT, '>', $schema_file or die "Problem opening output file $schema_file : $!";
$generator->fromDBI($dbi_dsn, $user, $password) or die "Problem getting schema from database: $!";
close STDOUT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment