Mercurial > hg > fapweb
diff createdb.php @ 525:d7302b3a479e
Change database tool commandline a bit.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Dec 2013 17:45:42 +0200 |
parents | 6aa9356ead52 |
children | d6726a4883a6 |
line wrap: on
line diff
--- a/createdb.php Mon Dec 09 21:20:31 2013 +0200 +++ b/createdb.php Tue Dec 10 17:45:42 2013 +0200 @@ -639,16 +639,16 @@ "Usage: ".$argv[0]." <mode> [args]\n". "Where mode is one of following:\n". "\n". - " new Create a new database with given PDO spec\n". + " new <dbspec> Create a new database with given PDO spec\n". " or default to the one in mconfig.inc.php\n". "\n". - " test Like new, but add initial test data.\n". + " test <dbspec> Like new, but add initial test data.\n". "\n". - " upgrade <output dbspec>\n". + " upgrade <input_dbspec> <output_dbspec>\n". " Upgrade current database, if possible.\n". " Output to new database (DO NOT USE SAME as current!)\n". "\n". - " migrate <output dbspec>\n". + " migrate <input_dbspec> <output_dbspec>\n". " Like upgrade, but no version check. Creates\n". " a copy of the database to the output spec.\n". "\n"; @@ -656,14 +656,6 @@ } -// Try to connect to database -$inSpec = stGetSetting("sqlDB"); -if (($inDB = stConnectSQLDBSpec($inSpec)) === false) - die("Could not connect to SQL database '".$inSpec."'.\n"); - -echo "Using INPUT database spec '".$inSpec."'.\n"; - - // Act according to specified command $addTestData = FALSE; switch (stCArgLC(1)) @@ -672,6 +664,16 @@ $addTestData = TRUE; case "new": + // Try to connect to database + if (($inSpec = stCArg(2)) === false) + die("No PDO database spec specified.\n"); + + if (($inDB = stConnectSQLDBSpec($inSpec)) === false) + die("Could not connect to SQL database '".$inSpec."'.\n"); + + echo "Using database spec '".$inSpec."'.\n"; + + // Create tables, add defaults if (stCreateTables($inDB, FALSE)) { stAddSettings($inDB, $inDB, $dbMeta, "dbmeta", FALSE); @@ -690,6 +692,20 @@ // // Attempt to upgrade database // + if ($argc < 4) + die("Usage: ".$argv[0]." upgrade <input_dbspec> <output_dbspec>\n"); + + $inSpec = stCArg(2); + $outSpec = stCArg(3); + + if ($outSpec == $inSpec) + die("The input and output databases CAN NOT BE SAME.\nBe VERY CAREFUL to not accidentally specify same db!\n"); + + echo "Using database spec '".$inSpec."'.\n"; + + if (($inDB = stConnectSQLDBSpec($inSpec)) === false) + die("Could not connect to SQL database '".$inSpec."'.\n"); + // Check the current version first ... if (($currVersion = stGetDBMeta($inDB, "dbVersion")) === FALSE) $currVersion = -1; @@ -701,13 +717,6 @@ else { // Okay, we shall create an upgraded version .. - if ($argc < 3) - die("Usage: ".$argv[0]." upgrade <output dbspec>\n"); - - $outSpec = stCArg(2); - if ($outSpec == $inSpec) - die("The input and output databases CAN NOT BE SAME.\n"); - if (($outDB = stConnectSQLDBSpec($outSpec)) === false) die("Could not connect to SQL database '".$outSpec."'.\n");