53 lines
1.4 KiB
Bash
Executable File
53 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Script to reinitialize database with new Player schema
|
|
|
|
cd /home/pi/Desktop/digiserver-v2
|
|
|
|
echo "🗑️ Removing old database..."
|
|
rm -f instance/dev.db
|
|
|
|
echo "🚀 Recreating database with new schema..."
|
|
.venv/bin/python << 'EOF'
|
|
from app.app import create_app
|
|
from app.extensions import db, bcrypt
|
|
from app.models import User, Player
|
|
import secrets
|
|
|
|
print('🚀 Creating Flask app...')
|
|
app = create_app()
|
|
|
|
with app.app_context():
|
|
print('🗄️ Creating database tables...')
|
|
db.create_all()
|
|
print('✅ Database tables created')
|
|
|
|
# Create admin user
|
|
hashed = bcrypt.generate_password_hash('admin123').decode('utf-8')
|
|
admin = User(username='admin', password=hashed, role='admin')
|
|
db.session.add(admin)
|
|
|
|
# Create example player
|
|
player = Player(
|
|
name='Demo Player',
|
|
hostname='player-001',
|
|
location='Main Office',
|
|
auth_code=secrets.token_urlsafe(32),
|
|
orientation='Landscape'
|
|
)
|
|
player.set_password('demo123')
|
|
player.set_quickconnect_code('QUICK123')
|
|
db.session.add(player)
|
|
|
|
db.session.commit()
|
|
print('✅ Admin user created (admin/admin123)')
|
|
print('✅ Demo player created:')
|
|
print(f' - Hostname: player-001')
|
|
print(f' - Password: demo123')
|
|
print(f' - Quick Connect: QUICK123')
|
|
print(f' - Auth Code: {player.auth_code}')
|
|
|
|
print('')
|
|
print('🎉 Database ready!')
|
|
print('📍 Restart Flask server to use new database')
|
|
EOF
|