2 ###############################################################################
7 mig-init - This will add or recreate tracking tables for the B<mig> toolset
8 to the database specified by the current mig environment.
10 In practice, you should invoke 'mig env use schema_name' prior to calling
21 ###############################################################################
26 HOME MYSQL_HOST MYSQL_TCP_PORT MYSQL_USER MYSQL_DATABASE MYSQL_PW
27 MIGSCHEMA MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
32 my $mig_bin = "$FindBin::Bin/";
33 my $mig_sql = $mig_bin . "../sql/init/";
34 use lib "$FindBin::Bin/";
37 pod2usage(-verbose => 2) if $ARGV[0];
39 KMig::die_if_no_env_migschema();
41 if (! KMig::check_for_db_migschema()) {
42 die "could not find the schema";
45 KMig::die_if_mig_tracking_table_exists();
46 KMig::die_if_mig_column_tracking_table_exists();
47 loop_through_mig_sql_templates();
51 ###############################################################################
53 sub loop_through_mig_sql_templates {
54 print "Looping through mig.d/sql/init/ templates\n";
55 opendir my $dir, $mig_sql or die "Cannot open directory: $!";
56 my @files = sort readdir $dir;
58 foreach my $file (@files) {
59 if ($file =~ /.sql$/) {
60 print "executing $file:\n";
61 system( $mig_bin . "mig-sql", ('-e',"source $mig_sql$file") )