mirror of
https://github.com/OHV-IT/collabrix.git
synced 2025-12-16 00:58:37 +01:00
- Implement unread message indicators with Material-UI icons - Add BlinkingEnvelope component with theme-compatible colors - Create UnreadMessagesContext for managing unread states - Integrate WebSocket message handling for real-time notifications - Icons only appear for inactive channels/DMs, disappear when opened - Add test functionality (double-click to mark as unread) - Fix WebSocket URL handling for production deployment - Unify WebSocket architecture using presence connection for all messages
91 lines
3.1 KiB
Python
91 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Migration script to migrate is_admin to role column in user table
|
|
"""
|
|
import sys
|
|
import os
|
|
|
|
# Add parent directory to path to import app modules
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from sqlalchemy import text
|
|
from app.database import engine
|
|
|
|
|
|
def migrate():
|
|
"""Migrate is_admin column to role column in user table"""
|
|
with engine.connect() as conn:
|
|
# Check if role column already exists
|
|
result = conn.execute(text("""
|
|
SELECT column_name
|
|
FROM information_schema.columns
|
|
WHERE table_name='user' AND column_name='role'
|
|
"""))
|
|
|
|
if result.fetchone():
|
|
print("✅ Column 'role' already exists in user table")
|
|
# Check if is_admin column still exists
|
|
result2 = conn.execute(text("""
|
|
SELECT column_name
|
|
FROM information_schema.columns
|
|
WHERE table_name='user' AND column_name='is_admin'
|
|
"""))
|
|
if result2.fetchone():
|
|
# Migrate existing admin users
|
|
conn.execute(text("""
|
|
UPDATE "user" SET role = 'ADMIN' WHERE is_admin = true
|
|
"""))
|
|
# Set default role for non-admin users
|
|
conn.execute(text("""
|
|
UPDATE "user" SET role = 'USER' WHERE role IS NULL OR role = 'user'
|
|
"""))
|
|
# Drop the old is_admin column
|
|
conn.execute(text("""
|
|
ALTER TABLE "user" DROP COLUMN is_admin
|
|
"""))
|
|
conn.commit()
|
|
print("✅ Migrated existing data and dropped is_admin column")
|
|
else:
|
|
# Correct any wrong values
|
|
conn.execute(text("""
|
|
UPDATE "user" SET role = 'ADMIN' WHERE role = 'admin'
|
|
"""))
|
|
conn.execute(text("""
|
|
UPDATE "user" SET role = 'USER' WHERE role = 'user'
|
|
"""))
|
|
conn.execute(text("""
|
|
UPDATE "user" SET role = 'SUPERADMIN' WHERE role = 'superadmin'
|
|
"""))
|
|
conn.commit()
|
|
print("✅ Corrected role values to enum names")
|
|
return
|
|
|
|
# Add role column
|
|
conn.execute(text("""
|
|
ALTER TABLE "user" ADD COLUMN role VARCHAR(20) DEFAULT 'USER'
|
|
"""))
|
|
|
|
# Migrate existing admin users
|
|
conn.execute(text("""
|
|
UPDATE "user" SET role = 'ADMIN' WHERE is_admin = true
|
|
"""))
|
|
|
|
# Set default role for non-admin users
|
|
conn.execute(text("""
|
|
UPDATE "user" SET role = 'USER' WHERE role IS NULL
|
|
"""))
|
|
|
|
# Drop the old is_admin column
|
|
conn.execute(text("""
|
|
ALTER TABLE "user" DROP COLUMN is_admin
|
|
"""))
|
|
|
|
conn.commit() # Commit the changes
|
|
|
|
print("✅ Successfully migrated is_admin to role column")
|
|
print("✅ Existing admins have been assigned 'admin' role")
|
|
print("✅ Other users have been assigned 'user' role")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
migrate() |