#!/usr/bin/env python3 """ Migration script to create Kanban checklist tables """ 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(): """Create Kanban checklist tables""" with engine.connect() as conn: # Check if tables already exist result = conn.execute(text(""" SELECT table_name FROM information_schema.tables WHERE table_schema = 'public' AND table_name IN ('kanban_checklist', 'kanban_checklist_item') """)) existing_tables = [row[0] for row in result.fetchall()] if 'kanban_checklist' in existing_tables: print("✅ Kanban checklist tables already exist") return # Create kanban_checklist table conn.execute(text(""" CREATE TABLE kanban_checklist ( id SERIAL PRIMARY KEY, card_id INTEGER NOT NULL REFERENCES kanban_card(id) ON DELETE CASCADE, title VARCHAR NOT NULL, position INTEGER DEFAULT 0, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP ) """)) # Create kanban_checklist_item table conn.execute(text(""" CREATE TABLE kanban_checklist_item ( id SERIAL PRIMARY KEY, checklist_id INTEGER NOT NULL REFERENCES kanban_checklist(id) ON DELETE CASCADE, title VARCHAR NOT NULL, is_completed BOOLEAN DEFAULT FALSE, position INTEGER DEFAULT 0, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP ) """)) # Create indexes conn.execute(text(""" CREATE INDEX idx_kanban_checklist_card_id ON kanban_checklist(card_id) """)) conn.execute(text(""" CREATE INDEX idx_kanban_checklist_item_checklist_id ON kanban_checklist_item(checklist_id) """)) conn.commit() print("✅ Kanban checklist tables created successfully") if __name__ == "__main__": migrate()