Created
June 13, 2012 06:01
-
-
Save rjattrill/2922152 to your computer and use it in GitHub Desktop.
Create Schema from Database with DBIx::DataModel
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
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