collabrix/scripts/add_snippet_department_table.py
DGSoft 93b98cfb5c Initial commit: Team Chat System with Code Snippet Library
- Complete chat application similar to Microsoft Teams
- Code snippet library with syntax highlighting
- Real-time messaging with WebSockets
- File upload with Office integration
- Department-based permissions
- Dark/Light theme support
- Production deployment with SSL/Reverse Proxy
- Docker containerization
- PostgreSQL database with SQLModel ORM
2025-12-09 22:25:03 +01:00

47 lines
1.3 KiB
Python

#!/usr/bin/env python3
"""
Add snippet_department table for department-based snippet access control
"""
import psycopg2
from psycopg2 import sql
def main():
# Database connection details
db_config = {
'host': '192.168.0.19',
'database': 'OfficeDesk',
'user': 'postgres',
'password': 'your_password'
}
try:
# Connect to database
conn = psycopg2.connect(**db_config)
cursor = conn.cursor()
# Create snippet_department table
cursor.execute("""
CREATE TABLE IF NOT EXISTS snippet_department (
snippet_id INTEGER NOT NULL REFERENCES snippet(id) ON DELETE CASCADE,
department_id INTEGER NOT NULL REFERENCES department(id) ON DELETE CASCADE,
enabled BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (snippet_id, department_id)
);
""")
print("✅ snippet_department table created successfully!")
# Commit changes
conn.commit()
cursor.close()
conn.close()
except Exception as e:
print(f"❌ Error: {e}")
return
if __name__ == "__main__":
main()