From: Peter Rabbitson Date: Mon, 26 Aug 2013 12:19:43 +0000 (+0200) Subject: Automatically regenerate the example ddl/db from the example Schema X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6635c6d22b8b28954db80113273584027e16d9e1;p=dbsrgits%2FDBIx-Class-Historic.git Automatically regenerate the example ddl/db from the example Schema --- diff --git a/.gitignore b/.gitignore index 80fc61d..c8cda3e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,4 @@ t/var/ .#* *~ maint/.Generated_Pod +examples/Schema/db diff --git a/examples/Schema/db/example.db b/examples/Schema/db/example.db deleted file mode 100644 index a7d8330..0000000 Binary files a/examples/Schema/db/example.db and /dev/null differ diff --git a/examples/Schema/db/example.sql b/examples/Schema/db/example.sql deleted file mode 100644 index 3aeba46..0000000 --- a/examples/Schema/db/example.sql +++ /dev/null @@ -1,17 +0,0 @@ -CREATE TABLE artist ( - artistid INTEGER PRIMARY KEY, - name TEXT NOT NULL -); - -CREATE TABLE cd ( - cdid INTEGER PRIMARY KEY, - artist INTEGER NOT NULL REFERENCES artist(artistid), - title TEXT NOT NULL, - year DATETIME -); - -CREATE TABLE track ( - trackid INTEGER PRIMARY KEY, - cd INTEGER NOT NULL REFERENCES cd(cdid), - title TEXT NOT NULL -); diff --git a/maint/Makefile.PL.inc/56_autogen_schema_files.pl b/maint/Makefile.PL.inc/56_autogen_schema_files.pl index 446cc2a..6096010 100644 --- a/maint/Makefile.PL.inc/56_autogen_schema_files.pl +++ b/maint/Makefile.PL.inc/56_autogen_schema_files.pl @@ -1,6 +1,11 @@ require File::Spec; -my $test_ddl_fn = File::Spec->catfile(qw( t lib sqlite.sql )); -my @test_ddl_cmd = qw( -I lib -I t/lib -- maint/gen_sqlite_schema_files --schema-class DBICTest::Schema ); +my $test_ddl_fn = File::Spec->catfile(qw( t lib sqlite.sql )); +my @test_ddl_cmd = qw( -I lib -I t/lib -- maint/gen_sqlite_schema_files --schema-class DBICTest::Schema ); + +my $example_ddl_fn = File::Spec->catfile(qw( examples Schema db example.sql )); +my $example_db_fn = File::Spec->catfile(qw( examples Schema db example.db )); +my @example_ddl_cmd = qw( -I lib -I examples/Schema -- maint/gen_sqlite_schema_files --schema-class MyApp::Schema ); +my @example_pop_cmd = qw( -I lib -I examples/Schema -- examples/Schema/insertdb.pl ); # If the author doesn't have the prereqs, still generate a Makefile # The EUMM build-stage generation will run unconditionally and @@ -10,6 +15,12 @@ if ( DBIx::Class::Optional::Dependencies->req_ok_for ('deploy') ) { print "Regenerating $test_ddl_fn\n"; system( $^X, @test_ddl_cmd, '--ddl-out' => $test_ddl_fn ); + print "Regenerating $example_ddl_fn and $example_db_fn\n"; + system( $^X, @example_ddl_cmd, '--ddl-out' => $example_ddl_fn, '--deploy-to' => $example_db_fn ); + + print "Populating $example_db_fn\n"; + system( $^X, @example_pop_cmd ); + # if we don't do it some git tools (e.g. gitk) get confused that the # ddl file is modified, when it clearly isn't system('git status --porcelain >' . File::Spec->devnull); @@ -21,6 +32,8 @@ clonedir_generate_files : dbic_clonedir_regen_test_ddl dbic_clonedir_regen_test_ddl : \t\$(ABSPERLRUN) @test_ddl_cmd --ddl-out @{[ $mm_proto->quote_literal($test_ddl_fn) ]} +\t\$(ABSPERLRUN) @example_ddl_cmd --ddl-out @{[ $mm_proto->quote_literal($example_ddl_fn) ]} --deploy-to @{[ $mm_proto->quote_literal($example_db_fn) ]} +\t\$(ABSPERLRUN) @example_pop_cmd EOP # keep the Makefile.PL eval happy diff --git a/maint/gen_sqlite_schema_files b/maint/gen_sqlite_schema_files index 9fa6a4c..03db999 100755 --- a/maint/gen_sqlite_schema_files +++ b/maint/gen_sqlite_schema_files @@ -14,6 +14,7 @@ my $args = {}; $getopt->getoptions($args, qw/ ddl-out=s@ schema-class=s@ + deploy-to=s@ /); die "You need to specify one DDL output filename via --ddl-out\n" @@ -22,8 +23,19 @@ die "You need to specify one DDL output filename via --ddl-out\n" die "You need to specify one DBIC schema class via --schema-class\n" if @{$args->{'schema-class'}||[]} != 1; +die "You may not specify more than one deploy path via --deploy-to\n" + if @{$args->{'deploy-to'}||[]} > 1; -my $schema = use_module( $args->{'schema-class'}[0] )->connect(); +my $schema = use_module( $args->{'schema-class'}[0] )->connect( + $args->{'deploy-to'} + ? ( "DBI:SQLite:$args->{'deploy-to'}[0]", undef, undef, { on_connect_do => "PRAGMA synchronous = OFF" } ) + : () +); + +if ($args->{'deploy-to'}) { + file($args->{'deploy-to'}[0])->dir->mkpath; + $schema->deploy({ add_drop_table => 1 }); +} my $ddl_fh; if ($args->{'ddl-out'}[0] eq '-') {