ein-dateien backend erstellt
This commit is contained in:
55
archiv/flask-backend/scripts/init_db.py
Normal file
55
archiv/flask-backend/scripts/init_db.py
Normal file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
from app import create_app, db
|
||||
from app.models import User, Printer
|
||||
import uuid
|
||||
|
||||
def init_db():
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
# Create tables
|
||||
db.create_all()
|
||||
|
||||
# Check if we already have an admin user
|
||||
admin = User.query.filter_by(role='admin').first()
|
||||
if not admin:
|
||||
# Create admin user
|
||||
admin = User(
|
||||
id=str(uuid.uuid4()),
|
||||
username='admin',
|
||||
display_name='Administrator',
|
||||
email='admin@example.com',
|
||||
role='admin'
|
||||
)
|
||||
admin.set_password('admin123') # Default password, change in production!
|
||||
db.session.add(admin)
|
||||
print("Created admin user with username 'admin' and password 'admin123'")
|
||||
|
||||
# Check if we have any printers
|
||||
printer_count = Printer.query.count()
|
||||
if printer_count == 0:
|
||||
# Create sample printers
|
||||
printers = [
|
||||
Printer(
|
||||
name='Printer 1',
|
||||
description='3D Printer for general use',
|
||||
status=0 # OPERATIONAL
|
||||
),
|
||||
Printer(
|
||||
name='Printer 2',
|
||||
description='High resolution printer for detailed work',
|
||||
status=0 # OPERATIONAL
|
||||
),
|
||||
Printer(
|
||||
name='Printer 3',
|
||||
description='Large format printer for big projects',
|
||||
status=0 # OPERATIONAL
|
||||
)
|
||||
]
|
||||
db.session.add_all(printers)
|
||||
print("Created sample printers")
|
||||
|
||||
db.session.commit()
|
||||
print("Database initialized successfully!")
|
||||
|
||||
if __name__ == '__main__':
|
||||
init_db()
|
Reference in New Issue
Block a user