Spaces:
Sleeping
Sleeping
Download scripts/seed_data.py from yabeskn/briga-core-api: direct link, hf CLI and curl.
- Browser
- Download file 2.42 kB
-
https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/scripts/seed_data.py
- Command line
-
hf download hf://spaces/yabeskn/briga-core-api/scripts/seed_data.py
-
curl -L -o seed_data.py https://huggingface.co/spaces/yabeskn/briga-core-api/resolve/main/scripts/seed_data.py
2.42 kB
| """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() | |