summaryrefslogtreecommitdiffstats
path: root/kittystore
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2012-11-26 15:49:55 +0100
committerAurélien Bompard <aurelien@bompard.org>2012-11-26 15:53:52 +0100
commit35204016d043c9d2623f163ba7b7f37d6da207ab (patch)
treeec1763984b51ae4618eaaa6523c83d02fa5b8cbc /kittystore
parentc16f2bcd2da789d36383c064a5cfbebb0cf8d099 (diff)
downloadkittystore-35204016d043c9d2623f163ba7b7f37d6da207ab.tar.gz
kittystore-35204016d043c9d2623f163ba7b7f37d6da207ab.tar.xz
kittystore-35204016d043c9d2623f163ba7b7f37d6da207ab.zip
Add a script to manually update the DB schema
Diffstat (limited to 'kittystore')
-rw-r--r--kittystore/scripts.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/kittystore/scripts.py b/kittystore/scripts.py
new file mode 100644
index 0000000..d882d9a
--- /dev/null
+++ b/kittystore/scripts.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2011-2012 by the Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+"""
+Various utility scripts.
+
+Author: Aurelien Bompard <abompard@fedoraproject.org>
+"""
+
+
+from optparse import OptionParser
+
+from kittystore import get_store
+
+
+def updatedb():
+ parser = OptionParser(usage="%prog -s store_url")
+ parser.add_option("-s", "--store", help="the URL to the store database")
+ parser.add_option("-d", "--debug", action="store_true",
+ help="show SQL queries")
+ opts, args = parser.parse_args()
+ if opts.store is None:
+ parser.error("the store URL is missing (eg: "
+ "sqlite:///kittystore.sqlite).")
+ if args:
+ parser.error("no arguments allowed.")
+ print 'Upgrading the database schema if necessary...'
+ store = get_store(opts.store, debug=opts.debug)
+ version = list(store.db.execute(
+ "SELECT patch.version FROM patch "
+ "ORDER BY version DESC LIMIT 1"
+ ))[0][0]
+ print "Done, the current schema version is %d." % version