#!/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()