]> WPIA git - motion.git/blobdiff - motion.py
adding automatic schema migration mechanism
[motion.git] / motion.py
index 957bf96f9ff8a96bd8bcbb4039ddf314462ccd6a..741eb302d0d37f6cebc8f859ed8fe5d655260527 100644 (file)
--- a/motion.py
+++ b/motion.py
@@ -78,8 +78,16 @@ def close_connection(exception):
 def init_db():
     with app.app_context():
         db = get_db()
-        with app.open_resource('schema.sql', mode='r') as f:
-            db.execute(f.read())
+        try:
+            ver = db.prepare("SELECT version FROM schema_version")()[0][0];
+            print("Database Schema version: ", ver)
+        except postgresql.exceptions.UndefinedTableError:
+            ver = 0
+        if ver < 1:
+            with app.open_resource('sql/schema.sql', mode='r') as f:
+                db.execute(f.read())
+
+init_db()
 
 @app.route("/")
 def main():
@@ -147,7 +155,7 @@ def show_motion(motion):
                          + "WHERE motion.id=$1")
     rv = p(motion, g.voter)
     votes = None
-    if may("audit", rv[0].get("type")):
+    if may("audit", rv[0].get("type")) and not rv[0].get("running") and not rv[0].get("canceled"):
         votes = get_db().prepare("SELECT vote.result, voter.email FROM vote INNER JOIN voter ON voter.id = vote.voter_id WHERE vote.motion_id=$1")(motion);
     return render_template('single_motion.html', motion=rv[0], may_vote=may("vote", rv[0].get("type")), may_cancel=may("cancel", rv[0].get("type")), votes=votes)