-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed_multitenant.py
More file actions
67 lines (59 loc) · 1.73 KB
/
seed_multitenant.py
File metadata and controls
67 lines (59 loc) · 1.73 KB
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
from backend.database import SessionLocal
from backend.models import Product, Restaurant, User
from backend.auth import get_password_hash
def seed_multitenant():
db = SessionLocal()
# Check if restaurant exists
if db.query(Restaurant).count() > 0:
print("Data already exists.")
return
# 1. Create Restaurant
restaurant = Restaurant(name="Ordera Grill")
db.add(restaurant)
db.commit()
db.refresh(restaurant)
print(f"Created Restaurant: {restaurant.name} (ID: {restaurant.id})")
# 2. Create Admin
admin = User(
username="admin",
hashed_password=get_password_hash("admin123"),
role="admin",
restaurant_id=restaurant.id
)
db.add(admin)
db.commit()
print("Created Admin: admin / admin123")
# 3. Create Products
products = [
Product(
name="Double Cheeseburger",
description="Two patties, extra cheese",
price=12.99,
category="Burgers",
restaurant_id=restaurant.id,
modifiers={"size": ["Single", "Double"]}
),
Product(
name="Large Fries",
description="Crispy golden fries",
price=5.99,
category="Sides",
restaurant_id=restaurant.id,
modifiers={}
),
Product(
name="Chocolate Shake",
description="Rich chocolate milkshake",
price=6.99,
category="Drinks",
restaurant_id=restaurant.id,
modifiers={}
)
]
for p in products:
db.add(p)
db.commit()
print("Seeded 3 products for Ordera Grill.")
db.close()
if __name__ == "__main__":
seed_multitenant()