Bugzilla – Attachment 146715 Details for
Bug 32334
Sync comments in database with schema
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32334: Add sync_db_comments script
Bug-32334-Add-syncdbcomments-script.patch (text/plain), 5.70 KB, created by
Marcel de Rooy
on 2023-02-16 08:51:27 UTC
(
hide
)
Description:
Bug 32334: Add sync_db_comments script
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2023-02-16 08:51:27 UTC
Size:
5.70 KB
patch
obsolete
>From f0b6d8204ba10f48d1cff46cc6cb683474955773 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Wed, 23 Nov 2022 13:19:35 +0100 >Subject: [PATCH] Bug 32334: Add sync_db_comments script >Content-Type: text/plain; charset=utf-8 > >Test plan: >[1] Backup your database, if not done already. >[2] Check output of dry_run when clearing a table: > misc/maintenance/sync_db_comments.pl -clear -table items -dry >[3] Save output of misc/devel/update_dbix_class_files before changing > comments in order to compare later. (Commit your changes.) > You may not have changes after running (at least on a fresh > database). That's fine. >[4] Clear all comments: > misc/maintenance/sync_db_comments.pl -clear >[5] Renumber all comments: > misc/maintenance/sync_db_comments.pl -renum >[6] Reset all comments to schema. Make sure that script finds your > structure in installer/data/mysql folder. > misc/maintenance/sync_db_comments.pl -reset >[7] Run update_dbix_class_files again and inspect changes as compared > to previous run. > Can you explain them? You should only see changes related to > column comments. If you did not have changes in step 3, you > should not have them here too. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > misc/maintenance/sync_db_comments.pl | 120 +++++++++++++++++++++++++++ > 1 file changed, 120 insertions(+) > create mode 100755 misc/maintenance/sync_db_comments.pl > >diff --git a/misc/maintenance/sync_db_comments.pl b/misc/maintenance/sync_db_comments.pl >new file mode 100755 >index 0000000000..6fbd2e6d52 >--- /dev/null >+++ b/misc/maintenance/sync_db_comments.pl >@@ -0,0 +1,120 @@ >+#!/usr/bin/perl >+ >+# This script helps you synchronize database comments between DB and schema. >+ >+# This file is part of Koha. >+# >+# Copyright 2022 Rijksmuseum, Koha development team >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Data::Dumper qw(Dumper); >+use Getopt::Long qw( GetOptions ); >+use Pod::Usage qw( pod2usage ); >+ >+use C4::Context; >+use Koha::Database::Commenter; >+ >+my $cmd_args = {}; >+GetOptions( >+ 'clear' => \$cmd_args->{clear}, >+ 'database:s' => \$cmd_args->{database}, >+ 'dry_run' => \$cmd_args->{dry_run}, >+ 'help|h' => \$cmd_args->{help}, >+ 'renumber' => \$cmd_args->{renumber}, >+ 'reset' => \$cmd_args->{reset}, >+ 'table:s' => \$cmd_args->{table}, >+ 'verbose|v' => \$cmd_args->{verbose}, >+); >+ >+my $commenter = Koha::Database::Commenter->new({ database => delete $cmd_args->{database}, dbh => C4::Context->dbh }); >+if( $cmd_args->{help} ) { >+ pod2usage( -verbose => 2 ); >+} elsif( delete $cmd_args->{clear} ) { # clear overrules reset >+ alert_dry_run( $cmd_args->{dry_run} ); >+ $commenter->clear( $cmd_args ); >+} elsif( delete $cmd_args->{reset} ) { # reset overrules renumber >+ alert_dry_run( $cmd_args->{dry_run} ); >+ $commenter->reset_to_schema( $cmd_args ); >+} elsif( delete $cmd_args->{renumber} ) { >+ alert_dry_run( $cmd_args->{dry_run} ); >+ $commenter->renumber( $cmd_args ); >+} else { >+ pod2usage( -verbose => 1 ); >+} >+ >+sub alert_dry_run { print "-- DRY RUN\n" if $_[0]; } >+ >+__END__ >+ >+=pod >+ >+=head1 NAME >+ >+misc/maintenance/sync_db_comments.pl >+ >+=head1 SYNOPSIS >+ >+ perl sync_db_comments.pl [-h] [-v] [-database DB_NAME] [-table TABLE_NAME] [-dry_run] [-clear|-reset|-renumber] >+ >+=head1 DESCRIPTION >+ >+ Synchronize column comments in database with Koha schema. Allows you >+ to clear comments too. Operates additionally on specific tables only. >+ And provides a dry run mode that prints sql statements. >+ >+ Warning: According to good practice, make a backup of your database >+ before running this script. >+ >+ Some examples: >+ >+ misc/maintance/sync_db_comments.pl -help >+ Usage statement. >+ >+ misc/maintance/sync_db_comments.pl -clear -verbose >+ Clear all column comments in database. >+ The verbose flag shows all issued ALTER TABLE statements. >+ >+ misc/maintance/sync_db_comments.pl -reset -database mydb -table items >+ Only resets comments in items table. >+ Operates on specific database instead of the one from $KOHA_CONF. >+ >+ misc/maintance/sync_db_comments.pl -renumber -dry_run >+ Renumbers all comments like Comment_1,2,.. >+ Added for testing purposes. Not meant to run on production. >+ The dry_run flag allows you to see what would be done. >+ >+=head1 ADDITIONAL COMMENTS >+ >+ This script may prove helpful to track synchronization issues between >+ Koha schema and actual database structure due to inconsistencies in >+ database revisions. It reduces the noise from missing column comments >+ when running script update_dbix_class_files.pl. >+ >+ The script is just a wrapper around the module Koha::Database::Commenter. >+ A test script is provided in t/db_dependent/Koha/Database/Commenter.t. >+ >+ The flags -clear, -reset and -renumber are mutually exclusive. Clear ignores >+ the other two, reset ignores renumber. >+ >+ The renumber option has been helpful in verifying that the alter table >+ operations work on the complete Koha database. It is not recommended to run >+ it in production (obviously). >+ >+=head1 AUTHOR >+ >+ Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands >+ >+=cut >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 32334
:
144391
|
144392
|
144393
|
144394
|
146712
|
146713
|
146714
|
146715
|
146716
|
146717
|
146718
|
146719
|
146720
|
148266
|
148299
|
148335
|
148338
|
148339
|
148340
|
148341
|
148342
|
148343
|
148344
|
148345
|
148346
|
148347
|
148348
|
149259
|
149260
|
149261
|
149262
|
149263
|
149264
|
149265
|
149266
|
149267
|
149268
|
149269
|
149270