-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit_db.py
More file actions
54 lines (46 loc) · 1.8 KB
/
Copy pathinit_db.py
File metadata and controls
54 lines (46 loc) · 1.8 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
"""
init_db.py — Initialize (or reset) the database
--------------------------------------------------
• Drops all tables, recreates them fresh
• Seeds a default admin account (admin@escaperoom.com / admin123)
• Loads DATABASE_URL + keys from .env automatically
⚠️ WARNING: Running this WIPES all existing data.
Only run on first deploy or when you want to reset everything.
"""
import os
from dotenv import load_dotenv
# Load .env before importing app/config so DATABASE_URL is picked up
load_dotenv()
from app import create_app
from extensions import db, bcrypt
from models import User
app = create_app()
with app.app_context():
print(f"→ Using database: {app.config['SQLALCHEMY_DATABASE_URI'].split('@')[-1]}")
# Drop all tables
db.drop_all()
print('✓ Tables dropped')
# Recreate tables
db.create_all()
print('✓ Tables created (7 total)')
# Create admin with bcrypt-hashed password
password_hash = bcrypt.generate_password_hash('admin123').decode('utf-8')
admin = User(
name = 'Admin',
username = 'admin',
email = 'admin@escaperoom.com',
password_hash = password_hash,
role = 'admin',
batch = 'FACULTY',
is_active = True,
is_banned = False,
)
db.session.add(admin)
db.session.commit()
print('✓ Admin account created')
print(' ─────────────────────────────')
print(' Username : admin')
print(' Email : admin@escaperoom.com')
print(' Password : admin123')
print(' ─────────────────────────────')
print('\n🎯 Database ready. You can now log in and start adding rooms/questions.')