Skip to content
Browse files

Tab/WS crusade

  • Loading branch information...
1 parent bdf6058 commit aee4b66eb2152b7066ced4def46e0223eb1649b1 @ribasushi ribasushi committed Jan 17, 2012
Showing with 1,188 additions and 1,140 deletions.
  1. +1 −0 Changes
  2. +22 −3 Makefile.PL
  3. +21 −21 lib/SQL/Translator/Manual.pod
  4. +101 −101 lib/SQL/Translator/Parser/DB2.pm
  5. +1 −1 lib/SQL/Translator/Parser/SQLServer.pm
  6. +1 −1 lib/SQL/Translator/Producer/Oracle.pm
  7. +8 −8 script/sqlt
  8. +7 −7 script/sqlt-diagram
  9. +22 −22 script/sqlt-diff
  10. +235 −235 script/sqlt-diff-old
  11. +13 −13 script/sqlt-graph
  12. +98 −98 script/sqlt.cgi
  13. +117 −117 t/02mysql-parser.t
  14. +2 −2 t/05bgep-re.t
  15. +8 −8 t/08postgres-to-mysql.t
  16. +2 −2 t/09sqlt-diagram.t
  17. +3 −3 t/10excel.t
  18. +54 −54 t/13schema.t
  19. +1 −1 t/14postgres-parser.t
  20. +58 −60 t/15oracle-parser.t
  21. +1 −1 t/16xml-parser.t
  22. +3 −3 t/17sqlfxml-producer.t
  23. +6 −254 t/18ttschema-producer.t
  24. +1 −1 t/19sybase-parser.t
  25. +1 −1 t/26sybase.t
  26. +2 −2 t/27sqlite-parser.t
  27. +3 −3 t/29html.t
  28. +11 −11 t/30sqlt-diff.t
  29. +11 −11 t/30sqlt-new-diff-mysql.t
  30. +1 −1 t/30sqlt-new-diff-pgsql.t
  31. +4 −4 t/30sqlt-new-diff-sqlite.t
  32. +8 −8 t/30sqlt-new-diff.t
  33. +1 −1 t/31dumper.t
  34. +8 −17 t/33tt-table-producer.t
  35. +2 −2 t/38-filter-names.t
  36. +33 −33 t/38-mysql-producer.t
  37. +1 −1 t/40oracle-parser-dbi.t
  38. +8 −8 t/47postgres-producer.t
  39. +1 −1 t/48xml-to-sqlite.t
  40. +1 −1 t/50-sqlserver-parser.t
  41. +3 −3 t/51-xml-to-oracle.t
  42. +3 −3 t/51-xml-to-oracle_quoted.t
  43. +1 −1 t/61translator_agnostic.t
  44. +7 −7 t/63-spacial-pgsql.t
  45. +1 −1 t/66-postgres-dbi-parser.t
  46. +1 −1 t/data/template/basic.tt
  47. +248 −0 t/data/template/testresult_basic.txt
  48. +10 −0 t/data/template/testresult_table.txt
  49. +3 −3 t/mysql-sqlite-translate.t
  50. +14 −0 xt/eol.t
  51. +15 −0 xt/notabs.t
  52. 0 t/01pod.t → xt/pod.t
View
1 Changes
@@ -20,6 +20,7 @@
* MySQL parser correctly differentiates between signed and unsigned integer column
display sizes
* Replace Class::Accessor::Fast dependency with already-included Moo
+* Entire codebase is now free of tabs and trailing whitespace
# ----------------------------------------------------------
# 0.11010 2011-10-05
View
25 Makefile.PL
@@ -63,8 +63,6 @@ for my $type (qw/requires recommends test_requires/) {
}
}
-tests_recursive ();
-
install_script (qw|
script/sqlt-diagram
script/sqlt-diff
@@ -76,7 +74,28 @@ install_script (qw|
install_share();
-auto_provides();
+tests_recursive ();
+
+
+# temporary(?) until I get around to fix M::I wrt xt/
+# needs Module::Install::AuthorTests
+eval {
+ # this should not be necessary since the autoloader is supposed
+ # to work, but there were reports of it failing
+ require Module::Install::AuthorTests;
+ recursive_author_tests (qw/xt/);
+ 1;
+} || do {
+ if ($Module::Install::AUTHOR) {
+ my $err = $@;
+
+ # better error message in case of missing dep
+ eval { require Module::Install::AuthorTests }
+ || die "\nYou need Module::Install::AuthorTests installed to run this Makefile.PL in author mode:\n\n$@\n";
+
+ die $err;
+ }
+};
auto_install();
View
42 lib/SQL/Translator/Manual.pod
@@ -19,7 +19,7 @@ groupings:
=item * Parsers
-The parsers are responsible for reading the input files and describing
+The parsers are responsible for reading the input files and describing
them to the Schema object middleware.
=item * Producers
@@ -37,7 +37,7 @@ Indices, Constraints, etc.
It's not necessary to understand how to write or manipulate any
of these for most common tasks, but you should aware of the concepts
-as they will be referenced later in this document.
+as they will be referenced later in this document.
=head1 SQLFAIRY SCRIPTS
@@ -51,7 +51,7 @@ do:
=item * sqlt
This is the main interface for text-to-text translations, e.g.,
-converting a MySQL schema to Oracle.
+converting a MySQL schema to Oracle.
=item * sqlt-diagram
@@ -61,7 +61,7 @@ myriad options.
=item * sqlt-diff
This script will examine two schemas and report the SQL commands
-(ALTER, CREATE) needed to turn the first schema into the second.
+(ALTER, CREATE) needed to turn the first schema into the second.
=item * sqlt-dumper
@@ -135,11 +135,11 @@ would be fairly easy to add an XML parser for something like the TorqueDB
(http://db.apache.org/torque/) project. The actual parsing of XML should be
trivial given the number of XML parsers available, so all that would be left
would be to map the specific concepts in the source file to the Schema objects
-in SQLFairy.
+in SQLFairy.
To convert a schema in SQLFairy's XML dialect to Oracle, do the following:
- $ sqlt -f XML-SQLFairy -t Oracle foo.xml > foo-oracle.sql
+ $ sqlt -f XML-SQLFairy -t Oracle foo.xml > foo-oracle.sql
=head1 SERIALIZING SCHEMAS
@@ -157,7 +157,7 @@ This can be accomplished like so:
$ ...
SQLFairy has three serialization producers, none of which is superior
-to the other in their description of a schema.
+to the other in their description of a schema.
=over 4
@@ -213,7 +213,7 @@ the "sqlt-graph" script for more information.
=back
-=head1 AUTOMATED CODE-GENERATION
+=head1 AUTOMATED CODE-GENERATION
Given that so many applications interact with SQL databases, it's no
wonder that people have automated code to deal with this interaction.
@@ -321,14 +321,14 @@ somewhat quirky:
$ sqlt-diff foo-v1.sql=MySQL foo-v2.sql=Oracle > diff.sql
As demonstrated, the schemas need not even be from the same vendor,
-though this is likely to produce some spurious results as
+though this is likely to produce some spurious results as
datatypes are not currently viewed equivalent unless they match
exactly, even if they would be converted to the same. For example,
MySQL's "integer" data type would be converted to Oracle's "number,"
but the differ isn't quite smart enough yet to figure this out. Also,
as the SQL to ALTER a field definition varies from database vendor to
vendor, these statements are made using just the keyword "CHANGE" and
-will likely need to be corrected for the target database.
+will likely need to be corrected for the target database.
=head1 A UNIFIED GRAPHICAL INTERFACE
@@ -355,28 +355,28 @@ Please read the POD for SQL::Translator and SQL::Translator::Schema to
learn the methods you can call. Here is a very simple example:
#!/usr/bin/perl
-
+
use strict;
use SQL::Translator;
-
+
my $input = q[
create table foo (
foo_id int not null default '0' primary key,
foo_name varchar(30) not null default ''
);
-
+
create table bar (
bar_id int not null default '0' primary key,
bar_value varchar(100) not null default ''
);
];
-
+
my $t = SQL::Translator->new;
$t->parser('MySQL') or die $t->error;
$t->producer( \&produce ) or die $t->error;
my $output = $t->translate( \$input ) or die $t->error;
print $output;
-
+
sub produce {
my $tr = shift;
my $schema = $tr->schema;
@@ -389,7 +389,7 @@ learn the methods you can call. Here is a very simple example:
Executing this script produces the following:
- $ ./my-producer.pl
+ $ ./my-producer.pl
Table = foo
Table = bar
@@ -404,25 +404,25 @@ is that you have to decide how to parse the incoming data and then
map the concepts in the data to the Schema object.
#!/usr/bin/perl
-
+
use strict;
use SQL::Translator;
-
+
my $input =
"foo:foo_id int 11:foo_name varchar 30\n" .
"bar:bar_id int 11:bar_value varchar 30"
;
-
+
my $t = SQL::Translator->new;
$t->parser( \&parser ) or die $t->error;
$t->producer('Oracle') or die $t->error;
my $output = $t->translate( \$input ) or die $t->error;
print $output;
-
+
sub parser {
my ( $tr, $data ) = @_;
my $schema = $tr->schema;
-
+
for my $line ( split( /\n/, $data ) ) {
my ( $table_name, @fields ) = split( /:/, $line );
my $table = $schema->add_table( name => $table_name )
View
202 lib/SQL/Translator/Parser/DB2.pm
@@ -33,7 +33,7 @@ startrule : statement(s) eofile {
eofile : /^\Z/
-statement :
+statement :
comment
| create
| <error>
@@ -129,21 +129,21 @@ FULL: /full/i
OUTER: /outer/i
WHERE: /where/i
-
+
trigger_name: SCHEMA '.' NAME
{ $return = { schema => $item[1], name => $item[3] } }
| NAME
- { $return = { name => $item[1] } }
+ { $return = { name => $item[1] } }
table_name: SCHEMA '.' NAME
{ $return = { schema => $item[1], name => $item[3] } }
| NAME
- { $return = { name => $item[1] } }
+ { $return = { name => $item[1] } }
view_name: SCHEMA '.' NAME
{ $return = { schema => $item[1], name => $item[3] } }
| NAME
- { $return = { name => $item[1] } }
+ { $return = { name => $item[1] } }
column_name: NAME
@@ -160,7 +160,7 @@ SCHEMA: /\w{1,128}/
NAME: /\w+/
NAME: /\w{1,18}/
-
+
options: /WITH/i ( /CASCADED/i | /LOCAL/i ) /CHECK\s+OPTION/i
# root_view_definition: /MODE\s+DB2SQL/i '(' oid_column ( /,/ with_options )(?) ')'
@@ -175,21 +175,21 @@ options: /WITH/i ( /CASCADED/i | /LOCAL/i ) /CHECK\s+OPTION/i
common_table_expression: table_name column_list /AS/i get_bracketed
{
- $return = { name => $item{table_name}{name},
+ $return = { name => $item{table_name}{name},
query => $item[4]
};
}
-get_bracketed:
-{
+get_bracketed:
+{
extract_bracketed($text, '(');
}
common_table_expression: table_name column_list /AS/i '(' fullselect ')'
# fullselect: ( subselect | '(' fullselect ')' | values_clause ) ( ( /UNION/i | /UNION/i /ALL/i | /EXCEPT/i | /EXCEPT/i /ALL/i | /INTERSECT/i | /INTERSECT/i /ALL/i ) ( subselect | '(' fullselect ')' | values_clause ) )(s)
-# values_clause: /VALUES/i values_row(s /,/)
+# values_clause: /VALUES/i values_row(s /,/)
# values_row: ( expression | /NULL/i ) | '(' ( expression | /NULL/i )(s /,/) ')'
@@ -201,37 +201,37 @@ common_table_expression: table_name column_list /AS/i '(' fullselect ')'
# from_clause: /FROM/i table_reference(s /,/)
-# table_reference:
-# (
-# ( nickname
-# | table_name
-# | view_name
-# )
+# table_reference:
+# (
+# ( nickname
+# | table_name
+# | view_name
+# )
# | ( /ONLY/i
-# | /OUTER/i
-# ) '('
-# ( table_name
-# | view_name
-# ) ')'
-# ) correlation_clause(?)
-# | TABLE '(' function_name '(' expression(s? /,/) ')' ')' correlation_clause
-# | TABLE(?) '(' fullselect ')' correlation_clause
-# | joined_table
-
+# | /OUTER/i
+# ) '('
+# ( table_name
+# | view_name
+# ) ')'
+# ) correlation_clause(?)
+# | TABLE '(' function_name '(' expression(s? /,/) ')' ')' correlation_clause
+# | TABLE(?) '(' fullselect ')' correlation_clause
+# | joined_table
+
# correlation_clause: /AS/i(?) correlation_name column_list(?)
-# joined_table:
-# table_reference ( INNER
-# | outer
+# joined_table:
+# table_reference ( INNER
+# | outer
# )(?) JOIN table_reference ON join_condition
# | '(' joined_table ')'
-
+
# outer: ( LEFT | RIGHT | FULL ) OUTER(?)
where_clause: WHERE search_condition
-# group_by_clause: /GROUP\s+BY/i ( grouping_expression
+# group_by_clause: /GROUP\s+BY/i ( grouping_expression
# | grouping_sets
# | super_groups
# )(s /,/)
@@ -245,27 +245,27 @@ where_clause: WHERE search_condition
# # Name of one of the selected columns!
# simple_column_name: NAME
-# simple_integer: /\d+/
+# simple_integer: /\d+/
# { $item[1] <= $numberofcolumns && $item[1] > 1 }
# sort_key_expression: expression
# { expression from select columns list, grouping_expression, column function.. }
-# grouping_sets: /GROUPING\s+SETS/i '(' (
-# ( grouping_expression
-# | super_groups
-# )
-# | '(' ( grouping_expression
-# | super_groups
-# )(s /,/) ')'
-# )(s /,/) ')'
+# grouping_sets: /GROUPING\s+SETS/i '(' (
+# ( grouping_expression
+# | super_groups
+# )
+# | '(' ( grouping_expression
+# | super_groups
+# )(s /,/) ')'
+# )(s /,/) ')'
-# super_groups: /ROLLUP/i '(' grouping_expression_list ')'
+# super_groups: /ROLLUP/i '(' grouping_expression_list ')'
# | /CUBE/i '(' grouping_expression_list ')'
# | grand_total
-# grouping_expression_list: ( grouping_expression
-# | '(' grouping_expression(s /,/) ')'
+# grouping_expression_list: ( grouping_expression
+# | '(' grouping_expression(s /,/) ')'
# )(s /,/)
# grand_total: '(' ')'
@@ -283,7 +283,7 @@ before: /NO CASCADE BEFORE/i
after: /AFTER/i
-type: /UPDATE/i /OF/i column_name(s /,/)
+type: /UPDATE/i /OF/i column_name(s /,/)
{ $return = { event => 'update_on',
fields => $item[3] }
}
@@ -294,10 +294,10 @@ type: ( /INSERT/i | /DELETE/i | /UPDATE/i )
reference_b: /REFERENCING/i old_new_corr(0..2)
{ $return = join(' ', $item[1], join(' ', @{$item[2]}) ) }
-reference_a: /REFERENCING/i old_new_corr(0..2) old_new_table(0..2)
+reference_a: /REFERENCING/i old_new_corr(0..2) old_new_table(0..2)
{ $return = join(' ', $item[1], join(' ', @{$item[2]}), join(' ', @{$item[3]}) ) }
-old_new_corr: /OLD/i /(AS)?/i correlation_name
+old_new_corr: /OLD/i /(AS)?/i correlation_name
{ $return = join(' ', @item[1..3] ) }
| /NEW/i /(AS)?/i correlation_name
{ $return = join(' ', @item[1..3] ) }
@@ -310,33 +310,33 @@ old_new_table: /OLD_TABLE/i /(AS)?/i identifier
# Just parsing simple search conditions for now.
search_condition: /[^)]+/
-expression: (
- ( '+'
- | '-'
- )(?)
+expression: (
+ ( '+'
+ | '-'
+ )(?)
( function
| '(' expression ')'
| constant
| column_name
| host_variable
| special_register
- | '(' scalar_fullselect ')'
+ | '(' scalar_fullselect ')'
| labeled_duration
| case_expression
| cast_specification
# | dereference_operation
| OLAP_function
| method_invocation
| subtype_treatment
- | sequence_reference
+ | sequence_reference
)
)(s /operator/)
-operator: ( /CONCAT/i | '||' ) | '/' | '*' | '+' | '-'
+operator: ( /CONCAT/i | '||' ) | '/' | '*' | '+' | '-'
-function: ( /SYSIBM\.|/i sysibm_function
+function: ( /SYSIBM\.|/i sysibm_function
| /SYSFUN\.|/i sysfun_function
- | userdefined_function
+ | userdefined_function
) '(' func_args(s /,/) ')'
constant: int_const | float_const | dec_const | char_const | hex_const | grastr_const
@@ -493,83 +493,83 @@ scalar_fullselect: '(' fullselect ')'
labeled_duration: ld_type ld_duration
-ld_type: function
- | '(' expression ')'
- | constant
- | column_name
+ld_type: function
+ | '(' expression ')'
+ | constant
+ | column_name
| host_variable
-ld_duration: /YEARS?/i
- | /MONTHS?/i
- | /DAYS?/i
- | /HOURS?/i
+ld_duration: /YEARS?/i
+ | /MONTHS?/i
+ | /DAYS?/i
+ | /HOURS?/i
| /MINUTES?/i
| /SECONDS?/i
| /MICROSECONDS?/i
-case_expression: /CASE/i ( searched_when_clause
- | simple_when_clause
- )
- ( /ELSE\s+NULL/i
- | /ELSE/i result_expression
+case_expression: /CASE/i ( searched_when_clause
+ | simple_when_clause
+ )
+ ( /ELSE\s+NULL/i
+ | /ELSE/i result_expression
)(?) /END/i
-searched_when_clause: ( /WHEN/i search_condition /THEN/i
- ( result_expression
+searched_when_clause: ( /WHEN/i search_condition /THEN/i
+ ( result_expression
| /NULL/i
)
)(s)
-simple_when_clause: expression ( /WHEN/i search_condition /THEN/i
- ( result_expression
+simple_when_clause: expression ( /WHEN/i search_condition /THEN/i
+ ( result_expression
| /NULL/i
)
)(s)
-result_expression: expression
+result_expression: expression
-cast_specification: /CAST/i '(' ( expression
+cast_specification: /CAST/i '(' ( expression
| /NULL/i
| parameter_marker
- ) /AS/i data_type
- ( /SCOPE/ ( typed_table_name
+ ) /AS/i data_type
+ ( /SCOPE/ ( typed_table_name
| typed_view_name
)
)(?) ')'
-dereference_operation: scoped_reference_expression '->' name1
+dereference_operation: scoped_reference_expression '->' name1
( '(' expression(s) ')' )(?)
# ( '(' expression(s /,/) ')' )(?)
-scoped_reference_expression: expression
-{ # scoped, reference
+scoped_reference_expression: expression
+{ # scoped, reference
}
name1: NAME
-OLAP_function: ranking_function
+OLAP_function: ranking_function
| numbering_function
| aggregation_function
-ranking_function: ( /RANK/ '()'
- | /DENSE_RANK|DENSERANK/i '()'
+ranking_function: ( /RANK/ '()'
+ | /DENSE_RANK|DENSERANK/i '()'
) /OVER/i '(' window_partition_clause(?) window_order_clause ')'
-numbering_function: /ROW_NUMBER|ROWNUMBER/i '()' /OVER/i '(' window_partition_clause(?)
- ( window_order_clause window_aggregation_group_clause(?)
- )(?)
- ( /RANGE\s+BETWEEN\s+UNBOUNDED\s+PRECEDING\s+AND\s+UNBBOUNDED\s+FOLLOWING/i
+numbering_function: /ROW_NUMBER|ROWNUMBER/i '()' /OVER/i '(' window_partition_clause(?)
+ ( window_order_clause window_aggregation_group_clause(?)
+ )(?)
+ ( /RANGE\s+BETWEEN\s+UNBOUNDED\s+PRECEDING\s+AND\s+UNBBOUNDED\s+FOLLOWING/i
| window_aggregation_group_clause
)(?) ')'
window_partition_clause: /PARTITION\s+BY/i partitioning_expression(s /,/)
-window_order_clause: /ORDER\s+BY/i
- ( sort_key_expression
- ( asc_option
- | desc_option
+window_order_clause: /ORDER\s+BY/i
+ ( sort_key_expression
+ ( asc_option
+ | desc_option
)(?)
)(s /,/)
@@ -579,42 +579,42 @@ desc_option: /DESC/i ( /NULLS\s+FIRST/i | /NULLS\s+LAST/i )(?)
window_aggregation_group_clause: ( /ROWS/i
| /RANGE/i
- )
+ )
( group_start
| group_between
| group_end
)
-group_start: /UNBOUNDED\s+PRECEDING/i
+group_start: /UNBOUNDED\s+PRECEDING/i
| unsigned_constant /PRECEDING/i
| /CURRENT\s+ROW/i
group_between: /BETWEEN/i group_bound1 /AND/i group_bound2
-group_bound1: /UNBOUNDED\s+PRECEDING/i
+group_bound1: /UNBOUNDED\s+PRECEDING/i
| unsigned_constant /PRECEDING/i
| unsigned_constant /FOLLOWING/i
| /CURRENT\s+ROW/i
-group_bound2: /UNBOUNDED\s+PRECEDING/i
+group_bound2: /UNBOUNDED\s+PRECEDING/i
| unsigned_constant /PRECEDING/i
| unsigned_constant /FOLLOWING/i
| /CURRENT\s+ROW/i
-group_end: /UNBOUNDED\s+PRECEDING/i
- | unsigned_constant /FOLLOWING/i
+group_end: /UNBOUNDED\s+PRECEDING/i
+ | unsigned_constant /FOLLOWING/i
method_invocation: subject_expression '..' method_name
- ( '(' expression(s) ')'
-# ( '(' expression(s /,/) ')'
+ ( '(' expression(s) ')'
+# ( '(' expression(s /,/) ')'
)(?)
subject_expression: expression
-{ # with static result type that is a used-defined struct type
+{ # with static result type that is a used-defined struct type
}
method_name: NAME
-{ # must be a method of subject_expression
+{ # must be a method of subject_expression
}
subtype_treatment: /TREAT/i '(' expression /AS/i data_type ')'
@@ -633,7 +633,7 @@ search_condition: /NOT|/i ( predicate ( /SELECTIVITY/i numeric_constant )(?) | '
cond: ( /AND/i | /OR/i ) /NOT|/i ( predicate ( /SELECTIVITY/i numeric_constant )(?) | '(' search_condition ')' )
-predicate: basic_p | quantified_p | between_p | exists_p | in_p | like_p | null_p | type_p
+predicate: basic_p | quantified_p | between_p | exists_p | in_p | like_p | null_p | type_p
basic_p: expression /(=|<>|<|>|<=|=>|\^=|\^<|\^>|\!=)/ expression
View
2 lib/SQL/Translator/Parser/SQLServer.pm
@@ -175,7 +175,7 @@ create_table : /create/i /table/i ident '(' create_def(s /,/) ')' lock(?) on_sys
disable_constraints : if_exists(?) /alter/i /table/i ident /nocheck/i /constraint/i /all/i END_STATEMENT
-# this is for the normal case
+# this is for the normal case
create_constraint : /create/i constraint END_STATEMENT
{
@table_comments = ();
View
2 lib/SQL/Translator/Producer/Oracle.pm
@@ -709,7 +709,7 @@ sub create_field {
"CREATE OR REPLACE TRIGGER $trig_name\n".
"BEFORE INSERT OR UPDATE ON $table_name_q\n".
"FOR EACH ROW WHEN (new.$field_name_q IS NULL)\n".
- "BEGIN \n".
+ "BEGIN\n".
" SELECT sysdate INTO :new.$field_name_q FROM dual;\n".
"END;\n";
View
16 script/sqlt
@@ -51,7 +51,7 @@ To translate a schema:
General Parser Options:
--skip Comma-separated list of tables to skip (only implemented in some parsers)
- --ignore_opts Comma-separated list of table options to ignore
+ --ignore_opts Comma-separated list of table options to ignore
DBI Parser Options:
@@ -247,12 +247,12 @@ GetOptions(
) or pod2usage(2);
if ($use_same_auth) {
- $producer_dsn = $dsn;
- $producer_db_user = $db_user;
- $producer_db_password = $db_password;
+ $producer_dsn = $dsn;
+ $producer_db_user = $db_user;
+ $producer_db_password = $db_password;
}
-if (
+if (
( !defined $from && defined $dsn )
||
$from =~ /^DBI.*/
@@ -277,7 +277,7 @@ if ( $show_version ) {
exit(0);
}
-my $translator = SQL::Translator->new(
+my $translator = SQL::Translator->new(
debug => $debug || 0,
trace => $trace || 0,
no_comments => $no_comments || 0,
@@ -318,7 +318,7 @@ my $translator = SQL::Translator->new(
newlines => $newlines,
postgres_version => $postgres_version,
mysql_version => $mysql_version,
- package_name => $package_name,
+ package_name => $package_name,
},
);
@@ -345,7 +345,7 @@ $translator->parser($from);
$translator->producer($to);
for my $file (@files) {
- my @args =
+ my @args =
($file eq '-') ? (data => \*STDIN) :
($file eq '!') ? (data => '') :
(file => $file);
View
14 script/sqlt-diagram
@@ -18,7 +18,7 @@
# 02111-1307 USA
# -------------------------------------------------------------------
-=head1 NAME
+=head1 NAME
sqlt-diagram - Automatically create a diagram from a database schema
@@ -37,13 +37,13 @@ sqlt-diagram - Automatically create a diagram from a database schema
default "medium")
--gutter Gutter size between tables
--color Add colors
- --show-fk-only Only show fields that act as primary
+ --show-fk-only Only show fields that act as primary
or foreign keys
--natural-join Perform natural joins
--natural-join-pk Perform natural joins from primary keys only
-s|--skip Fields to skip in natural joins
- --skip-tables Comma-separated list of table names to exclude
+ --skip-tables Comma-separated list of table names to exclude
--skip-tables-like Comma-separated list of regexen to exclude tables
--debug Print debugging information
@@ -82,10 +82,10 @@ $VERSION = '1.59';
#
# Get arguments.
#
-my (
- $out_file, $image_type, $db_driver, $title, $num_columns,
+my (
+ $out_file, $image_type, $db_driver, $title, $num_columns,
$no_lines, $font_size, $add_color, $debug, $show_fk_only,
- $gutter, $natural_join, $join_pk_only, $skip_fields,
+ $gutter, $natural_join, $join_pk_only, $skip_fields,
$skip_tables, $skip_tables_like, $help
);
@@ -114,7 +114,7 @@ pod2usage(1) if $help;
pod2usage( -message => "No db driver specified" ) unless $db_driver;
pod2usage( -message => 'No input file' ) unless @files;
-my $translator = SQL::Translator->new(
+my $translator = SQL::Translator->new(
from => $db_driver,
to => 'Diagram',
debug => $debug || 0,
View
44 script/sqlt-diff
@@ -57,8 +57,8 @@ Options:
=head1 DESCRIPTION
sqlt-diff is a utility for creating a file of SQL commands necessary to
-transform the first schema provided to the second. While not yet
-exhaustive in its ability to mutate the entire schema, it will report the
+transform the first schema provided to the second. While not yet
+exhaustive in its ability to mutate the entire schema, it will report the
following
=over
@@ -71,24 +71,24 @@ indices).
=item * Missing/altered fields
-Any fields missing or altered between the two schemas will be reported
+Any fields missing or altered between the two schemas will be reported
as:
- ALTER TABLE <table_name>
- [DROP <field_name>]
+ ALTER TABLE <table_name>
+ [DROP <field_name>]
[CHANGE <field_name> <datatype> (<size>)] ;
=item * Missing/altered indices
Any indices missing or of a different type or on different fields will be
indicated. Indices that should be dropped will be reported as such:
-
+
DROP INDEX <index_name> ON <table_name> ;
-An index of a different type or on different fields will be reported as a
+An index of a different type or on different fields will be reported as a
new index as such:
- CREATE [<index_type>] INDEX [<index_name>] ON <table_name>
+ CREATE [<index_type>] INDEX [<index_name>] ON <table_name>
( <field_name>[,<field_name>] ) ;
=back
@@ -113,9 +113,9 @@ use SQL::Translator::Schema::Constants;
use vars qw( $VERSION );
$VERSION = '1.59';
-my ( @input, $list, $help, $debug, $trace, $caseopt, $ignore_index_names,
- $ignore_constraint_names, $output_db, $mysql_parser_version,
- $ignore_view_sql, $ignore_proc_sql, $no_batch_alters );
+my ( @input, $list, $help, $debug, $trace, $caseopt, $ignore_index_names,
+ $ignore_constraint_names, $output_db, $mysql_parser_version,
+ $ignore_view_sql, $ignore_proc_sql, $no_batch_alters );
for my $arg ( @ARGV ) {
if ( $arg =~ m/^-?-l(ist)?$/ ) {
$list = 1;
@@ -124,31 +124,31 @@ for my $arg ( @ARGV ) {
$help = 1;
}
elsif ( $arg =~ m/^-?-d(ebug)?$/ ) {
- $debug = 1;
+ $debug = 1;
}
elsif ( $arg =~ m/^-?-t(race)?$/ ) {
- $trace = 1;
+ $trace = 1;
}
elsif ( $arg =~ m/^-?-c(ase-insensitive)?$/ ) {
- $caseopt = 1;
+ $caseopt = 1;
}
elsif ( $arg =~ m/^--ignore-index-names$/ ) {
- $ignore_index_names = 1;
+ $ignore_index_names = 1;
}
elsif ( $arg =~ m/^--ignore-constraint-names$/ ) {
- $ignore_constraint_names = 1;
+ $ignore_constraint_names = 1;
}
elsif ( $arg =~ m/^--mysql-parser-version=(.+)$/ ) {
- $mysql_parser_version = $1;
+ $mysql_parser_version = $1;
}
elsif ( $arg =~ m/^--output-db=(.+)$/ ) {
- $output_db = $1;
+ $output_db = $1;
}
elsif ( $arg =~ m/^--ignore-view-sql$/ ) {
- $ignore_view_sql = 1;
+ $ignore_view_sql = 1;
}
elsif ( $arg =~ m/^--ignore-proc-sql$/ ) {
- $ignore_proc_sql = 1;
+ $ignore_proc_sql = 1;
}
elsif ( $arg =~ m/^([^=]+)=(.+)$/ ) {
push @input, { file => $1, parser => $2 };
@@ -162,7 +162,7 @@ for my $arg ( @ARGV ) {
}
print STDERR <<'EOM';
-This code is experimental, currently the new code only supports MySQL or
+This code is experimental, currently the new code only supports MySQL or
SQLite diffing. To add support for other databases, please patch the relevant
SQL::Translator::Producer:: module. If you need compatibility with the old
sqlt-diff, please use sqlt-diff-old, and look into helping us make this one
@@ -204,7 +204,7 @@ my ( $source_schema, $source_db, $target_schema, $target_db ) = map {
($schema, $parser);
} @input;
-my $result = SQL::Translator::Diff::schema_diff($source_schema, $source_db,
+my $result = SQL::Translator::Diff::schema_diff($source_schema, $source_db,
$target_schema, $target_db,
{ caseopt => $caseopt,
ignore_index_names => $ignore_index_names,
View
470 script/sqlt-diff-old
@@ -44,8 +44,8 @@ Options:
=head1 DESCRIPTION
sqlt-diff is a utility for creating a file of SQL commands necessary to
-transform the first schema provided to the second. While not yet
-exhaustive in its ability to mutate the entire schema, it will report the
+transform the first schema provided to the second. While not yet
+exhaustive in its ability to mutate the entire schema, it will report the
following
=over
@@ -58,24 +58,24 @@ indices).
=item * Missing/altered fields
-Any fields missing or altered between the two schemas will be reported
+Any fields missing or altered between the two schemas will be reported
as:
- ALTER TABLE <table_name>
- [DROP <field_name>]
+ ALTER TABLE <table_name>
+ [DROP <field_name>]
[CHANGE <field_name> <datatype> (<size>)] ;
=item * Missing/altered indices
Any indices missing or of a different type or on different fields will be
indicated. Indices that should be dropped will be reported as such:
-
+
DROP INDEX <index_name> ON <table_name> ;
-An index of a different type or on different fields will be reported as a
+An index of a different type or on different fields will be reported as a
new index as such:
- CREATE [<index_type>] INDEX [<index_name>] ON <table_name>
+ CREATE [<index_type>] INDEX [<index_name>] ON <table_name>
( <field_name>[,<field_name>] ) ;
=back
@@ -107,7 +107,7 @@ for my $arg ( @ARGV ) {
$help = 1;
}
elsif ( $arg =~ m/^-?-d(ebug)?$/ ) {
- $debug = 1;
+ $debug = 1;
}
elsif ( $arg =~ m/^([^=]+)=(.+)$/ ) {
push @input, { file => $1, parser => $2 };
@@ -181,65 +181,65 @@ for my $t1 ( $source_schema->get_tables ) {
warn "TABLE '$s1_name.$t1_name'\n" if $debug;
unless ( $t2 ) {
- warn "Couldn't find table '$s1_name.$t1_name' in '$s2_name'\n"
+ warn "Couldn't find table '$s1_name.$t1_name' in '$s2_name'\n"
if $debug;
if ( $target_db =~ /(SQLServer|Oracle)/ ) {
- for my $constraint ( $t1->get_constraints ) {
- next if $constraint->type ne FOREIGN_KEY;
- push @diffs_at_end, "ALTER TABLE $t1_name ADD ".
- constraint_to_string($constraint, $source_schema).";";
- $t1->drop_constraint($constraint);
- }
+ for my $constraint ( $t1->get_constraints ) {
+ next if $constraint->type ne FOREIGN_KEY;
+ push @diffs_at_end, "ALTER TABLE $t1_name ADD ".
+ constraint_to_string($constraint, $source_schema).";";
+ $t1->drop_constraint($constraint);
+ }
}
push @new_tables, $t1;
next;
}
-
+
# Go through our options
- my $options_different = 0;
- my %checkedOptions;
+ my $options_different = 0;
+ my %checkedOptions;
OPTION:
- for my $t1_option_ref ( $t1->options ) {
- my($key1, $value1) = %{$t1_option_ref};
- for my $t2_option_ref ( $t2->options ) {
- my($key2, $value2) = %{$t2_option_ref};
- if ( $key1 eq $key2 ) {
- if ( defined $value1 != defined $value2 ) {
- $options_different = 1;
- last OPTION;
- }
- if ( defined $value1 && $value1 ne $value2 ) {
- $options_different = 1;
- last OPTION;
- }
- $checkedOptions{$key1} = 1;
- next OPTION;
- }
- }
- $options_different = 1;
- last OPTION;
- }
+ for my $t1_option_ref ( $t1->options ) {
+ my($key1, $value1) = %{$t1_option_ref};
+ for my $t2_option_ref ( $t2->options ) {
+ my($key2, $value2) = %{$t2_option_ref};
+ if ( $key1 eq $key2 ) {
+ if ( defined $value1 != defined $value2 ) {
+ $options_different = 1;
+ last OPTION;
+ }
+ if ( defined $value1 && $value1 ne $value2 ) {
+ $options_different = 1;
+ last OPTION;
+ }
+ $checkedOptions{$key1} = 1;
+ next OPTION;
+ }
+ }
+ $options_different = 1;
+ last OPTION;
+ }
# Go through the other table's options
unless ( $options_different ) {
- for my $t2_option_ref ( $t2->options ) {
- my($key, $value) = %{$t2_option_ref};
- next if $checkedOptions{$key};
- $options_different = 1;
- last;
- }
+ for my $t2_option_ref ( $t2->options ) {
+ my($key, $value) = %{$t2_option_ref};
+ next if $checkedOptions{$key};
+ $options_different = 1;
+ last;
+ }
}
# If there's a difference, just re-set all the options
my @diffs_table_options;
if ( $options_different ) {
- my @options = ();
- foreach my $option_ref ( $t1->options ) {
- my($key, $value) = %{$option_ref};
- push(@options, defined $value ? "$key=$value" : $key);
- }
- my $options = join(' ', @options);
- @diffs_table_options = ("ALTER TABLE $t1_name $options;");
+ my @options = ();
+ foreach my $option_ref ( $t1->options ) {
+ my($key, $value) = %{$option_ref};
+ push(@options, defined $value ? "$key=$value" : $key);
+ }
+ my $options = join(' ', @options);
+ @diffs_table_options = ("ALTER TABLE $t1_name $options;");
}
-
+
my $t2_name = $t2->name;
my(@diffs_table_adds, @diffs_table_changes);
for my $t1_field ( $t1->get_fields ) {
@@ -256,48 +256,48 @@ OPTION:
my $f2_full_name = "$s2_name.$t2_name.$f1_name";
unless ( $t2_field ) {
- warn "Couldn't find field '$f2_full_name' in '$t2_name'\n"
+ warn "Couldn't find field '$f2_full_name' in '$t2_name'\n"
if $debug;
my $temp_default_value = 0;
if ( $target_db =~ /SQLServer/ && !$f1_nullable && !defined $f1_default ) {
- # SQL Server doesn't allow adding non-nullable, non-default columns
- # so we add it with a default value, then remove the default value
- $temp_default_value = 1;
- my(@numeric_types) = qw(decimal numeric float real int bigint smallint tinyint);
- $f1_default = grep($_ eq $f1_type, @numeric_types) ? 0 : '';
+ # SQL Server doesn't allow adding non-nullable, non-default columns
+ # so we add it with a default value, then remove the default value
+ $temp_default_value = 1;
+ my(@numeric_types) = qw(decimal numeric float real int bigint smallint tinyint);
+ $f1_default = grep($_ eq $f1_type, @numeric_types) ? 0 : '';
}
push @diffs_table_adds, sprintf( "ALTER TABLE %s ADD %s%s %s%s%s%s%s%s;",
$t1_name, $target_db =~ /Oracle/ ? '(' : '',
$f1_name, $f1_type,
($f1_size && $f1_type !~ /(blob|text)$/) ? "($f1_size)" : '',
!defined $f1_default ? ''
- : uc $f1_default eq 'NULL' ? ' DEFAULT NULL'
- : uc $f1_default eq 'CURRENT_TIMESTAMP' ? ' DEFAULT CURRENT_TIMESTAMP'
- : " DEFAULT '$f1_default'",
+ : uc $f1_default eq 'NULL' ? ' DEFAULT NULL'
+ : uc $f1_default eq 'CURRENT_TIMESTAMP' ? ' DEFAULT CURRENT_TIMESTAMP'
+ : " DEFAULT '$f1_default'",
$f1_nullable ? '' : ' NOT NULL',
$f1_auto_inc ? ' AUTO_INCREMENT' : '',
$target_db =~ /Oracle/ ? ')' : '',
);
if ( $temp_default_value ) {
- undef $f1_default;
- push @diffs_table_adds, sprintf( <<END
+ undef $f1_default;
+ push @diffs_table_adds, sprintf( <<END
DECLARE \@defname VARCHAR(100), \@cmd VARCHAR(1000)
-SET \@defname =
-(SELECT name
+SET \@defname =
+(SELECT name
FROM sysobjects so JOIN sysconstraints sc
-ON so.id = sc.constid
-WHERE object_name(so.parent_obj) = '%s'
+ON so.id = sc.constid
+WHERE object_name(so.parent_obj) = '%s'
AND so.xtype = 'D'
-AND sc.colid =
- (SELECT colid FROM syscolumns
- WHERE id = object_id('%s') AND
+AND sc.colid =
+ (SELECT colid FROM syscolumns
+ WHERE id = object_id('%s') AND
name = '%s'))
SET \@cmd = 'ALTER TABLE %s DROP CONSTRAINT '
+ \@defname
EXEC(\@cmd)
END
- , $t1_name, $t1_name, $f1_name, $t1_name,
- );
+ , $t1_name, $t1_name, $f1_name, $t1_name,
+ );
}
next;
}
@@ -308,131 +308,131 @@ END
my $f2_default = $t2_field->default_value;
my $f2_auto_inc = $t2_field->is_auto_increment;
if ( !$t1_field->equals($t2_field, $case_insensitive) ) {
- # SQLServer timestamp fields can't be altered, so we drop and add instead
- if ( $target_db =~ /SQLServer/ && $f2_type eq "timestamp" ) {
- push @diffs_table_changes, "ALTER TABLE $t1_name DROP COLUMN $f1_name;";
- push @diffs_table_changes, sprintf( "ALTER TABLE %s ADD %s%s %s%s%s%s%s%s;",
- $t1_name, $target_db =~ /Oracle/ ? '(' : '',
- $f1_name, $f1_type,
- ($f1_size && $f1_type !~ /(blob|text)$/) ? "($f1_size)" : '',
- !defined $f1_default ? ''
- : uc $f1_default eq 'NULL' ? ' DEFAULT NULL'
- : uc $f1_default eq 'CURRENT_TIMESTAMP' ? ' DEFAULT CURRENT_TIMESTAMP'
- : " DEFAULT '$f1_default'",
- $f1_nullable ? '' : ' NOT NULL',
- $f1_auto_inc ? ' AUTO_INCREMENT' : '',
- $target_db =~ /Oracle/ ? ')' : '',
- );
- next;
- }
-
- my $changeText = $target_db =~ /SQLServer/ ? 'ALTER COLUMN' :
- $target_db =~ /Oracle/ ? 'MODIFY (' : 'CHANGE';
- my $nullText = $f1_nullable ? '' : ' NOT NULL';
- $nullText = '' if $target_db =~ /Oracle/ && $f1_nullable == $f2_nullable;
+ # SQLServer timestamp fields can't be altered, so we drop and add instead
+ if ( $target_db =~ /SQLServer/ && $f2_type eq "timestamp" ) {
+ push @diffs_table_changes, "ALTER TABLE $t1_name DROP COLUMN $f1_name;";
+ push @diffs_table_changes, sprintf( "ALTER TABLE %s ADD %s%s %s%s%s%s%s%s;",
+ $t1_name, $target_db =~ /Oracle/ ? '(' : '',
+ $f1_name, $f1_type,
+ ($f1_size && $f1_type !~ /(blob|text)$/) ? "($f1_size)" : '',
+ !defined $f1_default ? ''
+ : uc $f1_default eq 'NULL' ? ' DEFAULT NULL'
+ : uc $f1_default eq 'CURRENT_TIMESTAMP' ? ' DEFAULT CURRENT_TIMESTAMP'
+ : " DEFAULT '$f1_default'",
+ $f1_nullable ? '' : ' NOT NULL',
+ $f1_auto_inc ? ' AUTO_INCREMENT' : '',
+ $target_db =~ /Oracle/ ? ')' : '',
+ );
+ next;
+ }
+
+ my $changeText = $target_db =~ /SQLServer/ ? 'ALTER COLUMN' :
+ $target_db =~ /Oracle/ ? 'MODIFY (' : 'CHANGE';
+ my $nullText = $f1_nullable ? '' : ' NOT NULL';
+ $nullText = '' if $target_db =~ /Oracle/ && $f1_nullable == $f2_nullable;
push @diffs_table_changes, sprintf( "ALTER TABLE %s %s %s%s %s%s%s%s%s%s;",
$t1_name, $changeText,
$f1_name, $target_db =~ /MySQL/ ? " $f1_name" : '',
$f1_type, ($f1_size && $f1_type !~ /(blob|text)$/) ? "($f1_size)" : '',
$nullText,
!defined $f1_default || $target_db =~ /SQLServer/ ? ''
- : uc $f1_default eq 'NULL' ? ' DEFAULT NULL'
- : uc $f1_default eq 'CURRENT_TIMESTAMP' ? ' DEFAULT CURRENT_TIMESTAMP'
- : " DEFAULT '$f1_default'",
+ : uc $f1_default eq 'NULL' ? ' DEFAULT NULL'
+ : uc $f1_default eq 'CURRENT_TIMESTAMP' ? ' DEFAULT CURRENT_TIMESTAMP'
+ : " DEFAULT '$f1_default'",
$f1_auto_inc ? ' AUTO_INCREMENT' : '',
$target_db =~ /Oracle/ ? ')' : '',
);
if ( defined $f1_default && $target_db =~ /SQLServer/ ) {
- # Adding a column with a default value for SQL Server means adding a
- # constraint and setting existing NULLs to the default value
- push @diffs_table_changes, sprintf( "ALTER TABLE %s ADD CONSTRAINT DF_%s_%s %s FOR %s;",
- $t1_name, $t1_name, $f1_name, uc $f1_default eq 'NULL' ? 'DEFAULT NULL'
- : uc $f1_default eq 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP'
- : "DEFAULT '$f1_default'", $f1_name,
+ # Adding a column with a default value for SQL Server means adding a
+ # constraint and setting existing NULLs to the default value
+ push @diffs_table_changes, sprintf( "ALTER TABLE %s ADD CONSTRAINT DF_%s_%s %s FOR %s;",
+ $t1_name, $t1_name, $f1_name, uc $f1_default eq 'NULL' ? 'DEFAULT NULL'
+ : uc $f1_default eq 'CURRENT_TIMESTAMP' ? 'DEFAULT CURRENT_TIMESTAMP'
+ : "DEFAULT '$f1_default'", $f1_name,
);
- push @diffs_table_changes, sprintf( "UPDATE %s SET %s = %s WHERE %s IS NULL;",
- $t1_name, $f1_name, uc $f1_default eq 'NULL' ? 'NULL'
- : uc $f1_default eq 'CURRENT_TIMESTAMP' ? 'CURRENT_TIMESTAMP'
- : "'$f1_default'", $f1_name,
+ push @diffs_table_changes, sprintf( "UPDATE %s SET %s = %s WHERE %s IS NULL;",
+ $t1_name, $f1_name, uc $f1_default eq 'NULL' ? 'NULL'
+ : uc $f1_default eq 'CURRENT_TIMESTAMP' ? 'CURRENT_TIMESTAMP'
+ : "'$f1_default'", $f1_name,
);
}
}
}
-
- my(%checked_indices, @diffs_index_creates, @diffs_index_drops);
+
+ my(%checked_indices, @diffs_index_creates, @diffs_index_drops);
INDEX:
- for my $i1 ( $t1->get_indices ) {
- for my $i2 ( $t2->get_indices ) {
- if ( $i1->equals($i2, $case_insensitive) ) {
- $checked_indices{$i2} = 1;
- next INDEX;
- }
- }
- push @diffs_index_creates, sprintf(
+ for my $i1 ( $t1->get_indices ) {
+ for my $i2 ( $t2->get_indices ) {
+ if ( $i1->equals($i2, $case_insensitive) ) {
+ $checked_indices{$i2} = 1;
+ next INDEX;
+ }
+ }
+ push @diffs_index_creates, sprintf(
"CREATE %sINDEX%s ON %s (%s);",
$i1->type eq NORMAL ? '' : $i1->type." ",
$i1->name ? " ".$i1->name : '',
$t1_name,
join(",", $i1->fields),
);
- }
+ }
INDEX2:
- for my $i2 ( $t2->get_indices ) {
- next if $checked_indices{$i2};
- for my $i1 ( $t1->get_indices ) {
- next INDEX2 if $i2->equals($i1, $case_insensitive);
- }
- $target_db =~ /SQLServer/
- ? push @diffs_index_drops, "DROP INDEX $t1_name.".$i2->name.";"
- : push @diffs_index_drops, "DROP INDEX ".$i2->name." on $t1_name;";
- }
-
- my(%checked_constraints, @diffs_constraint_drops);
+ for my $i2 ( $t2->get_indices ) {
+ next if $checked_indices{$i2};
+ for my $i1 ( $t1->get_indices ) {
+ next INDEX2 if $i2->equals($i1, $case_insensitive);
+ }
+ $target_db =~ /SQLServer/
+ ? push @diffs_index_drops, "DROP INDEX $t1_name.".$i2->name.";"
+ : push @diffs_index_drops, "DROP INDEX ".$i2->name." on $t1_name;";
+ }
+
+ my(%checked_constraints, @diffs_constraint_drops);
CONSTRAINT:
- for my $c1 ( $t1->get_constraints ) {
- next if $source_db =~ /Oracle/ && $c1->type eq UNIQUE && $c1->name =~ /^SYS_/i;
- for my $c2 ( $t2->get_constraints ) {
- if ( $c1->equals($c2, $case_insensitive) ) {
- $checked_constraints{$c2} = 1;
- next CONSTRAINT;
- }
- }
- push @diffs_at_end, "ALTER TABLE $t1_name ADD ".
- constraint_to_string($c1, $source_schema).";";
- }
+ for my $c1 ( $t1->get_constraints ) {
+ next if $source_db =~ /Oracle/ && $c1->type eq UNIQUE && $c1->name =~ /^SYS_/i;
+ for my $c2 ( $t2->get_constraints ) {
+ if ( $c1->equals($c2, $case_insensitive) ) {
+ $checked_constraints{$c2} = 1;
+ next CONSTRAINT;
+ }
+ }
+ push @diffs_at_end, "ALTER TABLE $t1_name ADD ".
+ constraint_to_string($c1, $source_schema).";";
+ }
CONSTRAINT2:
- for my $c2 ( $t2->get_constraints ) {
- next if $checked_constraints{$c2};
- for my $c1 ( $t1->get_constraints ) {
- next CONSTRAINT2 if $c2->equals($c1, $case_insensitive);
- }
- if ( $c2->type eq UNIQUE ) {
- push @diffs_constraint_drops, "ALTER TABLE $t1_name DROP INDEX ".
- $c2->name.";";
- } elsif ( $target_db =~ /SQLServer/ ) {
- push @diffs_constraint_drops, "ALTER TABLE $t1_name DROP ".$c2->name.";";
- } else {
- push @diffs_constraint_drops, "ALTER TABLE $t1_name DROP ".$c2->type.
- ($c2->type eq FOREIGN_KEY ? " ".$c2->name : '').";";
- }
- }
-
- push @diffs, @diffs_index_drops, @diffs_constraint_drops,
- @diffs_table_options, @diffs_table_adds,
- @diffs_table_changes, @diffs_index_creates;
+ for my $c2 ( $t2->get_constraints ) {
+ next if $checked_constraints{$c2};
+ for my $c1 ( $t1->get_constraints ) {
+ next CONSTRAINT2 if $c2->equals($c1, $case_insensitive);
+ }
+ if ( $c2->type eq UNIQUE ) {
+ push @diffs_constraint_drops, "ALTER TABLE $t1_name DROP INDEX ".
+ $c2->name.";";
+ } elsif ( $target_db =~ /SQLServer/ ) {
+ push @diffs_constraint_drops, "ALTER TABLE $t1_name DROP ".$c2->name.";";
+ } else {
+ push @diffs_constraint_drops, "ALTER TABLE $t1_name DROP ".$c2->type.
+ ($c2->type eq FOREIGN_KEY ? " ".$c2->name : '').";";
+ }
+ }
+
+ push @diffs, @diffs_index_drops, @diffs_constraint_drops,
+ @diffs_table_options, @diffs_table_adds,
+ @diffs_table_changes, @diffs_index_creates;
}
for my $t2 ( $target_schema->get_tables ) {
my $t2_name = $t2->name;
my $t1 = $source_schema->get_table( $t2_name, $target_db =~ /SQLServer/ );
unless ( $t1 ) {
- if ( $target_db =~ /SQLServer/ ) {
- for my $constraint ( $t2->get_constraints ) {
- next if $constraint->type eq PRIMARY_KEY;
- push @diffs, "ALTER TABLE $t2_name DROP ".$constraint->name.";";
- }
- }
+ if ( $target_db =~ /SQLServer/ ) {
+ for my $constraint ( $t2->get_constraints ) {
+ next if $constraint->type eq PRIMARY_KEY;
+ push @diffs, "ALTER TABLE $t2_name DROP ".$constraint->name.";";
+ }
+ }
push @diffs_at_end, "DROP TABLE $t2_name;";
next;
}
@@ -441,7 +441,7 @@ for my $t2 ( $target_schema->get_tables ) {
my $f2_name = $t2_field->name;
my $t1_field = $t1->get_field( $f2_name );
unless ( $t1_field ) {
- my $modifier = $target_db =~ /SQLServer/ ? "COLUMN " : '';
+ my $modifier = $target_db =~ /SQLServer/ ? "COLUMN " : '';
push @diffs, "ALTER TABLE $t2_name DROP $modifier$f2_name;";
}
}
@@ -462,7 +462,7 @@ if ( @diffs ) {
}
if ( @diffs ) {
- print join( "\n",
+ print join( "\n",
"-- Convert schema '$s2_name' to '$s1_name':\n", @diffs, "\n"
);
exit(1);
@@ -472,74 +472,74 @@ else {
}
sub constraint_to_string {
- my $c = shift;
- my $schema = shift or die "No schema given";
- my @fields = $c->field_names or return '';
-
- if ( $c->type eq PRIMARY_KEY ) {
- if ( $target_db =~ /Oracle/ ) {
- return (defined $c->name ? 'CONSTRAINT '.$c->name.' ' : '') .
- 'PRIMARY KEY (' . join(', ', @fields). ')';
- } else {
- return 'PRIMARY KEY (' . join(', ', @fields). ')';
- }
- }
- elsif ( $c->type eq UNIQUE ) {
- if ( $target_db =~ /Oracle/ ) {
- return (defined $c->name ? 'CONSTRAINT '.$c->name.' ' : '') .
- 'UNIQUE (' . join(', ', @fields). ')';
- } else {
- return 'UNIQUE '.
- (defined $c->name ? $c->name.' ' : '').
- '(' . join(', ', @fields). ')';
- }
- }
- elsif ( $c->type eq FOREIGN_KEY ) {
- my $def = join(' ',
- map { $_ || () } 'CONSTRAINT', $c->name, 'FOREIGN KEY'
- );
-
- $def .= ' (' . join( ', ', @fields ) . ')';
-
- $def .= ' REFERENCES ' . $c->reference_table;
-
- my @rfields = map { $_ || () } $c->reference_fields;
- unless ( @rfields ) {
- my $rtable_name = $c->reference_table;
- if ( my $ref_table = $schema->get_table( $rtable_name ) ) {
- push @rfields, $ref_table->primary_key;
- }
- else {
- warn "Can't find reference table '$rtable_name' " .
- "in schema\n";
- }
- }
-
- if ( @rfields ) {
- $def .= ' (' . join( ', ', @rfields ) . ')';
- }
- else {
- warn "FK constraint on " . 'some table' . '.' .
- join('', @fields) . " has no reference fields\n";
- }
-
- if ( $c->match_type ) {
- $def .= ' MATCH ' .
- ( $c->match_type =~ /full/i ) ? 'FULL' : 'PARTIAL';
- }
-
- if ( $c->on_delete ) {
- $def .= ' ON DELETE '.join( ' ', $c->on_delete );
- }
-
- if ( $c->on_update ) {
- $def .= ' ON UPDATE '.join( ' ', $c->on_update );
- }
-
- return $def;
- }
+ my $c = shift;
+ my $schema = shift or die "No schema given";
+ my @fields = $c->field_names or return '';
+
+ if ( $c->type eq PRIMARY_KEY ) {
+ if ( $target_db =~ /Oracle/ ) {
+ return (defined $c->name ? 'CONSTRAINT '.$c->name.' ' : '') .
+ 'PRIMARY KEY (' . join(', ', @fields). ')';
+ } else {
+ return 'PRIMARY KEY (' . join(', ', @fields). ')';
+ }
+ }
+ elsif ( $c->type eq UNIQUE ) {
+ if ( $target_db =~ /Oracle/ ) {
+ return (defined $c->name ? 'CONSTRAINT '.$c->name.' ' : '') .
+ 'UNIQUE (' . join(', ', @fields). ')';
+ } else {
+ return 'UNIQUE '.
+ (defined $c->name ? $c->name.' ' : '').
+ '(' . join(', ', @fields). ')';
+ }
+ }
+ elsif ( $c->type eq FOREIGN_KEY ) {
+ my $def = join(' ',
+ map { $_ || () } 'CONSTRAINT', $c->name, 'FOREIGN KEY'
+ );
+
+ $def .= ' (' . join( ', ', @fields ) . ')';
+
+ $def .= ' REFERENCES ' . $c->reference_table;
+
+ my @rfields = map { $_ || () } $c->reference_fields;
+ unless ( @rfields ) {
+ my $rtable_name = $c->reference_table;
+ if ( my $ref_table = $schema->get_table( $rtable_name ) ) {
+ push @rfields, $ref_table->primary_key;
+ }
+ else {
+ warn "Can't find reference table '$rtable_name' " .
+ "in schema\n";
+ }
+ }
+
+ if ( @rfields ) {
+ $def .= ' (' . join( ', ', @rfields ) . ')';
+ }
+ else {
+ warn "FK constraint on " . 'some table' . '.' .
+ join('', @fields) . " has no reference fields\n";
+ }
+
+ if ( $c->match_type ) {
+ $def .= ' MATCH ' .
+ ( $c->match_type =~ /full/i ) ? 'FULL' : 'PARTIAL';
+ }
+
+ if ( $c->on_delete ) {
+ $def .= ' ON DELETE '.join( ' ', $c->on_delete );
+ }
+
+ if ( $c->on_update ) {
+ $def .= ' ON UPDATE '.join( ' ', $c->on_update );
+ }
+
+ return $def;
+ }
}
-
+
# -------------------------------------------------------------------
# Bring out number weight & measure in a year of dearth.
# William Blake
View
26 script/sqlt-graph
@@ -18,7 +18,7 @@
# 02111-1307 USA
# -------------------------------------------------------------------
-=head1 NAME
+=head1 NAME
sqlt-graph - Automatically create a graph from a database schema
@@ -30,9 +30,9 @@ sqlt-graph - Automatically create a graph from a database schema
-l|--layout Layout schema for GraphViz
("dot," "neato," "twopi"; default "dot")
- -n|--node-shape Shape of the nodes ("record," "plaintext,"
- "ellipse," "circle," "egg," "triangle," "box,"
- "diamond," "trapezium," "parallelogram," "house,"
+ -n|--node-shape Shape of the nodes ("record," "plaintext,"
+ "ellipse," "circle," "egg," "triangle," "box,"
+ "diamond," "trapezium," "parallelogram," "house,"
"hexagon," "octagon," default "record")
-o|--output Output file name (default STDOUT)
-t|--output-type Output file type ("canon", "text," "ps," "hpgl,"
@@ -44,13 +44,13 @@ sqlt-graph - Automatically create a graph from a database schema
--no-fields Don't show field names
--height Image height (in inches, default "11",
set to "0" to undefine)
- --width Image width (in inches, default "8.5",
+ --width Image width (in inches, default "8.5",
set to "0" to undefine)
--fontsize custom font size for node and edge labels
- --fontname name of custom font (or full path to font file) for
+ --fontname name of custom font (or full path to font file) for
node, edge, and graph labels
--nodeattr attribute name and value (in key=val syntax) for
- nodes; this option may be repeated to specify
+ nodes; this option may be repeated to specify
multiple node attributes
--edgeattr same as --nodeattr, but for edge attributes
--graphattr same as --nodeattr, but for graph attributes
@@ -60,7 +60,7 @@ sqlt-graph - Automatically create a graph from a database schema
--show-sizes Show column sizes for VARCHAR and CHAR fields
--show-constraints Show list of constraints for each field
-s|--skip Fields to skip in natural joins
- --skip-tables Comma-separated list of table names to exclude
+ --skip-tables Comma-separated list of table names to exclude
--skip-tables-like Comma-separated list of regexen to exclude tables
--debug Print debugging information
@@ -88,8 +88,8 @@ If the schema defines foreign keys, then the graph produced will be
directed showing the direction of the relationship. If the foreign
keys are intuited via natural joins, the graph will be undirected.
-Clustering of tables allows you to group and box tables according to
-function or domain or whatever criteria you choose. The syntax for
+Clustering of tables allows you to group and box tables according to
+function or domain or whatever criteria you choose. The syntax for
clustering tables is:
cluster1=table1,table2;cluster2=table3,table4
@@ -112,8 +112,8 @@ $VERSION = '1.59';
#
# Get arguments.
#
-my (
- $layout, $node_shape, $out_file, $output_type, $db_driver, $add_color,
+my (
+ $layout, $node_shape, $out_file, $output_type, $db_driver, $add_color,
$natural_join, $join_pk_only, $skip_fields, $show_datatypes,
$show_sizes, $show_constraints, $debug, $help, $height, $width,
$no_fields, $fontsize, $fontname, $skip_tables, $skip_tables_like,
@@ -158,7 +158,7 @@ pod2usage(1) if $help;
pod2usage( -message => "No db driver specified" ) unless $db_driver;
pod2usage( -message => 'No input file' ) unless @files;
-my $translator = SQL::Translator->new(
+my $translator = SQL::Translator->new(
from => $db_driver,
to => 'GraphViz',
debug => $debug || 0,
View
196 script/sqlt.cgi
@@ -25,7 +25,7 @@ sqlt.cgi - CGI front-end for SQL::Translator
=head1 DESCRIPTION
Place this script in your "cgi-bin" directory and point your browser
-to it. This script is meant to be a simple graphical interface to
+to it. This script is meant to be a simple graphical interface to
all the parsers and producers of SQL::Translator.
=cut
@@ -58,18 +58,18 @@ eval {
my $output_type = $producer eq 'Diagram'
? $q->param('diagram_output_type')
: $producer eq 'GraphViz'
- ? $q->param('graphviz_output_type')
+ ? $q->param('graphviz_output_type')
: ''
;
- my $t = SQL::Translator->new(
+ my $t = SQL::Translator->new(
from => $q->param('parser'),
producer_args => {
add_drop_table => $q->param('add_drop_table'),
output_type => $output_type,
title => $q->param('title') || 'Schema',
- natural_join => $q->param('natural_join') eq 'no' ? 0 : 1,
- join_pk_only => $q->param('natural_join') eq 'pk_only'
+ natural_join => $q->param('natural_join') eq 'no' ? 0 : 1,
+ join_pk_only => $q->param('natural_join') eq 'pk_only'
? 1 : 0,
add_color => $q->param('add_color'),
skip_fields => $q->param('skip_fields'),
@@ -136,41 +136,41 @@ sub show_form {
my $q = shift;
my $title = 'SQL::Translator';
- print $q->header,
+ print $q->header,
$q->start_html( -title => $title ),
$q->h1( qq[<a href="http://sqlfairy.sourceforge.net">$title</a>] ),
$q->start_form(-enctype => 'multipart/form-data'),
$q->table( { -border => 1 },
- $q->Tr(
+ $q->Tr(
$q->td( [
'Upload your schema file:',
$q->filefield( -name => 'schema_file'),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Or paste your schema here:',
- $q->textarea(
- -name => 'schema',
- -rows => 5,
+ $q->textarea(
+ -name => 'schema',
+ -rows => 5,
-columns => 60,
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Parser:',
$q->radio_group(
-name => 'parser',
- -values => [ qw( MySQL PostgreSQL Oracle
- Sybase Excel XML-SQLFairy xSV
+ -values => [ qw( MySQL PostgreSQL Oracle
+ Sybase Excel XML-SQLFairy xSV
) ],
-default => 'MySQL',
-rows => 3,
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Producer:',
$q->radio_group(
@@ -184,103 +184,103 @@ sub show_form {
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td(
{ -colspan => 2, -align => 'center' },
- $q->submit(
- -name => 'submit',
+ $q->submit(
+ -name => 'submit',
-value => 'Submit',
)
),
),
- $q->Tr(
- $q->th(
- { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
- 'General Options:'
+ $q->Tr(
+ $q->th(
+ { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
+ 'General Options:'
),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Validate Schema:',
$q->radio_group(
-name => 'validate',
-values => [ 1, 0 ],
- -labels => {
- 1 => 'Yes',
- 0 => 'No'
+ -labels => {
+ 1 => 'Yes',
+ 0 => 'No'
},
-default => 0,
-rows => 2,
),
] ),
),
- $q->Tr(
- $q->th(
- { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
- 'DB Producer Options:'
+ $q->Tr(
+ $q->th(
+ { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
+ 'DB Producer Options:'
),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Add &quot;DROP TABLE&quot; statements:',
$q->radio_group(
-name => 'add_drop_table',
-values => [ 1, 0 ],
- -labels => {
- 1 => 'Yes',
- 0 => 'No'
+ -labels => {
+ 1 => 'Yes',
+ 0 => 'No'
},
-default => 0,
-rows => 2,
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Include comments:',
$q->radio_group(
-name => 'comments',
-values => [ 1, 0 ],
- -labels => {
- 1 => 'Yes',
- 0 => 'No'
+ -labels => {
+ 1 => 'Yes',
+ 0 => 'No'
},
-default => 1,
-rows => 2,
),
] ),
),
- $q->Tr(
- $q->th(
- { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
- 'HTML/POD/Diagram Producer Options:'
+ $q->Tr(
+ $q->th(
+ { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
+ 'HTML/POD/Diagram Producer Options:'
),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Title:',
$q->textfield('title'),
] ),
),
- $q->Tr(
- $q->th(
- { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
- 'TTSchema Producer Options:'
+ $q->Tr(
+ $q->th(
+ { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
+ 'TTSchema Producer Options:'
),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Template:',
$q->filefield( -name => 'template'),
] ),
),
- $q->Tr(
- $q->th(
- { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
+ $q->Tr(
+ $q->th(
+ { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
'Graphical Producer Options'
),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Perform Natural Joins:',
$q->radio_group(
@@ -296,7 +296,7 @@ sub show_form {
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Skip These Fields in Natural Joins:',
$q->textarea(
@@ -306,7 +306,7 @@ sub show_form {
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Show Only Foreign Keys:',
$q->radio_group(
@@ -321,22 +321,22 @@ sub show_form {
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Add Color:',
$q->radio_group(
-name => 'add_color',
-values => [ 1, 0 ],
- -labels => {
- 1 => 'Yes',
- 0 => 'No'
+ -labels => {
+ 1 => 'Yes',
+ 0 => 'No'
},
-default => 1,
-rows => 2,
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Show Field Names:',
$q->radio_group(
@@ -351,13 +351,13 @@ sub show_form {
),
] ),
),
- $q->Tr(
- $q->th(
- { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
+ $q->Tr(
+ $q->th(
+ { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
'Diagram Producer Options'
),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Output Type:',
$q->radio_group(
@@ -368,7 +368,7 @@ sub show_form {
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Font Size:',
$q->radio_group(
@@ -379,19 +379,19 @@ sub show_form {
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Number of Columns:',
$q->textfield('no_columns'),
] ),
),
- $q->Tr(
- $q->th(
- { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
+ $q->Tr(
+ $q->th(
+ { align => 'left', bgcolor => 'lightgrey', colspan => 2 },
'GraphViz Producer Options'
),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Output Type:',
$q->radio_group(
@@ -405,7 +405,7 @@ sub show_form {
),
] ),
),
- $q->Tr(
+ $q->Tr(
$q->td( [
'Layout:',
$q->radio_group(
@@ -416,87 +416,87 @@ sub show_form {