|
@@ -1,60 +0,0 @@
|
|
|
-#!@PYTHON@
|
|
|
-
|
|
|
-# Copyright (C) 2011 Internet Systems Consortium.
|
|
|
-#
|
|
|
-# Permission to use, copy, modify, and distribute this software for any
|
|
|
-# purpose with or without fee is hereby granted, provided that the above
|
|
|
-# copyright notice and this permission notice appear in all copies.
|
|
|
-#
|
|
|
-# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
|
|
|
-# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
|
|
|
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
|
|
|
-# INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
-# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
|
|
-# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
-# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
|
|
-# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
-
|
|
|
-import os, sqlite3, sys
|
|
|
-from optparse import OptionParser
|
|
|
-
|
|
|
-usage = 'usage: %prog [options] db_file'
|
|
|
-parser = OptionParser(usage=usage)
|
|
|
-parser.add_option("-u", "--upgrade", action="store_true",
|
|
|
- dest="upgrade", default=False,
|
|
|
- help="Upgrade the database file [default: %default]")
|
|
|
-(options, args) = parser.parse_args()
|
|
|
-if len(args) == 0:
|
|
|
- parser.error('missing argument')
|
|
|
-
|
|
|
-db_file = args[0]
|
|
|
-
|
|
|
-# If the file doesn't exist, there's nothing to do
|
|
|
-if not os.path.exists(db_file):
|
|
|
- sys.exit(0)
|
|
|
-
|
|
|
-conn = sqlite3.connect(db_file)
|
|
|
-cur = conn.cursor()
|
|
|
-try:
|
|
|
- # This can be anything that works iff the "diffs" table exists
|
|
|
- cur.execute('SELECT name FROM diffs DESC LIMIT 1')
|
|
|
-except sqlite3.OperationalError as ex:
|
|
|
- # If it fails with 'no such table', create a new one or fail with
|
|
|
- # warning depending on the --upgrade command line option.
|
|
|
- if str(ex) == 'no such table: diffs':
|
|
|
- if options.upgrade:
|
|
|
- cur.execute('CREATE TABLE diffs (id INTEGER PRIMARY KEY, ' +
|
|
|
- 'zone_id INTEGER NOT NULL, ' +
|
|
|
- 'version INTEGER NOT NULL, ' +
|
|
|
- 'operation INTEGER NOT NULL, ' +
|
|
|
- 'name TEXT NOT NULL COLLATE NOCASE, ' +
|
|
|
- 'rrtype TEXT NOT NULL COLLATE NOCASE, ' +
|
|
|
- 'ttl INTEGER NOT NULL, rdata TEXT NOT NULL)')
|
|
|
- else:
|
|
|
- sys.stdout.write('Found an older version of SQLite3 DB file: ' +
|
|
|
- db_file + '\n' + "Perform '" + os.getcwd() +
|
|
|
- "/sqlite3-difftbl-check.py --upgrade " +
|
|
|
- db_file + "'\n" +
|
|
|
- 'before continuing install.\n')
|
|
|
- sys.exit(1)
|
|
|
-conn.close()
|