TorbatYar/backend/services/payment/scripts/ensure_db.py
Mortezakoohjani 9fac160258 feat(payment): ship Torbat Pay MVP phases 14.0-14.5
Add independent payment-service (port 8012, payment_db) with foundation licensing, BYO-PSP, merchant accounts, idempotent requests, callbacks, and immutable ledger.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-27 17:57:04 +03:30

13 lines
618 B
Python

import os
from urllib.parse import urlparse
def main():
url=os.getenv("PAYMENT_DATABASE_URL_SYNC","")
if not url: return
import psycopg
p=urlparse(url.replace("+psycopg","")); db=(p.path or "/payment_db").lstrip("/")
with psycopg.connect(host=p.hostname or "localhost",port=p.port or 5432,user=p.username,password=p.password,dbname="postgres",autocommit=True) as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1 FROM pg_database WHERE datname=%s",(db,))
if not cur.fetchone(): cur.execute(f'CREATE DATABASE "{db}"')
if __name__=="__main__": main()