Spaces:
Sleeping
Sleeping
Remove init_db.py and fix Dockerfile - use existing Tabble.db database
Browse files- Dockerfile +0 -3
- init_db.py +0 -356
Dockerfile
CHANGED
|
@@ -30,9 +30,6 @@ RUN mkdir -p app/static/images/dishes && \
|
|
| 30 |
mkdir -p templates && \
|
| 31 |
chmod 755 app/static/images
|
| 32 |
|
| 33 |
-
# Initialize the database with sample data
|
| 34 |
-
RUN python init_db.py
|
| 35 |
-
|
| 36 |
# Expose port 7860 (Hugging Face Spaces default)
|
| 37 |
EXPOSE 7860
|
| 38 |
|
|
|
|
| 30 |
mkdir -p templates && \
|
| 31 |
chmod 755 app/static/images
|
| 32 |
|
|
|
|
|
|
|
|
|
|
| 33 |
# Expose port 7860 (Hugging Face Spaces default)
|
| 34 |
EXPOSE 7860
|
| 35 |
|
init_db.py
DELETED
|
@@ -1,356 +0,0 @@
|
|
| 1 |
-
from app.database import (
|
| 2 |
-
create_tables,
|
| 3 |
-
SessionLocal,
|
| 4 |
-
Dish,
|
| 5 |
-
Person,
|
| 6 |
-
Base,
|
| 7 |
-
LoyaltyProgram,
|
| 8 |
-
SelectionOffer,
|
| 9 |
-
Table,
|
| 10 |
-
)
|
| 11 |
-
from sqlalchemy import create_engine
|
| 12 |
-
from datetime import datetime, timezone
|
| 13 |
-
import os
|
| 14 |
-
import sys
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
def init_db(force_reset=False):
|
| 18 |
-
# Check if force_reset is enabled
|
| 19 |
-
if force_reset:
|
| 20 |
-
# Drop all tables and recreate them
|
| 21 |
-
print("Forcing database reset...")
|
| 22 |
-
Base.metadata.drop_all(
|
| 23 |
-
bind=create_engine(
|
| 24 |
-
"sqlite:///./tabble_new.db", connect_args={"check_same_thread": False}
|
| 25 |
-
)
|
| 26 |
-
)
|
| 27 |
-
|
| 28 |
-
# Create tables
|
| 29 |
-
create_tables()
|
| 30 |
-
|
| 31 |
-
# Create a database session
|
| 32 |
-
db = SessionLocal()
|
| 33 |
-
|
| 34 |
-
# Check if dishes already exist
|
| 35 |
-
existing_dishes = db.query(Dish).count()
|
| 36 |
-
if existing_dishes > 0:
|
| 37 |
-
print("Database already contains data. Skipping initialization.")
|
| 38 |
-
return
|
| 39 |
-
|
| 40 |
-
# Add sample dishes
|
| 41 |
-
sample_dishes = [
|
| 42 |
-
# Regular dishes
|
| 43 |
-
Dish(
|
| 44 |
-
name="Margherita Pizza",
|
| 45 |
-
description="Classic pizza with tomato sauce, mozzarella, and basil",
|
| 46 |
-
category='["Main Course", "Italian"]',
|
| 47 |
-
price=12.99,
|
| 48 |
-
quantity=20,
|
| 49 |
-
image_path="/static/images/default-dish.jpg",
|
| 50 |
-
discount=0,
|
| 51 |
-
is_offer=0,
|
| 52 |
-
is_special=0,
|
| 53 |
-
is_vegetarian=1,
|
| 54 |
-
),
|
| 55 |
-
Dish(
|
| 56 |
-
name="Caesar Salad",
|
| 57 |
-
description="Fresh romaine lettuce with Caesar dressing, croutons, and parmesan",
|
| 58 |
-
category='["Appetizer", "Salad"]',
|
| 59 |
-
price=8.99,
|
| 60 |
-
quantity=15,
|
| 61 |
-
image_path="/static/images/default-dish.jpg",
|
| 62 |
-
discount=0,
|
| 63 |
-
is_offer=0,
|
| 64 |
-
is_special=0,
|
| 65 |
-
is_vegetarian=1,
|
| 66 |
-
),
|
| 67 |
-
Dish(
|
| 68 |
-
name="Chocolate Cake",
|
| 69 |
-
description="Rich chocolate cake with ganache frosting",
|
| 70 |
-
category="Dessert",
|
| 71 |
-
price=6.99,
|
| 72 |
-
quantity=10,
|
| 73 |
-
image_path="/static/images/default-dish.jpg",
|
| 74 |
-
discount=0,
|
| 75 |
-
is_offer=0,
|
| 76 |
-
is_special=0,
|
| 77 |
-
),
|
| 78 |
-
Dish(
|
| 79 |
-
name="Iced Tea",
|
| 80 |
-
description="Refreshing iced tea with lemon",
|
| 81 |
-
category="Beverage",
|
| 82 |
-
price=3.99,
|
| 83 |
-
quantity=30,
|
| 84 |
-
image_path="/static/images/default-dish.jpg",
|
| 85 |
-
discount=0,
|
| 86 |
-
is_offer=0,
|
| 87 |
-
is_special=0,
|
| 88 |
-
),
|
| 89 |
-
Dish(
|
| 90 |
-
name="Chicken Alfredo",
|
| 91 |
-
description="Fettuccine pasta with creamy Alfredo sauce and grilled chicken",
|
| 92 |
-
category="Main Course",
|
| 93 |
-
price=15.99,
|
| 94 |
-
quantity=12,
|
| 95 |
-
image_path="/static/images/default-dish.jpg",
|
| 96 |
-
discount=0,
|
| 97 |
-
is_offer=0,
|
| 98 |
-
),
|
| 99 |
-
Dish(
|
| 100 |
-
name="Garlic Bread",
|
| 101 |
-
description="Toasted bread with garlic butter and herbs",
|
| 102 |
-
category="Appetizer",
|
| 103 |
-
price=4.99,
|
| 104 |
-
quantity=25,
|
| 105 |
-
image_path="/static/images/default-dish.jpg",
|
| 106 |
-
discount=0,
|
| 107 |
-
is_offer=0,
|
| 108 |
-
is_special=0,
|
| 109 |
-
),
|
| 110 |
-
# Special offer dishes
|
| 111 |
-
Dish(
|
| 112 |
-
name="Weekend Special Pizza",
|
| 113 |
-
description="Deluxe pizza with premium toppings and extra cheese",
|
| 114 |
-
category="Main Course",
|
| 115 |
-
price=18.99,
|
| 116 |
-
quantity=15,
|
| 117 |
-
image_path="/static/images/default-dish.jpg",
|
| 118 |
-
discount=20,
|
| 119 |
-
is_offer=1,
|
| 120 |
-
is_special=0,
|
| 121 |
-
),
|
| 122 |
-
Dish(
|
| 123 |
-
name="Seafood Pasta",
|
| 124 |
-
description="Fresh pasta with mixed seafood in a creamy sauce",
|
| 125 |
-
category="Main Course",
|
| 126 |
-
price=22.99,
|
| 127 |
-
quantity=10,
|
| 128 |
-
image_path="/static/images/default-dish.jpg",
|
| 129 |
-
discount=15,
|
| 130 |
-
is_offer=1,
|
| 131 |
-
is_special=0,
|
| 132 |
-
),
|
| 133 |
-
Dish(
|
| 134 |
-
name="Tiramisu",
|
| 135 |
-
description="Classic Italian dessert with coffee-soaked ladyfingers and mascarpone cream",
|
| 136 |
-
category="Dessert",
|
| 137 |
-
price=9.99,
|
| 138 |
-
quantity=8,
|
| 139 |
-
image_path="/static/images/default-dish.jpg",
|
| 140 |
-
discount=25,
|
| 141 |
-
is_offer=1,
|
| 142 |
-
is_special=0,
|
| 143 |
-
),
|
| 144 |
-
# Today's special dishes
|
| 145 |
-
Dish(
|
| 146 |
-
name="Chef's Special Steak",
|
| 147 |
-
description="Prime cut steak cooked to perfection with special house seasoning",
|
| 148 |
-
category="Main Course",
|
| 149 |
-
price=24.99,
|
| 150 |
-
quantity=12,
|
| 151 |
-
image_path="/static/images/default-dish.jpg",
|
| 152 |
-
discount=0,
|
| 153 |
-
is_offer=0,
|
| 154 |
-
is_special=1,
|
| 155 |
-
),
|
| 156 |
-
Dish(
|
| 157 |
-
name="Truffle Mushroom Risotto",
|
| 158 |
-
description="Creamy risotto with wild mushrooms and truffle oil",
|
| 159 |
-
category="Main Course",
|
| 160 |
-
price=16.99,
|
| 161 |
-
quantity=10,
|
| 162 |
-
image_path="/static/images/default-dish.jpg",
|
| 163 |
-
discount=0,
|
| 164 |
-
is_offer=0,
|
| 165 |
-
is_special=1,
|
| 166 |
-
),
|
| 167 |
-
Dish(
|
| 168 |
-
name="Chocolate Lava Cake",
|
| 169 |
-
description="Warm chocolate cake with a molten center, served with vanilla ice cream",
|
| 170 |
-
category="Dessert",
|
| 171 |
-
price=8.99,
|
| 172 |
-
quantity=15,
|
| 173 |
-
image_path="/static/images/default-dish.jpg",
|
| 174 |
-
discount=0,
|
| 175 |
-
is_offer=0,
|
| 176 |
-
is_special=1,
|
| 177 |
-
),
|
| 178 |
-
]
|
| 179 |
-
|
| 180 |
-
# Add dishes to database
|
| 181 |
-
for dish in sample_dishes:
|
| 182 |
-
db.add(dish)
|
| 183 |
-
|
| 184 |
-
# Add sample users
|
| 185 |
-
sample_users = [
|
| 186 |
-
Person(
|
| 187 |
-
username="john_doe",
|
| 188 |
-
password="password123",
|
| 189 |
-
visit_count=1,
|
| 190 |
-
last_visit=datetime.now(timezone.utc),
|
| 191 |
-
),
|
| 192 |
-
Person(
|
| 193 |
-
username="jane_smith",
|
| 194 |
-
password="password456",
|
| 195 |
-
visit_count=3,
|
| 196 |
-
last_visit=datetime.now(timezone.utc),
|
| 197 |
-
),
|
| 198 |
-
Person(
|
| 199 |
-
username="guest",
|
| 200 |
-
password="guest",
|
| 201 |
-
visit_count=5,
|
| 202 |
-
last_visit=datetime.now(timezone.utc),
|
| 203 |
-
),
|
| 204 |
-
]
|
| 205 |
-
|
| 206 |
-
# Add users to database
|
| 207 |
-
for user in sample_users:
|
| 208 |
-
db.add(user)
|
| 209 |
-
|
| 210 |
-
# Add sample loyalty program tiers
|
| 211 |
-
sample_loyalty_tiers = [
|
| 212 |
-
LoyaltyProgram(
|
| 213 |
-
visit_count=3,
|
| 214 |
-
discount_percentage=5.0,
|
| 215 |
-
is_active=True,
|
| 216 |
-
created_at=datetime.now(timezone.utc),
|
| 217 |
-
updated_at=datetime.now(timezone.utc),
|
| 218 |
-
),
|
| 219 |
-
LoyaltyProgram(
|
| 220 |
-
visit_count=5,
|
| 221 |
-
discount_percentage=10.0,
|
| 222 |
-
is_active=True,
|
| 223 |
-
created_at=datetime.now(timezone.utc),
|
| 224 |
-
updated_at=datetime.now(timezone.utc),
|
| 225 |
-
),
|
| 226 |
-
LoyaltyProgram(
|
| 227 |
-
visit_count=10,
|
| 228 |
-
discount_percentage=15.0,
|
| 229 |
-
is_active=True,
|
| 230 |
-
created_at=datetime.now(timezone.utc),
|
| 231 |
-
updated_at=datetime.now(timezone.utc),
|
| 232 |
-
),
|
| 233 |
-
LoyaltyProgram(
|
| 234 |
-
visit_count=20,
|
| 235 |
-
discount_percentage=20.0,
|
| 236 |
-
is_active=True,
|
| 237 |
-
created_at=datetime.now(timezone.utc),
|
| 238 |
-
updated_at=datetime.now(timezone.utc),
|
| 239 |
-
),
|
| 240 |
-
]
|
| 241 |
-
|
| 242 |
-
# Add loyalty tiers to database
|
| 243 |
-
for tier in sample_loyalty_tiers:
|
| 244 |
-
db.add(tier)
|
| 245 |
-
|
| 246 |
-
# Add sample selection offers
|
| 247 |
-
sample_selection_offers = [
|
| 248 |
-
SelectionOffer(
|
| 249 |
-
min_amount=50.0,
|
| 250 |
-
discount_amount=5.0,
|
| 251 |
-
is_active=True,
|
| 252 |
-
description="Spend $50, get $5 off",
|
| 253 |
-
created_at=datetime.now(timezone.utc),
|
| 254 |
-
updated_at=datetime.now(timezone.utc),
|
| 255 |
-
),
|
| 256 |
-
SelectionOffer(
|
| 257 |
-
min_amount=100.0,
|
| 258 |
-
discount_amount=15.0,
|
| 259 |
-
is_active=True,
|
| 260 |
-
description="Spend $100, get $15 off",
|
| 261 |
-
created_at=datetime.now(timezone.utc),
|
| 262 |
-
updated_at=datetime.now(timezone.utc),
|
| 263 |
-
),
|
| 264 |
-
SelectionOffer(
|
| 265 |
-
min_amount=150.0,
|
| 266 |
-
discount_amount=25.0,
|
| 267 |
-
is_active=True,
|
| 268 |
-
description="Spend $150, get $25 off",
|
| 269 |
-
created_at=datetime.now(timezone.utc),
|
| 270 |
-
updated_at=datetime.now(timezone.utc),
|
| 271 |
-
),
|
| 272 |
-
]
|
| 273 |
-
|
| 274 |
-
# Add selection offers to database
|
| 275 |
-
for offer in sample_selection_offers:
|
| 276 |
-
db.add(offer)
|
| 277 |
-
|
| 278 |
-
# Add sample tables
|
| 279 |
-
sample_tables = [
|
| 280 |
-
Table(
|
| 281 |
-
table_number=1,
|
| 282 |
-
is_occupied=False,
|
| 283 |
-
created_at=datetime.now(timezone.utc),
|
| 284 |
-
updated_at=datetime.now(timezone.utc),
|
| 285 |
-
),
|
| 286 |
-
Table(
|
| 287 |
-
table_number=2,
|
| 288 |
-
is_occupied=False,
|
| 289 |
-
created_at=datetime.now(timezone.utc),
|
| 290 |
-
updated_at=datetime.now(timezone.utc),
|
| 291 |
-
),
|
| 292 |
-
Table(
|
| 293 |
-
table_number=3,
|
| 294 |
-
is_occupied=False,
|
| 295 |
-
created_at=datetime.now(timezone.utc),
|
| 296 |
-
updated_at=datetime.now(timezone.utc),
|
| 297 |
-
),
|
| 298 |
-
Table(
|
| 299 |
-
table_number=4,
|
| 300 |
-
is_occupied=False,
|
| 301 |
-
created_at=datetime.now(timezone.utc),
|
| 302 |
-
updated_at=datetime.now(timezone.utc),
|
| 303 |
-
),
|
| 304 |
-
Table(
|
| 305 |
-
table_number=5,
|
| 306 |
-
is_occupied=False,
|
| 307 |
-
created_at=datetime.now(timezone.utc),
|
| 308 |
-
updated_at=datetime.now(timezone.utc),
|
| 309 |
-
),
|
| 310 |
-
Table(
|
| 311 |
-
table_number=6,
|
| 312 |
-
is_occupied=False,
|
| 313 |
-
created_at=datetime.now(timezone.utc),
|
| 314 |
-
updated_at=datetime.now(timezone.utc),
|
| 315 |
-
),
|
| 316 |
-
Table(
|
| 317 |
-
table_number=7,
|
| 318 |
-
is_occupied=False,
|
| 319 |
-
created_at=datetime.now(timezone.utc),
|
| 320 |
-
updated_at=datetime.now(timezone.utc),
|
| 321 |
-
),
|
| 322 |
-
Table(
|
| 323 |
-
table_number=8,
|
| 324 |
-
is_occupied=False,
|
| 325 |
-
created_at=datetime.now(timezone.utc),
|
| 326 |
-
updated_at=datetime.now(timezone.utc),
|
| 327 |
-
),
|
| 328 |
-
]
|
| 329 |
-
|
| 330 |
-
# Add tables to database
|
| 331 |
-
for table in sample_tables:
|
| 332 |
-
db.add(table)
|
| 333 |
-
|
| 334 |
-
# Commit changes
|
| 335 |
-
db.commit()
|
| 336 |
-
|
| 337 |
-
print("Database initialized with sample data:")
|
| 338 |
-
print("- Added", len(sample_dishes), "sample dishes")
|
| 339 |
-
print("- Added", len(sample_users), "sample users")
|
| 340 |
-
print("- Added", len(sample_loyalty_tiers), "loyalty program tiers")
|
| 341 |
-
print("- Added", len(sample_selection_offers), "selection offers")
|
| 342 |
-
print("- Added", len(sample_tables), "tables")
|
| 343 |
-
|
| 344 |
-
# Close session
|
| 345 |
-
db.close()
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
if __name__ == "__main__":
|
| 349 |
-
# Create static/images directory if it doesn't exist
|
| 350 |
-
os.makedirs("app/static/images", exist_ok=True)
|
| 351 |
-
|
| 352 |
-
# Check for force reset flag
|
| 353 |
-
force_reset = "--force-reset" in sys.argv
|
| 354 |
-
|
| 355 |
-
# Initialize database
|
| 356 |
-
init_db(force_reset)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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