All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 5m5s
Build and deploy / Secret scan and release gate (push) Successful in 11s
Build and deploy / Publish images (push) Successful in 1m23s
Integrações gets "Baixar ao chegar" next to "Baixar na Fila". On arrival the file (the generated print file, or the final once approved) goes into a Recebidos folder inside the chosen one and moves up when the order enters the queue. Files of orders cancelled, deleted or sent back for correction, and files replaced by another final, leave the folder. The launch reset now restarts order numbers at #1 by itself: the worker's role may set the orders' number sequence, and nothing else. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
85 lines
3.8 KiB
Python
85 lines
3.8 KiB
Python
"""Clear the test orders before the Site opens to customers, once, by hand.
|
|
|
|
Run from the worker's console (Portainer > Containers > worker > Console):
|
|
|
|
python -m ops.launch_reset shows what would be removed
|
|
python -m ops.launch_reset --confirmar APAGAR removes it
|
|
python -m ops.launch_reset --confirmar APAGAR --contas also customer accounts
|
|
|
|
Removes every order with its moves, files and notices, every quote, payment
|
|
attempt and payment notification, and the artwork pictures. The artwork
|
|
files are marked expired, so the worker deletes them from storage within a
|
|
minute. Operators, the Tiny connection and the backups are kept.
|
|
|
|
It refuses if any payment was made with real money (Mercado Pago's
|
|
live_mode): those are customers' orders, not tests.
|
|
|
|
Order numbers start again at #1. A database set up before the worker could
|
|
do that prints the one command to run in the database container's console.
|
|
"""
|
|
import argparse
|
|
import sys
|
|
|
|
from app.core import db
|
|
|
|
TABLES = [ # in an order the foreign keys allow
|
|
('movements', 'movimentos de etapa'),
|
|
('order_files', 'arquivos finais e correções'),
|
|
('print_files', 'arquivos de impressão gerados'),
|
|
('outbox', 'envios ao Tiny e avisos'),
|
|
('orders', 'pedidos'),
|
|
('payment_intents', 'tentativas de pagamento'),
|
|
('payment_events', 'avisos de pagamento'),
|
|
('quotes', 'cotações'),
|
|
('upload_thumbnails', 'miniaturas das artes'),
|
|
]
|
|
ACCOUNTS = [('sessions', 'sessões de clientes'), ('accounts', 'contas de clientes')]
|
|
CONFIRM = 'APAGAR'
|
|
RESTART = 'ALTER TABLE dtf_local.orders ALTER COLUMN number RESTART WITH 1;'
|
|
# What the worker's role may do itself (app/bootstrap.py grants it).
|
|
RENUMBER = "SELECT setval(pg_get_serial_sequence('dtf_local.orders','number'), 1, false)"
|
|
|
|
|
|
def counts(c, tables):
|
|
return {table: c.execute(f'SELECT count(*) AS n FROM dtf_local.{table}').fetchone()['n'] for table, _ in tables}
|
|
|
|
|
|
def main(argv=None, out=print, connect=db.connect):
|
|
parser = argparse.ArgumentParser(prog='python -m ops.launch_reset')
|
|
parser.add_argument('--confirmar', default='', help=f'escreva {CONFIRM} para apagar')
|
|
parser.add_argument('--contas', action='store_true', help='apagar também as contas de clientes')
|
|
args = parser.parse_args(argv)
|
|
tables = TABLES + (ACCOUNTS if args.contas else [])
|
|
with connect() as c:
|
|
live = c.execute("""SELECT count(*) AS n FROM dtf_local.payment_intents
|
|
WHERE response->>'live_mode'='true'""").fetchone()['n']
|
|
if live:
|
|
out(f'Recusado: {live} pagamento(s) com dinheiro real (live_mode). Esses pedidos são de clientes.')
|
|
return 1
|
|
before = counts(c, tables)
|
|
files = c.execute('SELECT count(*) AS n FROM dtf_local.uploads WHERE purged_at IS NULL').fetchone()['n']
|
|
for table, label in tables:
|
|
out(f'{before[table]:>7} {label}')
|
|
out(f'{files:>7} arquivos de arte (o worker apaga do armazenamento)')
|
|
if args.confirmar != CONFIRM:
|
|
out(f'Nada foi apagado. Repita com --confirmar {CONFIRM} para apagar.')
|
|
return 0
|
|
for table, _ in tables:
|
|
c.execute(f'DELETE FROM dtf_local.{table}')
|
|
c.execute('UPDATE dtf_local.uploads SET expires_at=now() WHERE purged_at IS NULL')
|
|
out('Apagado.')
|
|
try:
|
|
with connect() as c:
|
|
c.execute(RENUMBER)
|
|
out('A numeração dos pedidos recomeça em #1.')
|
|
except Exception as exc: # the application's role cannot alter the table
|
|
if 'permission' not in str(exc).lower() and 'owner' not in str(exc).lower():
|
|
raise
|
|
out('Para a numeração recomeçar em #1, rode no console do container do banco (db):')
|
|
out(f' psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "{RESTART}"')
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|