improved docs for mig-stagebibs
[migration-tools.git] / mig-bin / mig-env
index eddfc27..dceec4f 100755 (executable)
@@ -13,6 +13,8 @@ B<mig-env> <create|use> <migration_schema>
 
 B<mig-env> <show> [migration_schema]
 
+B<mig-env> <clone> [orig_migration_schema] [new_migration_schema]
+
 B<mig-env> <list>
 
 B<mig-env> <help>
@@ -55,7 +57,7 @@ The name of the actual database containing the migration schema.
 
 This script may also setup a symlink from a specified Git repository to a
 scripts/ directory within the migration work directory.  The default for this is
-~/git/migration-work/past_migrations/MIGSCHEMA --> MIGWORKDIR/scripts
+~/git/migration-work/MIGSCHEMA --> MIGWORKDIR/scripts
 
 It may also create the migration work directory if necessary.
 
@@ -81,6 +83,12 @@ This command will show the contents of the corresponding ~/.mig/<schema>.env
 script, or, if no schema is specified, then it will list pertinent variables in
 the current environment if they exist.
 
+=item B<clone> [orig schema] [new schema]
+
+This command will create a "shallow" clone of the orig schema, in that it will
+share database credentials as well as git and data directories, but will have a
+separate schema name.
+
 =item B<list>
 
 This command will list migration schemas found in ~/.mig
@@ -123,6 +131,12 @@ switch($ARGV[0]) {
         pod2usage(-verbose => 1) if ! $ARGV[1];
         mig_env_create();
     }
+    case "clone" {
+        pod2usage(-verbose => 1) if ! $ARGV[2];
+        $migration_schema = $ARGV[2] || '';
+        $filename = "$HOME/.mig/$migration_schema.env";
+        mig_env_clone();
+    }
     case "use" {
         pod2usage(-verbose => 1) if ! $ARGV[1];
         if (-e $filename) {
@@ -172,7 +186,7 @@ sub mig_env_create {
         $MIGWORKDIR = $migworkdir_default;
     }
     $MIGBASEGITDIR = "$HOME/git/migration-work/" unless $MIGBASEGITDIR;
-    my $miggitdir_default = "${MIGBASEGITDIR}past_migrations/$migration_schema/";
+    my $miggitdir_default = "${MIGBASEGITDIR}/$migration_schema/";
     print "git repo for migration-specific scripts (default $miggitdir_default): ";
     my $MIGGITDIR = <STDIN>;
     chomp $MIGGITDIR;
@@ -227,6 +241,7 @@ sub mig_env_create {
     print FILE "export PGPORT=$PGPORT\n";
     print FILE "export PGDATABASE=$PGDATABASE\n";
     print FILE "export PGUSER=$PGUSER\n";
+    print FILE "export PGOPTIONS='-c search_path=$migration_schema,public,evergreen'\n";
     print FILE "export MIGENVPROMPT=$migration_schema\n";
     print FILE "export MIGSCHEMA=$migration_schema\n";
     print FILE "export MIGBASEWORKDIR=$MIGBASEWORKDIR\n";
@@ -242,3 +257,12 @@ sub mig_env_create {
     close FILE;
 }
 
+sub mig_env_clone {
+    my $orig_migration_schema = $ARGV[1] || '';
+    my $orig_filename = "$HOME/.mig/$orig_migration_schema.env";
+    `cp $orig_filename $filename`;
+    `sed -i 's/export PGOPTIONS=.*/export PGOPTIONS='"'"'-c search_path=$migration_schema,public,evergreen'"'"'/' $filename`;
+    `sed -i 's/export MIGENVPROMPT=.*/export MIGENVPROMPT=$migration_schema/' $filename`;
+    `sed -i 's/export MIGSCHEMA=.*/export MIGSCHEMA=$migration_schema/' $filename`;
+}
+