blib/lib/DBIx/DBFlow.pm untested

filter: Statementstmt 0.0% 0 / 1 totaltotal 0.0% 0 / 1 SCAR -
1 package DBIx::DBFlow;
2 our $VERSION = '0.03';
3  
4 # This package is just a placeholder for the version
5  
6 ### main pod documentation begin ###
7  
8 =encoding UTF-8
9  
10 =head1 NAME
11  
12 DBIx::DBFlow - Database development helpers
13  
14 =head1 SYNOPSIS
15  
16 in your cpanfile add the following
17  
18 requires 'DBIx::DBFlow::Runtime';
19  
20 on develop => sub {
21 requires 'DBIx::DBFlow';
22 }
23  
24 =head1 USAGE
25  
26 =head2 Using the DBFlow on a new project:
27  
28 Create the database in MySQL (tables, fks, etc)
29  
30 dbflow_refresh_model --schema MySchema --dbh "DBD:mysql..."
31  
32 This will create lib/MySchema.pm. Add this code to it:
33  
34 our $VERSION = 1;
35
36 sub admin_connection {
37 my $schema = __PACKAGE__->connect(
38 "DBI:mysql:mysql_read_default_file=pathtoadmincreds.cnf;mysql_read_default_group=schema_group",
39 undef,
40 undef,
41 {
42 AutoCommit => 1,
43 RaiseError => 1,
44 mysql_enable_utf8 => 1,
45 quote_char => '`',
46 name_sep => '.',
47 },
48 );
49 }
50  
51 Now install the DBFlow with
52  
53 dbflow_create --schema MySchema
54  
55 Creates a "database" directory with the deploy info for the database. Creates a handler table in your schema
56  
57 =head2 Using the DBFlow
58  
59 Before modifying the database, bump up it's version (you're about to produce what will be the next version
60 of the database, so we have to signal that)
61  
62 Modify the database with your favorite tool (HeidiSQL, mysql CLI, etc). Add columns, indexes, etc.
63  
64 dbflow_refresh_model --schema MySchema
65  
66 This will regenerate lib/MySchema
67  
68 You can still tweak the database more times (add more columns, change types, etc). You have to execute
69 C<dbflow_refresh_model> each time, in order to refresh the DBIx::Class model
70  
71 When you're happy with your changes, and want to produce an upgrade:
72  
73 dbflow_make_upgrade_scripts --schema MySchema
74  
75 This creates a C<database/MySQL/upgrade/X-Y/___.sql> file that contains the SQL instructions to migrate
76 from version X to version Y.
77  
78 You can create your own (new) SQL files in the same directory that will be executed on upgrade, for operations
79 that cannot be automatically derived (suppose you have to UPDATE some values on a table), although it's better
80 to create Perl files that do the updating with the model (so you don't have to implement complex logic in SQL).
81  
82 Create a C<database/_common/upgrade/X-Y/01-upgrade_step.pl> file (where Y corresponds the version you are producing,
83 and X to the previous one). Put this code in it:
84  
85 sub {
86 my $model = shift;
87
88 my $things = $model->resultset('Things')->search({ ... });
89 }
90  
91 Do whatever perlish things you want in the update script, and please use the model to do it.
92  
93 you can test the updating all the times you want with C<make obliviatedb> and C<dbflow_upgrade_schema --schema MySchema>
94 until you are sure that the update will work in production.
95  
96 =head2 Updating the production database
97  
98 dbflow_upgrade_schema --schema MySchema
99  
100 In production all you have to do is execute C<dbflow_upgrade_schema>.
101  
102 =head1 Interesting utilities
103  
104 =head2 Visualizing your schema
105  
106 You can visualize your schema with
107  
108 dbflow_schema_diagram --schema MySchema
109  
110 It will generate a PNG image called MySchema_schema.png
111  
112 You can control the dimensions of the image with C<--height> and C<--width> parameters.
113  
114 You can also specify the name of the file to write to with C<--file>.
115  
116 =head1 FAQ
117  
118 =head2 MySchema.pm cannot be found
119  
120 The 'lib' directory in the current directory is automatically included (your schema should be there).
121 You can use the C<-I> option to specify an alternate, or try executing with a PERL5LIB that points to the
122 appropiate directory with your schema.
123  
124 =head2 I have more than one schema to manage in my project
125  
126 All utils let you specify the schema name you're acting upon with C<--schema> and the directory
127 to create the upgrade/deploy scripts C<--dir>
128  
129 =head1 CONTRIBUTE
130  
131 The source code and issues are on https://github.com/pplu/dbix-dbflow
132  
133 =head1 AUTHOR
134 Jose Luis Martinez
135 CPAN ID: JLMARTIN
136 pplusdomain@gmail.com
137  
138 =head1 COPYRIGHT and LICENSE
139  
140 Copyright (c) 2016 by Jose Luis Martinez Torres
141  
142 This code is distributed under the Apache 2 License. The full text of the
143 license can be found in the LICENSE file included with this module.
144  
145 =cut
146  
147 1;