AttendAIPro / update_users.py
ashrithagowthami's picture
Upload 2277 files
f759742 verified
Raw
History Blame Contribute Delete
996 Bytes
import sqlite3
import uuid
conn = sqlite3.connect('database.sqlite')
c = conn.cursor()
c.execute("SELECT id, email, name, role FROM users")
users = c.fetchall()
target_email = 'ramavathnithinnaik5@gmail.com'
found = False
for u in users:
print(u)
if u[1] == target_email:
found = True
if not found:
print(f"User {target_email} not found. Inserting default user as admin.")
new_id = str(uuid.uuid4())
c.execute("INSERT INTO users (id, email, name, role, is_active) VALUES (?, ?, ?, ?, ?)",
(new_id, target_email, 'Ramavath Nithin Naik', 'system_admin', 1))
# Try admin if system_admin is not what we want, but wait, the roles in db are admin, student, teacher. Let me insert as admin
c.execute("UPDATE users SET role='admin' WHERE id=?", (new_id,))
conn.commit()
print("User inserted.")
else:
c.execute("UPDATE users SET role='admin' WHERE email=?", (target_email,))
conn.commit()
print("User role updated to admin.")