fix: the launch cleanup leaves the Site videos' files alone
Some checks failed
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Some checks failed
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Publish images (push) Has been cancelled
Build and deploy / Secret scan and release gate (push) Has been cancelled
Build and deploy / Integration suite on a real stack (push) Has been cancelled
Marcus, 2026-11-16: the whole Site tab stays. The cleanup marked every upload expired, the files behind the Site's videos and captions too; it now skips the uploads site_videos points at, and counts only what it removes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,8 @@ Run from the worker's console (Portainer > Containers > worker > Console):
|
|||||||
Removes every order with its moves, files, notices and history, every quote,
|
Removes every order with its moves, files, notices and history, every quote,
|
||||||
payment attempt and payment notification, and the artwork pictures. The
|
payment attempt and payment notification, and the artwork pictures. The
|
||||||
artwork files are marked expired, so the worker deletes them from storage
|
artwork files are marked expired, so the worker deletes them from storage
|
||||||
within a minute. Operators, machines, prices, the Tiny connection and the
|
within a minute. Operators, machines, prices, the Site tab (products, coupons,
|
||||||
|
videos with their files), the montador's tables, the Tiny connection and the
|
||||||
backups are kept.
|
backups are kept.
|
||||||
|
|
||||||
It refuses if any payment was made with real money (Mercado Pago's
|
It refuses if any payment was made with real money (Mercado Pago's
|
||||||
@@ -48,6 +49,10 @@ ACCOUNTS = [('sessions', 'sessões de clientes'), ('accounts', 'contas de client
|
|||||||
FLOW_FOLDERS = ('1. Arte recebida', '2. Arte conferida', '3. Imprimindo',
|
FLOW_FOLDERS = ('1. Arte recebida', '2. Arte conferida', '3. Imprimindo',
|
||||||
'4. Revisão', '5. Finalizado', 'Recibos', 'Revisões')
|
'4. Revisão', '5. Finalizado', 'Recibos', 'Revisões')
|
||||||
CONFIRM = 'APAGAR'
|
CONFIRM = 'APAGAR'
|
||||||
|
# What stays points at some uploads: the Site's videos and captions (Marcus,
|
||||||
|
# 2026-11-16: the whole Site tab stays). Their files are left alone.
|
||||||
|
NOT_KEPT = '''id NOT IN (SELECT upload_id FROM dtf_local.site_videos WHERE upload_id IS NOT NULL
|
||||||
|
UNION SELECT captions_id FROM dtf_local.site_videos WHERE captions_id IS NOT NULL)'''
|
||||||
|
|
||||||
|
|
||||||
def counts(c, tables):
|
def counts(c, tables):
|
||||||
@@ -86,7 +91,7 @@ def main(argv=None, out=print, connect=db.connect):
|
|||||||
out(f'Recusado: {live} pagamento(s) com dinheiro real (live_mode). Esses pedidos são de clientes.')
|
out(f'Recusado: {live} pagamento(s) com dinheiro real (live_mode). Esses pedidos são de clientes.')
|
||||||
return 1
|
return 1
|
||||||
before = counts(c, tables)
|
before = counts(c, tables)
|
||||||
files = c.execute('SELECT count(*) AS n FROM dtf_local.uploads WHERE purged_at IS NULL').fetchone()['n']
|
files = c.execute(f'SELECT count(*) AS n FROM dtf_local.uploads WHERE purged_at IS NULL AND {NOT_KEPT}').fetchone()['n']
|
||||||
for table, label in tables:
|
for table, label in tables:
|
||||||
out(f'{before[table]:>7} {label}')
|
out(f'{before[table]:>7} {label}')
|
||||||
out(f'{files:>7} arquivos de arte (o worker apaga do armazenamento)')
|
out(f'{files:>7} arquivos de arte (o worker apaga do armazenamento)')
|
||||||
@@ -99,7 +104,7 @@ def main(argv=None, out=print, connect=db.connect):
|
|||||||
return 0
|
return 0
|
||||||
for table, _ in tables:
|
for table, _ in tables:
|
||||||
c.execute(f'DELETE FROM dtf_local.{table}')
|
c.execute(f'DELETE FROM dtf_local.{table}')
|
||||||
c.execute('UPDATE dtf_local.uploads SET expires_at=now() WHERE purged_at IS NULL')
|
c.execute(f'UPDATE dtf_local.uploads SET expires_at=now() WHERE purged_at IS NULL AND {NOT_KEPT}')
|
||||||
if args.root and not args.keep_files:
|
if args.root and not args.keep_files:
|
||||||
for folder in clean_folders(args.root, dry_run=False):
|
for folder in clean_folders(args.root, dry_run=False):
|
||||||
out(f'esvaziada {folder}')
|
out(f'esvaziada {folder}')
|
||||||
|
|||||||
@@ -25,6 +25,16 @@ def run():
|
|||||||
status,amount_cents,response) VALUES(%s,%s,'mercadopago',%s,'card','approved',1490,%s) RETURNING id''',
|
status,amount_cents,response) VALUES(%s,%s,'mercadopago',%s,'card','approved',1490,%s) RETURNING id''',
|
||||||
(uuid4(), quote, str(uuid4()), Jsonb({'live_mode': True}))).fetchone()['id']
|
(uuid4(), quote, str(uuid4()), Jsonb({'live_mode': True}))).fetchone()['id']
|
||||||
|
|
||||||
|
# A Site video's file stays: the whole Site tab is kept (Marcus, 2026-11-16).
|
||||||
|
video_upload, video_id = uuid4(), None
|
||||||
|
with db.connect() as c:
|
||||||
|
taken = {row['id'] for row in c.execute('SELECT id FROM dtf_local.site_videos').fetchall()}
|
||||||
|
video_id = next(name for name in ('retirada', 'sala', 'nota', 'avulsas', 'subindo', 'png') if name not in taken)
|
||||||
|
c.execute('''INSERT INTO dtf_local.uploads(id,owner,name,size,object_key,multipart_id,complete,expires_at)
|
||||||
|
VALUES(%s,%s,'reset-video.mp4',1,%s,'',true,now()+interval '30 days')''',
|
||||||
|
(video_upload, owner, f'reset-test/{video_upload}.mp4'))
|
||||||
|
c.execute("INSERT INTO dtf_local.site_videos(id,upload_id) VALUES(%s,%s)", (video_id, video_upload))
|
||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
# Real money paid: nothing happens, even when confirmed.
|
# Real money paid: nothing happens, even when confirmed.
|
||||||
assert launch_reset.main(['--confirmar', 'APAGAR'], out=lines.append) == 1
|
assert launch_reset.main(['--confirmar', 'APAGAR'], out=lines.append) == 1
|
||||||
@@ -47,7 +57,11 @@ def run():
|
|||||||
for table in ('orders', 'quotes', 'payment_intents', 'movements', 'outbox'):
|
for table in ('orders', 'quotes', 'payment_intents', 'movements', 'outbox'):
|
||||||
assert c.execute(f'SELECT count(*) AS n FROM dtf_local.{table}').fetchone()['n'] == 0, table
|
assert c.execute(f'SELECT count(*) AS n FROM dtf_local.{table}').fetchone()['n'] == 0, table
|
||||||
assert not c.execute('''SELECT 1 FROM dtf_local.uploads WHERE purged_at IS NULL
|
assert not c.execute('''SELECT 1 FROM dtf_local.uploads WHERE purged_at IS NULL
|
||||||
AND expires_at>now()''').fetchone()
|
AND expires_at>now() AND id<>%s''', (video_upload,)).fetchone()
|
||||||
|
assert c.execute('SELECT expires_at>now() AS kept FROM dtf_local.uploads WHERE id=%s',
|
||||||
|
(video_upload,)).fetchone()['kept']
|
||||||
|
c.execute('DELETE FROM dtf_local.site_videos WHERE id=%s', (video_id,))
|
||||||
|
c.execute('DELETE FROM dtf_local.uploads WHERE id=%s', (video_upload,))
|
||||||
assert c.execute('SELECT count(*) AS n FROM dtf_local.operators').fetchone()['n'] >= 1
|
assert c.execute('SELECT count(*) AS n FROM dtf_local.operators').fetchone()['n'] >= 1
|
||||||
assert any('Apagado.' in line for line in lines) and 'continua de onde parou' in lines[-1], lines
|
assert any('Apagado.' in line for line in lines) and 'continua de onde parou' in lines[-1], lines
|
||||||
# The numbering is not reset: DTF-1…DTF-15 already exist in Tiny.
|
# The numbering is not reset: DTF-1…DTF-15 already exist in Tiny.
|
||||||
@@ -77,7 +91,7 @@ def run():
|
|||||||
'4. Revisão', '5. Finalizado', 'Recibos', 'Revisões'):
|
'4. Revisão', '5. Finalizado', 'Recibos', 'Revisões'):
|
||||||
assert list((root / name).iterdir()) == [], name
|
assert list((root / name).iterdir()) == [], name
|
||||||
assert (root / 'Estampas' / '1001.png').read_bytes() == b'art'
|
assert (root / 'Estampas' / '1001.png').read_bytes() == b'art'
|
||||||
print('PASS: launch cleanup refuses real payments, counts first, then removes test orders and quotes, keeping the numbering and the art library')
|
print('PASS: launch cleanup refuses real payments, counts first, then removes test orders and quotes, keeping the numbering, the Site videos\' files and the art library')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user