first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
55
backend/scripts/seed.py
Normal file
55
backend/scripts/seed.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""Initialize admin user and default Bengaluru platform links."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from app.auth import hash_password
|
||||
from app.config import settings
|
||||
from app.database import SessionLocal, engine
|
||||
from app.models import AdminUser, Base, PlatformKind, PlatformLink
|
||||
|
||||
DEFAULT_LINKS = [
|
||||
(PlatformKind.bookmyshow, "BookMyShow", "https://in.bookmyshow.com/explore/home/bengaluru", 0),
|
||||
(PlatformKind.district, "District", "https://www.district.in/events/bengaluru", 1),
|
||||
(PlatformKind.instagram, "Instagram", "https://www.instagram.com/", 2),
|
||||
(PlatformKind.highape, "HighApe", "https://highape.com/bangalore", 3),
|
||||
]
|
||||
|
||||
REMOVED_KINDS = (PlatformKind.youtube, PlatformKind.whatsapp)
|
||||
|
||||
|
||||
def main():
|
||||
Base.metadata.create_all(bind=engine)
|
||||
db = SessionLocal()
|
||||
try:
|
||||
if not db.query(AdminUser).filter(AdminUser.email == settings.admin_email).first():
|
||||
db.add(
|
||||
AdminUser(
|
||||
email=settings.admin_email,
|
||||
hashed_password=hash_password(settings.admin_password),
|
||||
)
|
||||
)
|
||||
print(f"Created admin: {settings.admin_email}")
|
||||
|
||||
if db.query(PlatformLink).count() == 0:
|
||||
for kind, label, url, order in DEFAULT_LINKS:
|
||||
db.add(PlatformLink(kind=kind, label=label, url=url, sort_order=order, is_active=True))
|
||||
print("Seeded default platform links (update URLs in admin)")
|
||||
else:
|
||||
for kind in REMOVED_KINDS:
|
||||
db.query(PlatformLink).filter(PlatformLink.kind == kind).delete()
|
||||
for kind, label, url, order in DEFAULT_LINKS:
|
||||
row = db.query(PlatformLink).filter(PlatformLink.kind == kind).first()
|
||||
if not row:
|
||||
db.add(PlatformLink(kind=kind, label=label, url=url, sort_order=order, is_active=True))
|
||||
print("Synced platform links (removed YouTube/WhatsApp, ensured BMS/District/Insta/HighApe)")
|
||||
|
||||
db.commit()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue