83 lines
2.2 KiB
Python
83 lines
2.2 KiB
Python
"""
|
|
Quick Migration - Add is_admin column to users table
|
|
"""
|
|
|
|
import sqlite3
|
|
import os
|
|
|
|
def find_database():
|
|
"""Find the database file."""
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
possible_paths = [
|
|
os.path.join(script_dir, 'instance', 'lego_instructions.db'),
|
|
os.path.join(script_dir, 'lego_instructions.db'),
|
|
os.path.join(script_dir, 'app', 'lego_instructions.db'),
|
|
]
|
|
|
|
for path in possible_paths:
|
|
if os.path.exists(path):
|
|
return path
|
|
|
|
return None
|
|
|
|
def main():
|
|
db_path = find_database()
|
|
|
|
if not db_path:
|
|
print("=" * 70)
|
|
print("❌ Database not found!")
|
|
print("=" * 70)
|
|
return
|
|
|
|
print("=" * 70)
|
|
print("Quick Migration - Adding is_admin Column")
|
|
print("=" * 70)
|
|
print()
|
|
print(f"Database: {db_path}")
|
|
print()
|
|
|
|
try:
|
|
conn = sqlite3.connect(db_path)
|
|
cursor = conn.cursor()
|
|
|
|
# Check if column exists
|
|
cursor.execute("PRAGMA table_info(users)")
|
|
columns = [col[1] for col in cursor.fetchall()]
|
|
|
|
if 'is_admin' in columns:
|
|
print("✅ Column 'is_admin' already exists!")
|
|
print(" No migration needed.")
|
|
else:
|
|
print("Adding 'is_admin' column...")
|
|
cursor.execute("""
|
|
ALTER TABLE users
|
|
ADD COLUMN is_admin BOOLEAN DEFAULT 0 NOT NULL
|
|
""")
|
|
conn.commit()
|
|
print("✅ Successfully added 'is_admin' column!")
|
|
|
|
# Try to add index
|
|
try:
|
|
cursor.execute("CREATE INDEX idx_users_is_admin ON users(is_admin)")
|
|
conn.commit()
|
|
print("✅ Created index on is_admin column!")
|
|
except sqlite3.OperationalError:
|
|
print(" (Index already exists)")
|
|
|
|
conn.close()
|
|
|
|
print()
|
|
print("=" * 70)
|
|
print("Migration complete!")
|
|
print("=" * 70)
|
|
print()
|
|
print("Next step: Run check_admin.py to make jessikitty an admin")
|
|
print()
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error: {e}")
|
|
return
|
|
|
|
if __name__ == "__main__":
|
|
main()
|