72 lines
No EOL
2.1 KiB
Markdown
Executable file
72 lines
No EOL
2.1 KiB
Markdown
Executable file
# Legacy Folder Migration Script
|
|
|
|
## Purpose
|
|
This script migrates legacy folders to be compatible with the hierarchy system by adding missing fields required for drag & drop functionality.
|
|
|
|
## The Problem
|
|
Legacy folders created before the hierarchy feature lack the `level` field, which causes:
|
|
- `folder.level === 0` to evaluate as `false`
|
|
- `canReceiveDrop` to be disabled
|
|
- Drag & drop functionality to not work
|
|
|
|
## The Solution
|
|
The script adds these required fields to legacy folders:
|
|
- `level: 0` (makes them root folders)
|
|
- `parent_folder_id: null`
|
|
- `created_by: <user_id>` (if missing)
|
|
- `created_at: <timestamp>` (if missing)
|
|
- `updated_at: <timestamp>`
|
|
|
|
## Usage
|
|
|
|
### Dry Run (Preview Changes)
|
|
```bash
|
|
source venv/bin/activate
|
|
MONGO_PORT=27020 python migrate_legacy_folders.py --dry-run
|
|
```
|
|
|
|
### Execute Migration
|
|
```bash
|
|
source venv/bin/activate
|
|
MONGO_PORT=27020 python migrate_legacy_folders.py
|
|
```
|
|
|
|
## Environment Variables
|
|
- `MONGO_PORT`: MongoDB port (default: 27017, but our setup uses 27020)
|
|
- `MONGO_HOST`: MongoDB host (default: localhost)
|
|
- `MONGO_USER`: MongoDB username (optional)
|
|
- `MONGO_PASS`: MongoDB password (optional)
|
|
|
|
## Output Example
|
|
```
|
|
=== Legacy Folder Migration Script ===
|
|
Mode: DRY RUN
|
|
Connecting to MongoDB...
|
|
Connected to MongoDB without authentication
|
|
Looking up user ID for username 'user'...
|
|
Found user ID: 68ad9c39e191a669e9b40701
|
|
Searching for legacy folders...
|
|
Found 1 legacy folder(s) to migrate:
|
|
- gen prompts test (ID: 68adf75bfa4b13bb59140ce5)
|
|
|
|
--- DRY RUN MODE - No actual changes will be made ---
|
|
|
|
[1/1] Processing folder: gen prompts test
|
|
Adding level: 0
|
|
Adding parent_folder_id: None
|
|
[DRY RUN] Would update folder 'gen prompts test' with: {...}
|
|
|
|
--- MIGRATION COMPLETE ---
|
|
Successfully processed: 1/1 folders
|
|
Run without --dry-run flag to execute the actual migration.
|
|
```
|
|
|
|
## Safety Features
|
|
- Dry run mode for testing
|
|
- Detailed logging of all operations
|
|
- Graceful error handling
|
|
- Atomic database updates
|
|
- Verification that all changes were successful
|
|
|
|
## After Migration
|
|
Once the script runs successfully, all legacy folders will have proper drag & drop functionality in the UI. |