File: mkdbic

package info (click to toggle)
pinto 0.14000-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,900 kB
  • sloc: perl: 12,566; sh: 255; makefile: 7
file content (54 lines) | stat: -rwxr-xr-x 1,760 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env perl

# To generate the schema classes, run this command from the root directory 
# of the distribution.  You must install DBIx::Class::Schema::Loader first.

use FindBin qw($Bin);
use Path::Class qw(file);
use File::Path qw(mkpath);

my $distdir = file($Bin)->parent;
my $libdir  = $distdir->subdir('lib');
push @INC, $libdir->stringify;

#-----------------------------------------------------------------------------

# Copyright 2013 Jeffrey Ryan Thalhammer <jeff@stratopan.com>

#-----------------------------------------------------------------------------
# Read DDL from inside the Database class

require Pinto::Database;
my $ddl = Pinto::Database->ddl;

#-----------------------------------------------------------------------------
# Create a temp directory to stash the database

my $tmpdir = $distdir->subdir('tmp');
mkpath $tmpdir->stringify if not -e $tmpdir;

#-----------------------------------------------------------------------------
# Create database, feeding in the DDL

my $dbfile = $tmpdir->file('pinto.db');
unlink $dbfile or die $!;

open my $fh, '|-', "sqlite3 $dbfile" or die $!;
print $fh $ddl;

#-----------------------------------------------------------------------------
# Run the schema generator

system <<"END_COMMAND"; 
dbicdump -Ilib                                            \\
    -o skip_load_external=1                               \\
    -o dump_directory=lib                                 \\
    -o 'use_moose=1'                                      \\
    -o 'result_roles=[ qw(Pinto::Role::Schema::Result) ]' \\
    Pinto::Schema                                         \\
    dbi:SQLite:$dbfile
END_COMMAND

#-----------------------------------------------------------------------------

exit;