[Catalyst-commits] r9349 - trunk/Catalyst-Example-InstantCRUD/script
zby at dev.catalyst.perl.org
zby at dev.catalyst.perl.org
Thu Feb 19 16:52:51 GMT 2009
Author: zby
Date: 2009-02-19 16:52:51 +0000 (Thu, 19 Feb 2009)
New Revision: 9349
Modified:
trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl
Log:
create_example_db
Modified: trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl
===================================================================
--- trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl 2009-02-19 07:18:54 UTC (rev 9348)
+++ trunk/Catalyst-Example-InstantCRUD/script/instantcrud.pl 2009-02-19 16:52:51 UTC (rev 9349)
@@ -14,7 +14,10 @@
use DBIx::Class::Schema::Loader qw/ make_schema_at /;
use DBIx::Class::Schema::Loader::RelBuilder;
use List::Util qw(first);
+use DBI;
+use File::Temp;
+
my $help = 0;
my $adv_help = 0;
my $nonew = 0;
@@ -32,6 +35,10 @@
my %auth;
my %authz;
+
+#print create_example_db(), "\n";
+#exit;
+
GetOptions(
'help|?' => \$help,
'advanced_help' => \$adv_help,
@@ -182,11 +189,27 @@
return \%m2m, \%bridges;
}
+sub create_example_db {
+ my $tmp = File::Temp->new( UNLINK => 0, SUFFIX => '.db' );
+ my $dsn ||= 'dbi:SQLite:dbname=' . $tmp->filename;
+ my $dbh = DBI->connect( $dsn ) or die "Cannot connect to $dsn\n";
+ my $sql;
+ {
+ local $/;
+ $sql = <DATA>;
+ }
+
+ for my $statement ( split /^\s*$/m, $sql ){
+ warn "executing: \n$statement";
+ $dbh->do($statement) or die $dbh->errstr;
+ }
+ return $tmp->filename;
+}
+
+
1;
-__END__
-
=head1 NAME
instantcrud.pl - Bootstrap a Catalyst application example
@@ -332,10 +355,13 @@
=head1 AUTHOR
-Sebastian Riedel, C<sri at oook.de>,
-Andrew Ford, C<A.Ford at ford-mason.co.uk>
Zbigniew Lukasiak, C<zz bb yy at gmail.com>
Jonas Alves, C<jonas.alves at gmail.com>
+
+Based on catalyst.pl by:
+
+Andrew Ford, C<A.Ford at ford-mason.co.uk>
+Sebastian Riedel, C<sri at oook.de>,
Jonathan Manning
=head1 COPYRIGHT
@@ -346,4 +372,45 @@
the same terms as Perl itself.
=cut
-
+
+__DATA__
+CREATE TABLE dvd (
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ name VARCHAR(255) DEFAULT NULL,
+ imdb_id INTEGER DEFAULT NULL,
+ owner INTEGER NOT NULL REFERENCES user (id),
+ current_owner INTEGER DEFAULT NULL REFERENCES user (id),
+ creation_date date DEFAULT NULL,
+ alter_date datetime DEFAULT NULL,
+ hour time DEFAULT NULL
+);
+
+CREATE TABLE dvdtag (
+ dvd INTEGER NOT NULL DEFAULT '0' REFERENCES dvd (id),
+ tag INTEGER NOT NULL DEFAULT '0' REFERENCES tag (id),
+ PRIMARY KEY (dvd,tag)
+);
+
+CREATE TABLE role (
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ role VARCHAR(255)
+);
+
+CREATE TABLE tag (
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ name VARCHAR(255) DEFAULT NULL
+);
+
+CREATE TABLE user (
+ id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
+ username VARCHAR(255) DEFAULT NULL,
+ password VARCHAR(255) DEFAULT NULL,
+ name VARCHAR(255) DEFAULT NULL
+);
+
+CREATE TABLE user_role (
+ user INTEGER NOT NULL DEFAULT '0' REFERENCES user (id),
+ role INTEGER NOT NULL DEFAULT '0' REFERENCES role (id),
+ PRIMARY KEY (user, role)
+);
+
More information about the Catalyst-commits
mailing list