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(
27 source_schema => $db_schema,
28 target_schema => $sql_schema,
30 )->compute_differences->produce_diff_sql;
35 print "These commands are only suggestions! They are not a replacement for updatedatabase.pl!\n";
36 print "Review the database, updatedatabase.pl, and kohastructure.sql before making any changes!\n";
41 my $database_name = C4::Context->config("database");
42 print "Parsing schema for database '$database_name'\n";
43 my $dbh = C4::Context->dbh;
44 my $parser = SQL::Translator->new(
50 my $schema = $parser->translate();
52 #NOTE: Hack the schema to remove autoincrement
53 #Otherwise, that difference will cause options for all tables to be reset unnecessarily
54 my @tables = $schema->get_tables();
55 foreach my $table (@tables) {
57 my $replace_options = 0;
58 my $options = $table->{options};
59 foreach my $hashref (@$options) {
60 if ( $hashref->{AUTO_INCREMENT} ) {
63 push( @new_options, $hashref );
66 if ($replace_options) {
67 @{ $table->{options} } = @new_options;
73 sub get_kohastructure {
75 my $filename = $args->{filename};
76 print "Parsing schema for file '$filename'\n";
77 my $translator = SQL::Translator->new();
78 $translator->parser("MySQL");
79 my $schema = $translator->translate($filename);