59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Database Cleanup Script for Resources/Bookings Tables
|
|
This script removes resources, bookings tables from PostgreSQL database.
|
|
Usage: cd /Users/le0an/Developer/Personal/ManagementPortal && FLASK_APP=app.py flask cleanup-resources-bookings
|
|
Or run directly with app context.
|
|
"""
|
|
|
|
import sys
|
|
sys.path.insert(0, '/Users/le0an/Developer/Personal/ManagementPortal')
|
|
|
|
from sqlalchemy import text
|
|
|
|
|
|
def main():
|
|
"""Clean up resources and bookings tables."""
|
|
|
|
print("=" * 60)
|
|
print("Database Cleanup: Removing Resources & Bookings Tables")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
# Import after adding path to sys.path
|
|
from app import db, app
|
|
|
|
with app.app_context():
|
|
print("1. Dropping bookings table...")
|
|
try:
|
|
db.session.execute(text("""DROP TABLE IF EXISTS booking CASCADE"""))
|
|
print(" ✓ Bookings removed (with cascading deletes)")
|
|
except Exception as e:
|
|
print(f" ✗ Error removing bookings: {e}")
|
|
|
|
print()
|
|
print("2. Dropping resource_permissions table...")
|
|
try:
|
|
db.session.execute(text("""DROP TABLE IF EXISTS resource_permission CASCADE"""))
|
|
print(" ✓ ResourcePermissions removed (with cascading deletes)")
|
|
except Exception as e:
|
|
print(f" ✗ Error removing permissions: {e}")
|
|
|
|
print()
|
|
print("3. Dropping resources table...")
|
|
try:
|
|
db.session.execute(text("""DROP TABLE IF EXISTS resource CASCADE"""))
|
|
print(" ✓ Resources removed (with cascading deletes)")
|
|
except Exception as e:
|
|
print(f" ✗ Error removing resources: {e}")
|
|
|
|
print()
|
|
print("-" * 60)
|
|
print("Cleanup completed!")
|
|
print("-" * 60)
|
|
|
|
# Re-import models to clear references from deleted tables
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |