1010from protos import objects
1111from protos .objects import Listings , Followers , Following
1212from os .path import join
13- from db .migrations import migration1 , migration2 , migration3 , migration4 , migration5
13+ from db .migrations import migration1 , migration2 , migration3 , migration4 , migration5 , migration6
1414
1515
1616class Database (object ):
@@ -116,7 +116,7 @@ def _create_database(database_path):
116116 conn = lite .connect (database_path )
117117 cursor = conn .cursor ()
118118
119- cursor .execute ('''PRAGMA user_version = 5 ''' )
119+ cursor .execute ('''PRAGMA user_version = 6 ''' )
120120 cursor .execute ('''CREATE TABLE hashmap(hash TEXT PRIMARY KEY, filepath TEXT)''' )
121121
122122 cursor .execute ('''CREATE TABLE profile(id INTEGER PRIMARY KEY, serializedUserInfo BLOB, tempHandle TEXT)''' )
@@ -152,15 +152,15 @@ def _create_database(database_path):
152152
153153 cursor .execute ('''CREATE TABLE purchases(id TEXT PRIMARY KEY, title TEXT, description TEXT,
154154 timestamp INTEGER, btc FLOAT, address TEXT, status INTEGER, outpoint BLOB, thumbnail BLOB, vendor TEXT,
155- proofSig BLOB, contractType TEXT, unread INTEGER)''' )
155+ proofSig BLOB, contractType TEXT, unread INTEGER, statusChanged INTEGER )''' )
156156
157157 cursor .execute ('''CREATE TABLE sales(id TEXT PRIMARY KEY, title TEXT, description TEXT,
158158 timestamp INTEGER, btc REAL, address TEXT, status INTEGER, thumbnail BLOB, outpoint BLOB, buyer TEXT,
159- paymentTX TEXT, contractType TEXT, unread INTEGER)''' )
159+ paymentTX TEXT, contractType TEXT, unread INTEGER, statusChanged INTEGER )''' )
160160
161161 cursor .execute ('''CREATE TABLE cases(id TEXT PRIMARY KEY, title TEXT, timestamp INTEGER, orderDate TEXT,
162162 btc REAL, thumbnail BLOB, buyer TEXT, vendor TEXT, validation TEXT, claim TEXT, status INTEGER,
163- unread INTEGER)''' )
163+ unread INTEGER, statusChanged INTEGER )''' )
164164
165165 cursor .execute ('''CREATE TABLE ratings(listing TEXT, ratingID TEXT, rating TEXT)''' )
166166 cursor .execute ('''CREATE INDEX index_listing ON ratings(listing);''' )
@@ -204,6 +204,9 @@ def _run_migrations(self):
204204 migration5 .migrate (self .PATH )
205205 elif version == 4 :
206206 migration5 .migrate (self .PATH )
207+ migration6 .migrate (self .PATH )
208+ elif version == 5 :
209+ migration6 .migrate (self .PATH )
207210
208211
209212class HashMap (object ):
@@ -927,7 +930,7 @@ def get_all(self):
927930 conn = Database .connect_database (self .PATH )
928931 cursor = conn .cursor ()
929932 cursor .execute ('''SELECT id, title, description, timestamp, btc, status,
930- thumbnail, vendor, contractType, unread FROM purchases ''' )
933+ thumbnail, vendor, contractType, unread, statusChanged FROM purchases ''' )
931934 ret = cursor .fetchall ()
932935 conn .close ()
933936 return ret
@@ -948,6 +951,14 @@ def update_status(self, order_id, status):
948951 conn .commit ()
949952 conn .close ()
950953
954+ def status_changed (self , order_id , status ):
955+ conn = Database .connect_database (self .PATH )
956+ with conn :
957+ cursor = conn .cursor ()
958+ cursor .execute ('''UPDATE purchases SET statusChanged=? WHERE id=?;''' , (status , order_id ))
959+ conn .commit ()
960+ conn .close ()
961+
951962 def get_status (self , order_id ):
952963 conn = Database .connect_database (self .PATH )
953964 cursor = conn .cursor ()
@@ -1048,7 +1059,7 @@ def get_all(self):
10481059 conn = Database .connect_database (self .PATH )
10491060 cursor = conn .cursor ()
10501061 cursor .execute ('''SELECT id, title, description, timestamp, btc, status,
1051- thumbnail, buyer, contractType, unread FROM sales ''' )
1062+ thumbnail, buyer, contractType, unread, statusChanged FROM sales ''' )
10521063 ret = cursor .fetchall ()
10531064 conn .close ()
10541065 return ret
@@ -1069,6 +1080,14 @@ def update_status(self, order_id, status):
10691080 conn .commit ()
10701081 conn .close ()
10711082
1083+ def status_changed (self , order_id , status ):
1084+ conn = Database .connect_database (self .PATH )
1085+ with conn :
1086+ cursor = conn .cursor ()
1087+ cursor .execute ('''UPDATE sales SET statusChanged=? WHERE id=?;''' , (status , order_id ))
1088+ conn .commit ()
1089+ conn .close ()
1090+
10721091 def get_status (self , order_id ):
10731092 conn = Database .connect_database (self .PATH )
10741093 cursor = conn .cursor ()
@@ -1154,7 +1173,7 @@ def get_all(self):
11541173 conn = Database .connect_database (self .PATH )
11551174 cursor = conn .cursor ()
11561175 cursor .execute ('''SELECT id, title, timestamp, orderDate, btc, thumbnail,
1157- buyer, vendor, validation, claim, status, unread FROM cases ''' )
1176+ buyer, vendor, validation, claim, status, unread, statusChanged FROM cases ''' )
11581177 ret = cursor .fetchall ()
11591178 conn .close ()
11601179 return ret
@@ -1189,6 +1208,14 @@ def update_status(self, order_id, status):
11891208 conn .commit ()
11901209 conn .close ()
11911210
1211+ def status_changed (self , order_id , status ):
1212+ conn = Database .connect_database (self .PATH )
1213+ with conn :
1214+ cursor = conn .cursor ()
1215+ cursor .execute ('''UPDATE cases SET statusChanged=? WHERE id=?;''' , (status , order_id ))
1216+ conn .commit ()
1217+ conn .close ()
1218+
11921219
11931220class Ratings (object ):
11941221 """
0 commit comments