TaskPipe/Tool/Command_DeployTables.pm untested

filter: Statementstmt 0.0% 0 / 26 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 33 CC 2 SCAR 12.8
CC
2
Cov
0%
execute
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.6
1 package TaskPipe::Tool::Command_DeployTables;
2  
3 use Moose;
4 #use Moose::Util::TypeConstraints;
5 #use TryCatch;
6 use Module::Runtime 'require_module';
7 use TaskPipe::Sample;
8 extends 'TaskPipe::Tool::Command';
9 with 'MooseX::ConfigCascade';
10 #with 'TaskPipe::Role::MooseType_ScopeMode';
11  
12 has option_specs => (is => 'ro', isa => 'ArrayRef', lazy => 1, default => sub{[{
13 module => 'TaskPipe::PathSettings::Global',
14 is_config => 1
15 }, {
16 module => __PACKAGE__,
17 is_config => 0
18 },
19 {
20 module => 'TaskPipe::SchemaManager::Settings_'.ucfirst($_[0]->scope),
21 is_config => 1
22 }
23 ]});
24  
25  
26  
27 sub execute{
28 my ($self) = @_;
29  
30 $self->run_info->scope( $self->scope );
31  
32 if ( $self->scope eq 'global' ){
33  
34 my $sample = TaskPipe::Sample->new( scope => 'global' );
35 $sample->deploy_tables_from_schema_template( 'Global' );
36
37 } else {
38  
39 my $module = 'TaskPipe::Sample_'.ucfirst($self->sample);
40 require_module( $module );
41  
42 my $sample = $module->new;
43 $sample->deploy_tables;
44  
45 }
46 }
47  
48  
49  
50  
51 =head1 NAME
52  
53 TaskPipe::Tool::Command_DeployTables - command to deploy taskpipe tables
54  
55 =head1 PURPOSE
56  
57 Deploy the database tables which are needed by taskpipe to operate - ie taskpipe C<global> tables or C<cache> tables for an individual project.
58  
59 =head1 DESCRIPTION
60  
61 If you are installing taskpipe from scratch, then you need to deploy B<global> tables, which have shared usage between taskpipe processes. Ideally you should deploy these tables to a specific designated database, which B<only> contains these global taskpipe tables. (Perhaps call this database C<taskpipe> or C<taskpipe_global> etc.) It B<is> possible to have taskpipe global tables sit alongside other tables in the same database, but not recommended (use the C<table_prefix> option to differentiate taskpipe related tables).
62  
63 Running a taskpipe plan always involves using two databases - the global database (as above) and a database specfic to your project (the I<project database>). Your project database will contain 2 groups of tables, I<cache> and I<plan> tables. The I<plan> tables are tables specific to your project - so taskpipe cannot create these for you (sorry!). So deploying C<project> tables really means cache tables will be deployed to your designated project database.
64  
65 =head2 Global Database
66  
67 TaskPipe uses a global database to manage jobs, threads and other information. You should run C<deploy tables> once with C<--scope=global> after running C<setup>, to deploy global tables.
68  
69 Make sure you have
70  
71 =over
72  
73 =item *
74  
75 Created the database where the tables will be deployed. In MySQL:
76  
77 CREATE DATABASE taskpipe_global;
78  
79 =item *
80  
81 Created a user and password for taskpipe to use to access your database, and given correct access permissions for taskpipe to interface with your database.
82  
83 In MySQL:
84  
85 CREATE USER 'taskpipe_user'@'localhost' IDENTIFIED BY 'somecomplexpassword';
86 GRANT ALL PRIVILEGES ON taskpipe_global.* TO 'taskpipe_user'@'localhost';
87  
88 =item *
89  
90 Filled in the information about your database (database name, host, username, password) in the global configuration file (usually C<global.yml>, found inside C</global/conf> in your taskpipe directory). If you setup taskpipe in C</taskpipe> in your home directory, then you can modify this with a text editor. E.g. using C<nano>:
91  
92 nano ~/taskpipe/global/conf/global.yml
93  
94 Look for the C<TaskPipe::SchemaManager::Settings_Global> section and change the values to suit your setup:
95  
96 ...
97
98 TaskPipe::SchemaManager::Settings_Global:
99 host: localhost
100 method: dbi
101 module: TaskPipe::GlobalSchema
102 name: taskpipe
103 password: somecomplexpassword
104 table_prefix: ''
105 type: mysql
106 username: taskpipe_user
107  
108 ...
109  
110 Note that C<module> is the module taskpipe will use as a template for your tables. It is not recommended you change this.
111  
112 =back
113  
114 C<deploy tables> will deploy all tables with names that start with whatever you specify in C<table_prefix>. It is recommended that you don't use the global database for any other purpose (ie you simply set it up and then leave it alone). In this case, the table prefix is not important, and you can leave it as an empty string (as above).
115  
116 Once you have saved the global config file with the new settings, run <deploy tables>
117  
118 taskpipe deploy tables --scope=global
119  
120 You should then generate the schema files taskpipe will use to interface with the new tables
121  
122 taskpipe generate schema --scope=global
123  
124 See the help for C<generate schema> for more information. For more information on C<setup> run:
125  
126 taskpipe help setup
127  
128 =head2 Project Database
129  
130 C<deploy tables> needs to be run each time you create a new project. First deploy the files associated with the project
131  
132 taskpipe deploy files --project=newproject
133  
134 Next edit the project config that was created. If you used default directory settings, and you installed taskpipe into C<~/taskpipe> then you should find this file at C<~/taskpipe/projects/newproject/conf/project.yml> (remembering to change newproject to whatever name you called your project).
135  
136 nano ~/taskpipe/projects/newproject/conf/project.yml
137  
138 Find the section C<TaskPipe::SchemaManager::Settings_Project> and edit to suit your setup
139  
140 TaskPipe::SchemaManager::Settings_Project:
141 host: localhost
142 method: dbi
143 module: TaskPipe::Schema
144 name: newproject
145 password: somecomplexpassword
146 table_prefix: tp_
147 type: mysql
148 username: taskpipe_user
149  
150 Remember the table prefix will differentiate C<cache> tables (which C<deploy tables> creates) from C<plan> tables (which you will create yourself as part of your project).
151  
152 Create the database you are going to use for the project. E.g. in MySQL
153  
154 CREATE DATABASE newproject;
155  
156 and make sure your taskpipe user has permissions to the new database. E.g. in MySQL
157  
158 GRANT ALL PRIVILEGES ON newproject.* TO 'taskpipe_user'@'localhost';
159  
160 Then run C<deploy tables>
161  
162 taskpipe deploy tables --project=newproject
163  
164 You should now be ready to start building your project.
165  
166  
167 =head1 OPTIONS
168  
169 =over
170  
171 =item scope
172  
173 Either C<global> or C<project> (deploys cache tables only).
174  
175 =cut
176  
177 has scope => (is => 'ro', isa => 'ScopeMode', default => 'project');
178  
179  
180 =item sample
181  
182 The name of the sample to use to deploy tables. This is only relevant when C<scope> is C<project>. When C<scope> is C<global> this will be ignored.
183  
184 =back
185  
186 =cut
187  
188 has sample => (is => 'ro', isa => 'Str', default => 'stubs');
189  
190 =head1 AUTHOR
191  
192 Tom Gracey <tomgracey@gmail.com>
193  
194 =head1 COPYRIGHT AND LICENSE
195  
196 Copyright (c) Tom Gracey 2018
197  
198 TaskPipe is free software, licensed under
199  
200 The GNU Public License Version 3
201  
202 =cut
203  
204 __PACKAGE__->meta->make_immutable;
205 1;
206  
207