4141our $after_file ;
4242our $unsure_file ;
4343our $keep_identifier_case ;
44+ our $validate_constraints =' yes' ;
4445
4546my $template
4647 ; # These two variables are loaded in the BEGIN block at the end of this file (they are very big
@@ -77,7 +78,8 @@ sub parse_conf_file
7778 ' no relabel dbo' => ' norelabel_dbo' ,
7879 ' convert numeric to int' => ' convert_numeric_to_int' ,
7980 ' relabel schemas' => ' relabel_schemas' ,
80- ' keep identifier case' => ' keep_identifier_case' ,
81+ ' keep identifier case' => ' keep_identifier_case' ,
82+ ' validate constraints' => ' validate_constraints' ,
8183 );
8284
8385 # Open the conf file or die
@@ -1823,8 +1825,18 @@ sub generate_schema
18231825 {
18241826 $consdef .= " ON UPDATE CASCADE" ;
18251827 }
1828+ # We need a name on the constraint to be able to validate it later. Maybe it would be better to generate one
1829+ # FIXME: we'll see later if a generator is needed (probably)
1830+ if ($constraint -> {TYPE } eq ' FK' and ($validate_constraints =~ / ^after|no$ / ) and defined ($constraint -> {NAME }))
1831+ {
1832+ $consdef .= " NOT VALID" ;
1833+ }
18261834 $consdef .= " ;\n " ;
18271835 print AFTER $consdef ;
1836+ if ($constraint -> {TYPE } eq ' FK' and $validate_constraints eq ' after' and defined $constraint -> {NAME })
1837+ {
1838+ print UNSURE " ALTER TABLE " . format_identifier($schema ) . ' .' . format_identifier($table ) . " VALIDATE CONSTRAINT " . format_identifier($constraint -> {NAME }) . " ;\n " ;
1839+ }
18281840 }
18291841 elsif ($constraint -> {TYPE } eq ' CHECK' )
18301842 {
@@ -2075,7 +2087,8 @@ sub resolve_name_conflicts
20752087 " nr" => \$norelabel_dbo ,
20762088 " num" => \$convert_numeric_to_int ,
20772089 " relabel_schemas=s" => \$relabel_schemas ,
2078- " keep_identifier_case" => \$keep_identifier_case ,);
2090+ " keep_identifier_case" => \$keep_identifier_case ,
2091+ " validate_constraints=s" => \$validate_constraints ,);
20792092
20802093# We don't understand command line or have been asked for usage
20812094if (not $options or $help )
@@ -2101,6 +2114,11 @@ sub resolve_name_conflicts
21012114 exit 1;
21022115}
21032116
2117+ if ($validate_constraints !~ ' ^(yes|after|no)$' )
2118+ {
2119+ die " validate_constraints should be yes, after or no (default yes)\n " ;
2120+ }
2121+
21042122# We have been asked for kettle, but the compulsory parameters are not there
21052123if ($kettle
21062124 and ( not $sd
0 commit comments