scripts/skytools_upgrade.py: added "dry run" option and updated manual page
authormartinko <gamato@users.sf.net>
Thu, 26 Jul 2012 10:20:30 +0000 (12:20 +0200)
committermartinko <gamato@users.sf.net>
Thu, 26 Jul 2012 10:20:30 +0000 (12:20 +0200)
--not-really::  Don't actually do anything.

doc/skytools_upgrade.txt
scripts/skytools_upgrade.py

index 3189cb78eae43161064f935943123fe3913afc21..91dda01e7feb1cae6f1fa099b730ba105962442e 100644 (file)
@@ -6,7 +6,7 @@ skytools_upgrade - utility for upgrading Skytools code in databases.
 
 == SYNOPSIS ==
 
-  skytools_upgrade.py connstr [connstr ..]
+  skytools_upgrade.py [switches] connstr [connstr ...]
 
 == DESCRIPTION ==
 
@@ -20,14 +20,21 @@ It connects to given database, then looks for following schemas:
     Londiste replication.
 
 If schema exists, its version is detected by querying .version()
-function under schema.   If the function does not exists, there
-is some heiristics built in to differentiate between 2.1.4 and
-2.1.5 version of ther schemas.
+function under schema.  If the function does not exists, there
+is some heuristics built in to differentiate between 2.1.4 and
+2.1.5 version of the schemas.
 
-If detected that version is older that current, it is upgraded
+If detected that version is older than current, it is upgraded
 by applying upgrade scripts in order.
 
 == COMMAND LINE SWITCHES ==
 
 include::common.switches.txt[]
 
+Options specific to skytools_upgrade:
+
+--all::
+  Upgrade all databases.
+
+--not-really::
+  Don't actually do anything.
index 5a1cefe400af56cf83799d605c62244f99e67497..f509b93c34bd70729720fb7967627ab512c16105 100755 (executable)
@@ -80,6 +80,10 @@ class DbUpgrade(skytools.DBScript):
                 ignore[schema] = 1
                 continue
 
+            if self.options.not_really:
+                self.log.info ("%s: Would upgrade '%s' version %s to %s", dbname, schema, oldver, ver)
+                continue
+
             curs = db.cursor()
             curs.execute('begin')
             self.log.info("%s: Upgrading '%s' version %s to %s", dbname, schema, oldver, ver)
@@ -90,7 +94,7 @@ class DbUpgrade(skytools.DBScript):
         """Loop over databases."""
 
         self.set_single_loop(1)
-        
+
         self.load_cur_versions()
 
         # loop over all dbs
@@ -152,11 +156,13 @@ class DbUpgrade(skytools.DBScript):
         return self.get_database('db', connstr = cstr, autocommit = 1)
 
     def init_optparse(self, parser=None):
-        """Setup commend-line flags."""
+        """Setup command-line flags."""
         p = skytools.DBScript.init_optparse(self, parser)
         p.set_usage(usage)
         g = optparse.OptionGroup(p, "options for skytools_upgrade")
         g.add_option("--all", action="store_true", help = 'upgrade all databases')
+        g.add_option("--not-really", action = "store_true", dest = "not_really",
+                     default = False, help = "don't actually do anything")
         g.add_option("--user", help = 'username to use')
         g.add_option("--host", help = 'hostname to use')
         g.add_option("--port", help = 'port to use')
@@ -171,4 +177,3 @@ class DbUpgrade(skytools.DBScript):
 if __name__ == '__main__':
     script = DbUpgrade('skytools_upgrade', sys.argv[1:])
     script.start()
-