60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script to add the 'housekeeping' role to the database.
|
|
Run this script once to create the housekeeping role if it doesn't exist.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from pathlib import Path
|
|
|
|
# Add the Backend directory to the path
|
|
backend_dir = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(backend_dir))
|
|
|
|
from src.shared.config.database import SessionLocal
|
|
from src.models import Role # Use the models __init__ which handles all imports
|
|
|
|
def add_housekeeping_role():
|
|
"""Add the housekeeping role to the database if it doesn't exist."""
|
|
db = SessionLocal()
|
|
try:
|
|
# Check if housekeeping role already exists
|
|
existing_role = db.query(Role).filter(Role.name == 'housekeeping').first()
|
|
|
|
if existing_role:
|
|
print("✓ Housekeeping role already exists in the database.")
|
|
print(f" Role ID: {existing_role.id}")
|
|
print(f" Role Name: {existing_role.name}")
|
|
return
|
|
|
|
# Create the housekeeping role
|
|
housekeeping_role = Role(
|
|
name='housekeeping',
|
|
description='Housekeeping staff role with access to room cleaning tasks and status updates'
|
|
)
|
|
db.add(housekeeping_role)
|
|
db.commit()
|
|
db.refresh(housekeeping_role)
|
|
|
|
print("✓ Housekeeping role created successfully!")
|
|
print(f" Role ID: {housekeeping_role.id}")
|
|
print(f" Role Name: {housekeeping_role.name}")
|
|
print(f" Description: {housekeeping_role.description}")
|
|
|
|
except Exception as e:
|
|
db.rollback()
|
|
print(f"✗ Error creating housekeeping role: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|
|
finally:
|
|
db.close()
|
|
|
|
if __name__ == '__main__':
|
|
print("Adding housekeeping role to the database...")
|
|
print("=" * 60)
|
|
add_housekeeping_role()
|
|
print("=" * 60)
|
|
print("Done!")
|