<<

NAME

Koha::Database::Commenter - Manage column comments in database

SYNOPSIS

    use Koha::Database::Commenter;
    $mgr = Koha::Database::Commenter->new({ dbh => $dbh });

    $mgr->reset_to_schema;
    # OR:
    $mgr->clear;

DESCRIPTION

    This object helps you to keep column comments in your database in sync
    with the Koha schema. It also allows you to clear all comments.

    The advantage of keeping in sync is that you can easily track differences
    between schema and database with the maintenance script
    update_dbix_class_files.pl.

    Tip: make a backup of your database before running this script.

METHODS

new

    $mgr = Koha::Database::Commenter->new({
        dbh => $dbh, database => $d, schema_file => $s
    });

    Object constructor.
    Param dbh is mandatory. Params database and schema_file are
    optional.
    Param database can be used to move away from current database of
    db handle.
    Param schema_file is needed for resetting to schema. Falls back to
    the constant for Koha structure file.

clear

    $object->clear({ dry_run => 0, table => $table }, $messages );

    Clears all current column comments in storage.
    If table is passed, only that table is changed.
    Dry run only returns sql statements in $messages (arrayref).

reset_to_schema

    $object->reset_to_schema({ dry_run => 0, table => $table }, $messages );

    Resets column comments in storage to schema definition.
    Other column comments are cleared.
    When you pass table, only that table is changed.
    Dry run only returns sql statements in $messages (arrayref).

renumber

    $object->renumber({ dry_run => 0, table => $table }, $messages );

    This is primarily meant for testing purposes (verifying results across
    whole database).
    It adds comments like Comment_1, Comment_2 etc.
    When you pass table, only that table is changed. Otherwise all tables
    are affected; note that the column counter does not reset by table.
    Dry run only returns sql statements in $messages (arrayref).

INTERNAL ROUTINES

_find_schema

_fetch_schema_comments

_fetch_stored_comments

_change_column

ADDITIONAL COMMENTS

    The module contains the core code for the options of the maintenance
    script sync_db_comments.pl.

    It can be tested additionally with Commenter.t, but note that since
    SQL DDL statements - as generated by this module - implicitly commit,
    we are not modifying actual Koha tables in that test.

AUTHOR

    Marcel de Rooy, Rijksmuseum Amsterdam, The Netherlands

<<