rebranded to BIT
This commit is contained in:
37
backend/migrate_add_is_archived.py
Normal file
37
backend/migrate_add_is_archived.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Migration script to add is_archived column to existing projects.
|
||||
Run this once if you have an existing database.
|
||||
"""
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
# Get the database path
|
||||
db_path = os.path.join(os.path.dirname(__file__), 'bit.db')
|
||||
|
||||
if not os.path.exists(db_path):
|
||||
print(f"Database not found at {db_path}")
|
||||
print("No migration needed - new database will be created with the correct schema.")
|
||||
exit(0)
|
||||
|
||||
# Connect to the database
|
||||
conn = sqlite3.connect(db_path)
|
||||
cursor = conn.cursor()
|
||||
|
||||
try:
|
||||
# Check if the column already exists
|
||||
cursor.execute("PRAGMA table_info(projects)")
|
||||
columns = [column[1] for column in cursor.fetchall()]
|
||||
|
||||
if 'is_archived' in columns:
|
||||
print("Column 'is_archived' already exists. Migration not needed.")
|
||||
else:
|
||||
# Add the is_archived column
|
||||
cursor.execute("ALTER TABLE projects ADD COLUMN is_archived BOOLEAN NOT NULL DEFAULT 0")
|
||||
conn.commit()
|
||||
print("Successfully added 'is_archived' column to projects table.")
|
||||
print("All existing projects have been set to is_archived=False (0).")
|
||||
except Exception as e:
|
||||
print(f"Error during migration: {e}")
|
||||
conn.rollback()
|
||||
finally:
|
||||
conn.close()
|
||||
Reference in New Issue
Block a user