Download migrate_to_workspaces.py from Roccuss/RAG-ITS: direct link, hf CLI and curl.
- Browser
- Download file 1.98 kB
-
https://huggingface.co/spaces/Roccuss/RAG-ITS/resolve/main/migrate_to_workspaces.py
- Command line
-
hf download hf://spaces/Roccuss/RAG-ITS/migrate_to_workspaces.py
-
curl -L -o migrate_to_workspaces.py https://huggingface.co/spaces/Roccuss/RAG-ITS/resolve/main/migrate_to_workspaces.py
1.98 kB
| """ | |
| Migration script to add workspace support | |
| Creates default workspace and migrates existing data | |
| """ | |
| from flask import Flask | |
| from database import db, Workspace, HistoricalEmail, EnrollmentDocument, Correction | |
| import config | |
| app = Flask(__name__) | |
| app.config['SQLALCHEMY_DATABASE_URI'] = config.DATABASE_URL | |
| app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False | |
| db.init_app(app) | |
| with app.app_context(): | |
| print("\nπ Starting workspace migration...") | |
| # Create all tables (including new Workspace table) | |
| db.create_all() | |
| print("β Database tables created/updated") | |
| # Check if default workspace exists | |
| default_workspace = Workspace.query.filter_by(id=1).first() | |
| if not default_workspace: | |
| # Create default workspace | |
| default_workspace = Workspace( | |
| id=1, | |
| title="ITS Maker Academy", | |
| emoji="π", | |
| color="#1976d2", | |
| is_active=True | |
| ) | |
| db.session.add(default_workspace) | |
| db.session.commit() | |
| print("β Created default workspace: ITS Maker Academy π") | |
| else: | |
| print(f"β Default workspace already exists: {default_workspace.title}") | |
| # Update existing records to link to default workspace | |
| # (The default=1 in the schema handles this, but we ensure it explicitly) | |
| historical_count = HistoricalEmail.query.filter_by(workspace_id=1).count() | |
| documents_count = EnrollmentDocument.query.filter_by(workspace_id=1).count() | |
| corrections_count = Correction.query.filter_by(workspace_id=1).count() | |
| print(f"\nπ Default workspace contents:") | |
| print(f" - Historical Emails: {historical_count}") | |
| print(f" - Enrollment Documents: {documents_count}") | |
| print(f" - Corrections: {corrections_count}") | |
| print("\nβ Migration completed successfully!") | |
| print(" You can now create additional workspaces from the dashboard.\n") | |