]> rtime.felk.cvut.cz Git - coffee/coffee-flask.git/commitdiff
Rename DB field identifiers.status to identifiers.active
authorMichal Sojka <michal.sojka@cvut.cz>
Sun, 18 Aug 2019 20:19:31 +0000 (22:19 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Sun, 18 Aug 2019 20:19:31 +0000 (22:19 +0200)
This better reflects what is the meaning of the value.

If you need to manually create the table, use the following command,
not the one from the previous commit.

    CREATE TABLE if not exists identifiers (
        `userid` varchar ( 24 ) NOT NULL,
        `id` varchar ( 24 ) PRIMARY KEY NOT NULL,
        `name` varchar ( 24 ),
        `active` INTEGER NOT NULL DEFAULT 1,
        FOREIGN KEY(`userid`) REFERENCES `users`(`id`)
    );

coffee_db.py
coffee_db.sql

index 5c41d5132b70dc568d087baababe5c431d8374db..072fe92f19e937bd30158c1b22db5013d8d7b0fc 100644 (file)
@@ -32,11 +32,11 @@ def add_user_identifier(uid, iid, name):
 
         # Try to remove old relation of identifier
         # As 'delete or ignore' does not exist, workaround is used
-        res = c.execute("select * from identifiers where id = ? and status = ?", (iid, 0, ))
+        res = c.execute("select * from identifiers where id = ? and active = ?", (iid, 0, ))
 
         # This is True when some rows were found before; delete old relation
         if res.fetchone():
-            res = c.execute("delete from identifiers where id = ? and status = ?", (iid, 0, ))
+            res = c.execute("delete from identifiers where id = ? and active = ?", (iid, 0, ))
 
         # Add new relation
         res = c.execute("insert into identifiers (userid, id, name) values (?, ?, ?)", (uid, iid, name, ))
@@ -45,7 +45,7 @@ def add_user_identifier(uid, iid, name):
 
 def disable_user_identifier(uid, iid):
     conn, c = open_db()
-    c.execute("update identifiers set status = ? where userid = ? and id = ?", (0, uid, iid, ))
+    c.execute("update identifiers set active = ? where userid = ? and id = ?", (0, uid, iid, ))
     close_db(conn)
 
 def get_name(uid):
@@ -59,7 +59,7 @@ def get_name(uid):
 def get_uid(iid):
     conn, c = open_db()
     res = list(c.execute("""
-            select userid from identifiers where id = ? and status
+            select userid from identifiers where id = ? and active
             """, (iid,)))
     close_db(conn)
 
@@ -84,7 +84,7 @@ def list_users():
 def list_user_identifiers(uid):
     conn, c = open_db()
     res = list(c.execute("""
-            select * from identifiers where userid = ? and status
+            select * from identifiers where userid = ? and active
             """, (uid,)))
     close_db(conn)
     return res
@@ -124,10 +124,10 @@ def coffee_flavors(uid=None, days=0, start=0):
         query += " where date(time) between date('now', 'localtime', '-"+ str(days+start-1) +" days') and date('now', 'localtime', '-"+ str(start) +" days')"
 
         if uid is not None:
-            query += " and ids.userid = ? and ids.status"
+            query += " and ids.userid = ? and ids.active"
             variables.append(uid)
     elif uid is not None:
-        query += " where ids.userid = ? and ids.status"
+        query += " where ids.userid = ? and ids.active"
         variables.append(uid)
 
     res = list(c.execute("""
@@ -158,7 +158,7 @@ def coffee_history(uid=None):
             select strftime('%s', ds.d),count(c.flavor),c.flavor from
             (select num,date('now', 'localtime', -num || ' days') as d from days) ds
             left join
-            (select date(time, 'localtime') as time,flavor from coffees co left join identifiers ids on co.id = ids.id where ids.userid = ? and ids.status) c
+            (select date(time, 'localtime') as time,flavor from coffees co left join identifiers ids on co.id = ids.id where ids.userid = ? and ids.active) c
             on d = date(c.time) group by d, c.flavor
             """
             , (uid,)))
@@ -173,7 +173,7 @@ def drink_count(uid=None, start=None, stop=None):
     clauses = []
 
     if uid is not None:
-        clauses.append("ids.userid = ? and ids.status")
+        clauses.append("ids.userid = ? and ids.active")
         args.append(uid)
 
     if start is not None:
index c7c88d1ce29e599f401213691e87457f01f4ac68..5c65d11245b05469d8943899fba4b48bdc7fb2cc 100644 (file)
@@ -40,6 +40,6 @@ CREATE TABLE if not exists identifiers (
     `userid` varchar ( 24 ) NOT NULL,
     `id` varchar ( 24 ) PRIMARY KEY NOT NULL,
     `name` varchar ( 24 ),
-    `status` INTEGER NOT NULL DEFAULT 1,
+    `active` INTEGER NOT NULL DEFAULT 1,
     FOREIGN KEY(`userid`) REFERENCES `users`(`id`)
 );