kinda working safe point
This commit is contained in:
parent
b9a82af12f
commit
6dda02141e
31 changed files with 4302 additions and 2937 deletions
29
app/migrations/add_folder_id_to_files.py
Normal file
29
app/migrations/add_folder_id_to_files.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
"""
|
||||
Migration script to add folder_id column to files table
|
||||
"""
|
||||
from flask import Flask
|
||||
from app import create_app, db
|
||||
from app.models import File, Folder
|
||||
|
||||
def run_migration():
|
||||
"""Add folder_id column to files table if it doesn't exist"""
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
# Check if the column exists
|
||||
from sqlalchemy import inspect
|
||||
inspector = inspect(db.engine)
|
||||
columns = [col['name'] for col in inspector.get_columns('files')]
|
||||
|
||||
if 'folder_id' not in columns:
|
||||
print("Adding folder_id column to files table...")
|
||||
# Add the column
|
||||
db.engine.execute('ALTER TABLE files ADD COLUMN folder_id INTEGER;')
|
||||
# Add foreign key constraint
|
||||
db.engine.execute('ALTER TABLE files ADD CONSTRAINT fk_files_folder_id FOREIGN KEY (folder_id) REFERENCES folders (id);')
|
||||
print("Column added successfully!")
|
||||
else:
|
||||
print("folder_id column already exists")
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_migration()
|
Loading…
Add table
Add a link
Reference in a new issue