Spaces:
Sleeping
Sleeping
File size: 2,422 Bytes
b613c13 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | """Seed initial data into PostgreSQL.
Inserts default super admin, demo LPK account, and reference data.
Mirrors seedDemoLPKAccount() and seed data from schema.sql.
Usage:
python seed_data.py
"""
import hashlib
import os
import psycopg2
DATABASE_URL = os.environ.get("DATABASE_URL_SYNC", "postgresql://localhost:5432/brigawan")
def hash_password(password: str, salt: str = "BRIGAWAN_AUTH_SALT_2026") -> str:
"""Double-hash: SHA256(SHA256(password + email) + salt)."""
# Simulates the GAS hashPassword() protocol
pre_hash = hashlib.sha256((password + salt).encode()).hexdigest()
return hashlib.sha256((pre_hash + salt).encode()).hexdigest()
def seed():
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
# βββ Super Admin ββββββββββββββββββββββββββββββββββββββββββββββββββ
cur.execute(
"""
INSERT INTO admins (name, email, password_hash, role)
VALUES (%s, %s, %s, %s)
ON CONFLICT (email) DO NOTHING
""",
(
"Super Admin",
"admin@briga.id",
hash_password("changeme123"),
"SUPER_ADMIN",
),
)
print("β
Super admin seeded (admin@briga.id / changeme123)")
# βββ Demo LPK Partner ββββββββββββββββββββββββββββββββββββββββββββ
cur.execute(
"""
INSERT INTO lpk_partners (
lpk_id, lpk_name, city_branch, pic_name, pic_whatsapp,
email, password_hash, kemnaker_vin, lsp_affiliation,
status_active, pks_status
)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
ON CONFLICT (email) DO NOTHING
""",
(
"LPK-DEMO-001",
"LPK Training Hub Demo Briga",
"Jakarta",
"Tim Demo Briga",
"081234567890",
"demo@lpk.briga.id",
hash_password("DemoLPK2025", "demo@lpk.briga.id"),
"VIN-DEMO-001",
"LSP Demo Nasional",
True,
"Active",
),
)
print("β
Demo LPK account seeded (demo@lpk.briga.id / DemoLPK2025)")
conn.commit()
cur.close()
conn.close()
print("\n⨠Seed complete!")
if __name__ == "__main__":
seed()
|