history: payments hanya run terbaru, TANGGAL pindah ke judul, MEMO dihapus (DB+UI)
This commit is contained in:
1 parent
a3251eebc4
commit
344de409cd
10 files changed
+83
-41
No files matched your search
@@ -116,7 +116,6 @@ _PAY_COLS = (
|
||||
'run_id INTEGER NOT NULL, '
|
||||
'owner VARCHAR(13) NOT NULL, '
|
||||
'amount DOUBLE NOT NULL, '
|
||||
'memo TEXT NOT NULL, '
|
||||
'txid TEXT, '
|
||||
'status TEXT NOT NULL, '
|
||||
'error TEXT, '
|
||||
@@ -141,11 +140,32 @@ def ensure_distribute_schema():
|
||||
else:
|
||||
cur.execute(_RUN_DDL_MYSQL)
|
||||
cur.execute(_PAY_DDL_MYSQL)
|
||||
_drop_pay_memo(cur)
|
||||
conn.commit()
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def _drop_pay_memo(cur):
|
||||
"""Migrasi: buang kolom memo lama dari distribute_payments (idempoten).
|
||||
|
||||
Kolom `memo` pernah disimpan (V23) lalu dihapus — DB produksi yang sudah
|
||||
punya kolom perlu di-alter; DB baru langsung tanpa kolom.
|
||||
"""
|
||||
if DB_BACKEND == 'sqlite':
|
||||
cur.execute(
|
||||
"SELECT name FROM pragma_table_info('distribute_payments')")
|
||||
cols = {row[0] for row in cur.fetchall()}
|
||||
else:
|
||||
cur.execute(
|
||||
"SELECT COLUMN_NAME FROM information_schema.COLUMNS "
|
||||
"WHERE TABLE_SCHEMA = DATABASE() "
|
||||
" AND TABLE_NAME = 'distribute_payments'")
|
||||
cols = {row[0] for row in cur.fetchall()}
|
||||
if 'memo' in cols:
|
||||
cur.execute(_translate('ALTER TABLE distribute_payments DROP COLUMN memo'))
|
||||
|
||||
|
||||
def record_run(run_date, balance_start, total_voters, total_staked,
|
||||
total_sent, status, created_at):
|
||||
"""Insert baris `distribute_runs`, kembalikan run_id."""
|
||||
@@ -165,7 +185,7 @@ def record_run(run_date, balance_start, total_voters, total_staked,
|
||||
conn.close()
|
||||
|
||||
|
||||
def record_payment(run_id, owner, amount, memo, status, created_at,
|
||||
def record_payment(run_id, owner, amount, status, created_at,
|
||||
txid=None, error=None):
|
||||
"""Insert baris `distribute_payments` → payment_id."""
|
||||
ensure_distribute_schema()
|
||||
@@ -174,9 +194,9 @@ def record_payment(run_id, owner, amount, memo, status, created_at,
|
||||
cur = conn.cursor()
|
||||
cur.execute(_translate(
|
||||
'INSERT INTO distribute_payments '
|
||||
'(run_id, owner, amount, memo, txid, status, error, created_at, '
|
||||
' updated_at) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)'),
|
||||
(run_id, owner, amount, memo, txid, status, error, created_at,
|
||||
'(run_id, owner, amount, txid, status, error, created_at, '
|
||||
' updated_at) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)'),
|
||||
(run_id, owner, amount, txid, status, error, created_at,
|
||||
created_at))
|
||||
conn.commit()
|
||||
return cur.lastrowid
|
||||
@@ -224,11 +244,14 @@ def list_runs():
|
||||
'FROM distribute_runs ORDER BY run_id DESC')
|
||||
|
||||
|
||||
def list_payments():
|
||||
"""Transfer per-pemilih, terbaru dulu (gabung run untuk tanggal)."""
|
||||
def list_payments(run_id=None):
|
||||
"""Transfer per-pemilih, terbaru dulu; opsional filter satu run."""
|
||||
ensure_distribute_schema()
|
||||
return query(
|
||||
'SELECT p.payment_id, p.run_id, p.owner, p.amount, p.memo, p.txid, '
|
||||
' p.status, p.error, p.created_at, p.updated_at, r.run_date '
|
||||
'FROM distribute_payments p JOIN distribute_runs r '
|
||||
' ON p.run_id = r.run_id ORDER BY p.payment_id DESC')
|
||||
sql = ('SELECT payment_id, run_id, owner, amount, txid, status, error, '
|
||||
' created_at, updated_at FROM distribute_payments')
|
||||
params = ()
|
||||
if run_id is not None:
|
||||
sql += ' WHERE run_id = %s'
|
||||
params = (run_id,)
|
||||
sql += ' ORDER BY payment_id DESC'
|
||||
return query(sql, params)
|
||||
Reference in new issue
Block a user