1111from protos import objects
1212from protos .objects import Listings , Followers , Following
1313from os .path import join
14- from db .migrations import migration1 , migration2 , migration3 , migration4 , migration5 , migration6
14+ from db .migrations import migration1 , migration2 , migration3 , migration4 , migration5 , migration6 , migration7
1515
1616
1717class Database (object ):
@@ -154,15 +154,15 @@ def _create_database(database_path):
154154
155155 cursor .execute ('''CREATE TABLE purchases(id TEXT PRIMARY KEY, title TEXT, description TEXT,
156156 timestamp INTEGER, btc FLOAT, address TEXT, status INTEGER, outpoint BLOB, thumbnail BLOB, vendor TEXT,
157- proofSig BLOB, contractType TEXT, unread INTEGER)''' )
157+ proofSig BLOB, contractType TEXT, unread INTEGER, statusChanged INTEGER )''' )
158158
159159 cursor .execute ('''CREATE TABLE sales(id TEXT PRIMARY KEY, title TEXT, description TEXT,
160160 timestamp INTEGER, btc REAL, address TEXT, status INTEGER, thumbnail BLOB, outpoint BLOB, buyer TEXT,
161- paymentTX TEXT, contractType TEXT, unread INTEGER)''' )
161+ paymentTX TEXT, contractType TEXT, unread INTEGER, statusChanged INTEGER )''' )
162162
163163 cursor .execute ('''CREATE TABLE cases(id TEXT PRIMARY KEY, title TEXT, timestamp INTEGER, orderDate TEXT,
164164 btc REAL, thumbnail BLOB, buyer TEXT, vendor TEXT, validation TEXT, claim TEXT, status INTEGER,
165- unread INTEGER)''' )
165+ unread INTEGER, statusChanged INTEGER )''' )
166166
167167 cursor .execute ('''CREATE TABLE ratings(listing TEXT, ratingID TEXT, rating TEXT)''' )
168168 cursor .execute ('''CREATE INDEX index_listing ON ratings(listing);''' )
@@ -224,6 +224,9 @@ def _run_migrations(self):
224224 migration6 .migrate (self .PATH )
225225 elif version == 5 :
226226 migration6 .migrate (self .PATH )
227+ migration7 .migrate (self .PATH )
228+ elif version == 6 :
229+ migration7 .migrate (self .PATH )
227230
228231
229232class HashMap (object ):
@@ -947,7 +950,7 @@ def get_all(self):
947950 conn = Database .connect_database (self .PATH )
948951 cursor = conn .cursor ()
949952 cursor .execute ('''SELECT id, title, description, timestamp, btc, status,
950- thumbnail, vendor, contractType, unread FROM purchases ''' )
953+ thumbnail, vendor, contractType, unread, statusChanged FROM purchases ''' )
951954 ret = cursor .fetchall ()
952955 conn .close ()
953956 return ret
@@ -968,6 +971,14 @@ def update_status(self, order_id, status):
968971 conn .commit ()
969972 conn .close ()
970973
974+ def status_changed (self , order_id , status ):
975+ conn = Database .connect_database (self .PATH )
976+ with conn :
977+ cursor = conn .cursor ()
978+ cursor .execute ('''UPDATE purchases SET statusChanged=? WHERE id=?;''' , (status , order_id ))
979+ conn .commit ()
980+ conn .close ()
981+
971982 def get_status (self , order_id ):
972983 conn = Database .connect_database (self .PATH )
973984 cursor = conn .cursor ()
@@ -1068,7 +1079,7 @@ def get_all(self):
10681079 conn = Database .connect_database (self .PATH )
10691080 cursor = conn .cursor ()
10701081 cursor .execute ('''SELECT id, title, description, timestamp, btc, status,
1071- thumbnail, buyer, contractType, unread FROM sales ''' )
1082+ thumbnail, buyer, contractType, unread, statusChanged FROM sales ''' )
10721083 ret = cursor .fetchall ()
10731084 conn .close ()
10741085 return ret
@@ -1089,6 +1100,14 @@ def update_status(self, order_id, status):
10891100 conn .commit ()
10901101 conn .close ()
10911102
1103+ def status_changed (self , order_id , status ):
1104+ conn = Database .connect_database (self .PATH )
1105+ with conn :
1106+ cursor = conn .cursor ()
1107+ cursor .execute ('''UPDATE sales SET statusChanged=? WHERE id=?;''' , (status , order_id ))
1108+ conn .commit ()
1109+ conn .close ()
1110+
10921111 def get_status (self , order_id ):
10931112 conn = Database .connect_database (self .PATH )
10941113 cursor = conn .cursor ()
@@ -1174,7 +1193,7 @@ def get_all(self):
11741193 conn = Database .connect_database (self .PATH )
11751194 cursor = conn .cursor ()
11761195 cursor .execute ('''SELECT id, title, timestamp, orderDate, btc, thumbnail,
1177- buyer, vendor, validation, claim, status, unread FROM cases ''' )
1196+ buyer, vendor, validation, claim, status, unread, statusChanged FROM cases ''' )
11781197 ret = cursor .fetchall ()
11791198 conn .close ()
11801199 return ret
@@ -1209,6 +1228,14 @@ def update_status(self, order_id, status):
12091228 conn .commit ()
12101229 conn .close ()
12111230
1231+ def status_changed (self , order_id , status ):
1232+ conn = Database .connect_database (self .PATH )
1233+ with conn :
1234+ cursor = conn .cursor ()
1235+ cursor .execute ('''UPDATE cases SET statusChanged=? WHERE id=?;''' , (status , order_id ))
1236+ conn .commit ()
1237+ conn .close ()
1238+
12121239
12131240class Ratings (object ):
12141241 """
0 commit comments