File size: 836 Bytes
d9c16aa | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #!/usr/bin/env python3
"""
One-time script to set is_admin flag for existing admin user(s)
Run this after adding the is_admin column to the database
"""
import sys
import os
# Add parent directory to path so we can import app
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from app import db
from models import User
def main():
print("Setting admin flag for existing admin users...")
# Find the admin user
admin_user = User.query.filter_by(username='admin').first()
if admin_user:
admin_user.is_admin = True
db.session.commit()
print(f"Updated user {admin_user.username} (ID: {admin_user.id}) - admin flag set to True")
else:
print("Warning: No 'admin' user found in the database")
print("Done!")
if __name__ == "__main__":
main()
|