1SQL::Translator::Diff(3U)ser Contributed Perl DocumentatiSoQnL::Translator::Diff(3)
2
3
4
6 SQL::Translator::Diff
7
9 Takes two input SQL::Translator::Schemas (or SQL files) and produces
10 ALTER statments to make them the same
11
13 Simplest usage:
14
15 use SQL::Translator::Diff;
16 my $sql = SQL::Translator::Diff::schema_diff($source_schema, 'MySQL', $target_schema, 'MySQL', $options_hash)
17
18 OO usage:
19
20 use SQL::Translator::Diff;
21 my $diff = SQL::Translator::Diff->new({
22 output_db => 'MySQL',
23 source_schema => $source_schema,
24 target_schema => $target_schema,
25 %$options_hash,
26 })->compute_differences->produce_diff_sql;
27
29 ignore_index_names
30 Match indexes based on types and fields, ignoring name.
31
32 ignore_constraint_names
33 Match constrains based on types, fields and tables, ignoring name.
34
35 output_db
36 Which producer to use to produce the output.
37
38 case_insensitive
39 Ignore case of table, field, index and constraint names when
40 comparing
41
42 no_batch_alters
43 Produce each alter as a distinct "ALTER TABLE" statement even if
44 the producer supports the ability to do all alters for a table as
45 one statement.
46
47 ignore_missing_methods
48 If the diff would need a method that is missing from the producer,
49 just emit a comment showing the method is missing, rather than
50 dieing with an error
51
53 The following producer functions should be implemented for
54 completeness. If any of them are needed for a given diff, but not
55 found, an error will be thrown.
56
57 · "alter_create_constraint($con)"
58
59 · "alter_drop_constraint($con)"
60
61 · "alter_create_index($idx)"
62
63 · "alter_drop_index($idx)"
64
65 · "add_field($fld)"
66
67 · "alter_field($old_fld, $new_fld)"
68
69 · "rename_field($old_fld, $new_fld)"
70
71 · "drop_field($fld)"
72
73 · "alter_table($table)"
74
75 · "drop_table($table)"
76
77 · "rename_table($old_table, $new_table)" (optional)
78
79 · "batch_alter_table($table, $hash)" (optional)
80
81 If the producer supports "batch_alter_table", it will be called
82 with the table to alter and a hash, the keys of which will be the
83 method names listed above; values will be arrays of fields or
84 constraints to operate on. In the case of the field functions that
85 take two arguments this will appear as a hash.
86
87 I.e. the hash might look something like the following:
88
89 {
90 alter_create_constraint => [ $constraint1, $constraint2 ],
91 add_field => [ $field ],
92 alter_field => [ [$old_field, $new_field] ]
93 }
94
95 · "preprocess_schema($class, $schema)" (optional)
96
97 "preprocess_schema" is called by the Diff code to allow the
98 producer to normalize any data it needs to first. For example, the
99 MySQL producer uses this method to ensure that FK contraint names
100 are unique.
101
102 Basicaly any changes that need to be made to produce the SQL file
103 for the schema should be done here, so that a diff between a parsed
104 SQL file and (say) a parsed DBIx::Class::Schema object will be
105 sane.
106
107 (As an aside, DBIx::Class, for instance, uses the presence of a
108 "preprocess_schema" function on the producer to know that it can
109 diff between the previous SQL file and its own internal
110 representation. Without this method on th producer it will diff the
111 two SQL files which is slower, but known to work better on old-
112 style producers.)
113
115 Original Author(s) unknown.
116
117 Refactor/re-write and more comprehensive tests by Ash Berlin
118 "ash@cpan.org".
119
120 Redevelopment sponsored by Takkle Inc.
121
122
123
124perl v5.12.0 2010-02-14 SQL::Translator::Diff(3)