@@ -80,7 +80,8 @@ def _stalk_set_buy_price(cmd, price):
80
80
week_local , _ , expiration = _user_time_info (user_time )
81
81
with db :
82
82
db .execute ('''
83
- INSERT INTO sell_price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
83
+ INSERT INTO price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
84
+ ON CONFLICT(user_id, expiration) DO UPDATE SET price = excluded.price
84
85
''' , (user_id , week_local , 0 , expiration .astimezone (datetime .timezone .utc ), value ))
85
86
86
87
expires_in = readable_rel (expiration - user_time )
@@ -91,7 +92,7 @@ def _stalk_list_buy_prices(cmd):
91
92
current_time = datetime .datetime .now (datetime .timezone .utc )
92
93
sunday = _date_to_sunday (current_time )
93
94
cur = db .execute ('''
94
- SELECT username, expiration, price FROM sell_price
95
+ SELECT username, expiration, price FROM price
95
96
JOIN user ON user_id = user.id
96
97
WHERE week_local = ? AND week_index = 0
97
98
''' , (str (sunday ),))
@@ -157,17 +158,17 @@ def _stalk_set_sell_price(cmd, price):
157
158
week_local , week_index , expiration = _user_time_info (user_time )
158
159
with db :
159
160
db .execute ('''
160
- INSERT INTO sell_price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
161
+ INSERT INTO price (user_id, week_local, week_index, expiration, price) VALUES (?, ?, ?, ?, ?)
161
162
ON CONFLICT(user_id, expiration) DO UPDATE SET price = excluded.price
162
163
''' , (user_id , week_local , week_index , expiration .astimezone (datetime .timezone .utc ), value ))
163
164
164
165
sunday = _date_to_sunday (current_time )
165
166
with db :
166
- cur = db .execute ('SELECT week_index, price FROM sell_price WHERE user_id = ? AND week_local = ?' ,
167
+ cur = db .execute ('SELECT week_index, price FROM price WHERE user_id = ? AND week_local = ?' ,
167
168
(user_id , str (sunday ),))
168
- week_rows = cur .fetchall ()
169
+ week_price_rows = cur .fetchall ()
169
170
week_prices = [None ] * 13
170
- for row in week_rows :
171
+ for row in week_price_rows :
171
172
week_prices [row ['week_index' ]] = row ['price' ]
172
173
173
174
expires_in = readable_rel (expiration - user_time )
@@ -193,7 +194,7 @@ def _stalk_list_sale_prices(cmd):
193
194
sunday = _date_to_sunday (current_time )
194
195
cur = db .execute ('''
195
196
SELECT username, week_index, expiration, price
196
- FROM sell_price
197
+ FROM price
197
198
JOIN user ON user_id = user.id
198
199
WHERE week_local == ?
199
200
''' , (str (sunday ),))
@@ -291,8 +292,8 @@ def _turnip_prophet(week_prices):
291
292
292
293
def migrate (dry_run ):
293
294
with db :
294
- cur = db .execute ('''SELECT user_id, expiration, price, timezone FROM sell_price
295
- JOIN user ON sell_price .user_id = user.id''' )
295
+ cur = db .execute ('''SELECT user_id, expiration, price, timezone FROM price
296
+ JOIN user ON price .user_id = user.id''' )
296
297
rows = cur .fetchall ()
297
298
print ('migrating' , len (rows ), 'rows; dry-run:' , dry_run )
298
299
if not dry_run :
0 commit comments