head	1.1;
access;
symbols;
locks; strict;
comment	@# @;


1.1
date	2001.06.28.00.35.14;	author ms;	state Exp;
branches;
next	;


desc
@@


1.1
log
@Factored out the migrate scripts in each migration path into master migrate.
upgrade_tigris calls migrate which in turn does the proper actions for the migration path to upgrade.
Added ScriptOrder.lst to each migration path which lists scripts to run, takes relative or full paths.
migrateIZ is the script I wasnt easily able to factor away from the old classic-1.0.0/migrate script so it gets called in the ScriptOrder.lst.
@
text
@#!/usr/bin/perl -w

##
# this script runs the sql and scripts for a given upgrade path.
# it is called from upgrade_tigris.
# $Id$
##

use strict;

die "No migration basedir passed to migrate script, cannot continue"
    unless (scalar @@ARGV == 1);
my $dir = shift;

my $mysql_cmd = "mysql -u$ENV{DATABASE_USER} -p$ENV{DATABASE_PASSWORD} " .
                "-h$ENV{DATABASE_HOST}"; 

my $SQL_list    = $_ if (-e ($_ = "$dir/LoadOrder.lst"));
my $IZ_list     = $_ if (-e ($_ = "$dir/LoadOrderIZ.lst"));
my $script_list = $_ if (-e ($_ = "$dir/ScriptOrder.lst"));

&runFile ($SQL_list, $ENV{DATABASE_NAME});

&runFile ($IZ_list, $ENV{IZ_DATABASE_NAME});

&runFile ($script_list, '');

sub runFile
{
    my ($file, $db) = @@_;
    print "Running $file\n";
    open FILE, $file or die "Can't open $file: $!\n";
    while(<FILE>)
    {
        if ($db ne '')  # running SQL
        {
            print "Running $_ against $db\n";
            `$mysql_cmd $db < $dir/$_`;
        }
        else
        {
            my $script = $_;
            # construct full path if not given one in the file
            if (index ($script, "/") != 0)
            {
                $script = "$dir/$_";
            }
            print "Running script $script\n";
     
            if (/^\s*?#/)  # print comments in file
            {     
                print;
                next;
            }
            print "$script exited with error: $?\n" if (system ($script) != 0 );
        }
    }
    close FILE; # done
}
@
