5 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
17 HOME MYSQL_HOST MYSQL_TCP_PORT MYSQL_USER MYSQL_DATABASE MYSQL_PW
18 MIGSCHEMA MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
25 "dbi:mysql:host=$MYSQL_HOST;dbname=$MYSQL_DATABASE;port=$MYSQL_TCP_PORT"
28 ) || die "Unable to connect to $MYSQL_HOST:$MYSQL_TCP_PORT:$MYSQL_DATABASE:$MYSQL_USER : $!\n";
30 $dbh = DBI->connect("dbi:Pg:dbname=$MYSQL_DATABASE", "", "") || die "Unable to connect to $MYSQL_DATABASE : $!\n";
48 sub die_if_no_env_migschema {
49 die "MIGSCHEMA environment variable not set. See 'mig env help'\n"
53 sub check_for_db_migschema {
54 # the schema is the same as the database name, which is the same
55 # as the koha instance name prefixed with 'koha_', in most cases
59 sub check_db_migschema_for_migration_tables {
60 my $found = check_db_migschema_for_specific_table('m_borrowers');
62 print "Missing migration tables (such as m_borrowers)\n";
67 sub check_db_migschema_for_specific_table {
69 my $dbh = db_connect();
70 my $sth = $dbh->prepare("
73 FROM information_schema.tables
74 WHERE table_schema = " . $dbh->quote( $MYSQL_DATABASE ) . "
75 AND table_name = " . $dbh->quote( $table ) . "
78 my $rv = $sth->execute()
79 || die "Error checking migration schema ($MIGSCHEMA) for table ($table): $!";
80 my @cols = $sth->fetchrow_array;
92 sub check_for_mig_tracking_table {
93 my $dbh = db_connect();
94 my $sth = $dbh->prepare("
97 FROM information_schema.tables
98 WHERE table_schema = " . $dbh->quote( $MYSQL_DATABASE ) . "
99 AND table_name = 'm_tracked_file'
102 my $rv = $sth->execute()
103 || die "Error checking for table (m_tracked_file): $!";
104 my @cols = $sth->fetchrow_array;
110 sub die_if_mig_tracking_table_exists {
111 if (check_for_mig_tracking_table()) {
112 die "Table m_tracked_file already exists. Bailing init...\n";
116 sub die_if_mig_tracking_table_does_not_exist {
117 if (!check_for_mig_tracking_table()) {
118 die "Table m_tracked_file does not exist. Bailing...\n";
122 sub check_for_mig_column_tracking_table {
123 my $dbh = db_connect();
124 my $sth = $dbh->prepare("
127 FROM information_schema.tables
128 WHERE table_schema = " . $dbh->quote( $MYSQL_DATABASE ) . "
129 AND table_name = 'm_tracked_column'
132 my $rv = $sth->execute()
133 || die "Error checking for table (m_tracked_column): $!";
134 my @cols = $sth->fetchrow_array;
140 sub die_if_mig_column_tracking_table_exists {
141 if (check_for_mig_column_tracking_table()) {
142 die "Table m_tracked_column already exists. Bailing init...\n";
146 sub die_if_mig_column_tracking_table_does_not_exist {
147 if (!check_for_mig_column_tracking_table()) {
148 die "Table m_tracked_column does not exist. Bailing...\n";
152 sub check_for_tracked_file {
156 die "file not found: $file\n" unless $options && $options->{'allow_missing'};
158 my $dbh = db_connect();
159 my $sth = $dbh->prepare("
162 WHERE base_filename = " . $dbh->quote( $file ) . ";"
164 my $rv = $sth->execute()
165 || die "Error checking table (m_tracked_file) for base_filename ($file): $!";
166 my @cols = $sth->fetchrow_array;
172 sub check_for_tracked_column {
173 my ($table,$column,$options) = (shift,shift,shift);
174 my $dbh = db_connect();
175 my $sth = $dbh->prepare("
177 FROM m_tracked_column
178 WHERE staged_table = " . $dbh->quote( $table ) . "
179 AND staged_column = " . $dbh->quote( $column ) . ";"
181 my $rv = $sth->execute()
182 || die "Error checking table (m_tracked_column) for $table.$column: $!";
183 my @cols = $sth->fetchrow_array;
189 sub status_this_file {
191 my $dbh = db_connect();
192 my $sth = $dbh->prepare("
195 WHERE base_filename = " . $dbh->quote( $file ) . ";"
197 my $rv = $sth->execute()
198 || die "Error retrieving data from table (m_tracked_file) for base_filename ($file): $!";
199 my $data = $sth->fetchrow_hashref;
205 sub status_this_column {
206 my ($table,$column) = (shift,shift);
207 my $dbh = db_connect();
208 my $sth = $dbh->prepare("
210 FROM m_tracked_column
211 WHERE staged_table = " . $dbh->quote( $table ) . "
212 AND staged_column = " . $dbh->quote( $column ) . ";"
214 my $rv = $sth->execute()
215 || die "Error checking table (m_tracked_column) for $table.$column: $!";
216 my $data = $sth->fetchrow_hashref;