5 use SQL::Translator::Diff;
10 my $filename = "./installer/data/mysql/kohastructure.sql";
13 "filename=s" => \$filename,
14 ) or die("Error in command line arguments\n");
16 if ( ! -f $filename ){
17 die("Filename '$filename' does not exist\n");
20 my $sql_schema = get_kohastructure({ filename => $filename, });
21 my $db_schema = get_db();
23 if ($sql_schema && $db_schema){
24 my $diff = SQL::Translator::Diff->new({
26 source_schema => $db_schema,
27 target_schema => $sql_schema,
28 })->compute_differences->produce_diff_sql;
33 print "These commands are only suggestions! They are not a replacement for updatedatabase.pl!\n";
34 print "Review the database, updatedatabase.pl, and kohastructure.sql before making any changes!\n";
39 my $database_name = C4::Context->config("database");
40 print "Parsing schema for database '$database_name'\n";
41 my $dbh = C4::Context->dbh;
42 my $parser = SQL::Translator->new(
48 my $schema = $parser->translate();
50 #NOTE: Hack the schema to remove autoincrement
51 #Otherwise, that difference will cause options for all tables to be reset unnecessarily
52 my @tables = $schema->get_tables();
53 foreach my $table (@tables){
55 my $replace_options = 0;
56 my $options = $table->{options};
57 foreach my $hashref (@$options){
58 if ( $hashref->{AUTO_INCREMENT} ){
62 push(@new_options,$hashref);
65 if ($replace_options){
66 @{$table->{options}} = @new_options;
72 sub get_kohastructure {
74 my $filename = $args->{filename};
75 print "Parsing schema for file '$filename'\n";
76 my $translator = SQL::Translator->new();
77 $translator->parser("MySQL");
78 my $schema = $translator->translate($filename);