TaskPipe/Tool/Command_GenerateSchema.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 53 CC 1 SCAR 6.9
CC
1
Cov
0%
execute
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package TaskPipe::Tool::Command_GenerateSchema;
2  
3 use Moose;
4 use TaskPipe::SchemaManager;
5 use TaskPipe::JobManager;
6 use TaskPipe::Tool::Options;
7 use DateTime;
8 extends 'TaskPipe::Tool::Command';
9 with 'MooseX::ConfigCascade';
10 with 'TaskPipe::Role::MooseType_ScopeMode';
11  
12 has schema_manager => (is => 'rw', isa => 'TaskPipe::SchemaManager', lazy => 1, default => sub{
13 my $sm = TaskPipe::SchemaManager->new;
14 return $sm;
15 });
16
17  
18  
19 has option_specs => (is => 'ro', isa => 'ArrayRef', lazy => 1, default => sub{
20 my $settings = ref( $_[0]->schema_manager->settings );
21 my %items;
22  
23 if ( $_[0]->scope eq 'project' ){
24 $items{global} = [
25 'project_root',
26 'project'
27 ];
28 $items{project} = [
29 'lib_dir',
30 ]
31 } else {
32 $items{global} = [
33 'global_root',
34 'global_lib_dir'
35 ]
36 }
37  
38 my $specs = [{
39 module => __PACKAGE__,
40 is_config => 0
41 }, {
42 module => $settings,
43 items => [
44 'method',
45 'type',
46 'name',
47 'host',
48 'username',
49 'password',
50 'module'
51 ],
52 is_config => 1
53 }, {
54 module => 'TaskPipe::PathSettings::Global',
55 items => $items{global},
56 is_config => 1
57 }];
58  
59 if ( $items{project} ){
60 push @$specs, {
61 module => 'TaskPipe::PathSettings::Project',
62 items => $items{project},
63 is_config => 1
64 }
65 }
66  
67 return $specs;
68 });
69  
70  
71  
72  
73 sub execute{
74 my $self = shift;
75  
76 $self->run_info->scope( $self->scope );
77 $self->schema_manager->gen_schema;
78  
79 }
80  
81  
82  
83 =pod
84  
85 =head1 NAME
86  
87 TaskPipe::Tool::Command_GenerateSchema - command to generate taskpipe schema files
88  
89 =head1 PURPOSE
90  
91 generate the schema files needed by taskpipe to interact with the database
92  
93 =head1 DESCRIPTION
94  
95 TaskPipe uses the L<DBIx::Class> ORM to interface with your database(s). TaskPipe uses one general purpose I<global> database and one I<project> database for each project. See the help for C<deploy tables> for more information on the organisation of database tables.
96  
97 =head2 Global Schema Files
98  
99 After running C<setup> you will need to run C<generate schema> to create the schema files needed for your global database. You need to have already successfully deployed global tables (see C<deploy tables>). Then run
100  
101 taskpipe generate schema --scope=global
102  
103 =head2 Project Schema Files
104  
105 Each time you make changes to your project database, you need to run C<generate schema> over your project database before you can run your plan again.
106  
107 Schema files are generated for
108  
109 =over
110  
111 =item *
112  
113 the tables in your project which taskpipe autogenerated, and which taskpipe uses for caching (these are the C<cache> tables
114  
115 =item *
116  
117 the tables you created manually as part of your project (these are your C<plan> tables).
118  
119 =back
120  
121 To run C<generate schema> over your project database, make sure your tables are deployed (see C<deploy tables>). Then run
122  
123 taskpipe generate schema --project=myproject
124  
125 If you set a default project in your global config file, and you want to run C<generate schema> over the default project then you can just type
126  
127 taskpipe generate schema
128  
129 =head1 OPTIONS
130  
131 =over
132  
133 =item scope
134  
135 Specify C<project> to generate the schema over the tables in your project (both cache and plan tables) - or C<global> to generate the global schema
136  
137 =back
138  
139 =cut
140  
141 has scope => (is => 'rw', isa => 'ScopeMode', default => 'project');
142  
143 =head1 AUTHOR
144  
145 Tom Gracey <tomgracey@gmail.com>
146  
147 =head1 COPYRIGHT AND LICENSE
148  
149 Copyright (c) Tom Gracey 2018
150  
151 TaskPipe is free software, licensed under
152  
153 The GNU Public License Version 3
154  
155 =cut
156  
157 __PACKAGE__->meta->make_immutable;
158 1;