3 # This script helps you synchronize database comments between DB and schema.
5 # This file is part of Koha.
7 # Copyright 2022 Rijksmuseum, Koha development team
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Data::Dumper qw(Dumper);
24 use Getopt::Long qw( GetOptions );
25 use Pod::Usage qw( pod2usage );
28 use Koha::Database::Commenter;
32 'clear' => \$cmd_args->{clear},
33 'database:s' => \$cmd_args->{database},
34 'dry_run' => \$cmd_args->{dry_run},
35 'help|h' => \$cmd_args->{help},
36 'renumber' => \$cmd_args->{renumber},
37 'reset' => \$cmd_args->{reset},
38 'table:s' => \$cmd_args->{table},
39 'verbose|v' => \$cmd_args->{verbose},
42 my $commenter = Koha::Database::Commenter->new({ database => delete $cmd_args->{database}, dbh => C4::Context->dbh });
43 if( $cmd_args->{help} ) {
44 pod2usage( -verbose => 2 );
45 } elsif( delete $cmd_args->{clear} ) { # clear overrules reset
46 alert_dry_run( $cmd_args->{dry_run} );
47 $commenter->clear( $cmd_args );
48 } elsif( delete $cmd_args->{reset} ) { # reset overrules renumber
49 alert_dry_run( $cmd_args->{dry_run} );
50 $commenter->reset_to_schema( $cmd_args );
51 } elsif( delete $cmd_args->{renumber} ) {
52 alert_dry_run( $cmd_args->{dry_run} );
53 $commenter->renumber( $cmd_args );
55 pod2usage( -verbose => 1 );
58 sub alert_dry_run { print "-- DRY RUN\n" if $_[0]; }
66 misc/maintenance/sync_db_comments.pl
70 perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-dry_run] [-clear|-reset|-renumber]
74 Synchronize column comments in database with Koha schema. Allows you
75 to clear comments too. Operates additionally on specific tables only.
76 And provides a dry run mode that prints sql statements.
78 Warning: According to good practice, make a backup of your database
79 before running this script.
83 misc/maintance/sync_db_comments.pl -help
86 misc/maintance/sync_db_comments.pl -clear -verbose
87 Clear all column comments in database.
88 The verbose flag shows all issued ALTER TABLE statements.
90 misc/maintance/sync_db_comments.pl -reset -database mydb -table items
91 Only resets comments in items table.
92 Operates on specific database instead of the one from $KOHA_CONF.
94 misc/maintance/sync_db_comments.pl -renumber -dry_run
95 Renumbers all comments like Comment_1,2,..
96 Added for testing purposes. Not meant to run on production.
97 The dry_run flag allows you to see what would be done.
99 =head1 ADDITIONAL COMMENTS
101 This script may prove helpful to track synchronization issues between
102 Koha schema and actual database structure due to inconsistencies in
103 database revisions. It reduces the noise from missing column comments
104 when running script update_dbix_class_files.pl.
106 The script is just a wrapper around the module Koha::Database::Commenter.
107 A test script is provided in t/db_dependent/Koha/Database/Commenter.t.
109 The flags -clear, -reset and -renumber are mutually exclusive. Clear ignores
110 the other two, reset ignores renumber.
112 The renumber option has been helpful in verifying that the alter table
113 operations work on the complete Koha database. It is not recommended to run
114 it in production (obviously).
118 Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands