WIP
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
-- Create task_status enum
|
||||
CREATE TYPE task_status AS ENUM ('todo', 'inprogress', 'done', 'cancelled');
|
||||
|
||||
-- Create users table
|
||||
CREATE TABLE users (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
email VARCHAR(255) UNIQUE NOT NULL,
|
||||
password VARCHAR(255) NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Create projects table
|
||||
CREATE TABLE projects (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
name VARCHAR(255) NOT NULL,
|
||||
owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Create tasks table
|
||||
CREATE TABLE tasks (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
project_id UUID NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
||||
title VARCHAR(255) NOT NULL,
|
||||
description TEXT,
|
||||
status task_status NOT NULL DEFAULT 'todo',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX idx_projects_owner_id ON projects(owner_id);
|
||||
CREATE INDEX idx_tasks_project_id ON tasks(project_id);
|
||||
CREATE INDEX idx_tasks_status ON tasks(status);
|
||||
|
||||
-- Create updated_at trigger function
|
||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = NOW();
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ language 'plpgsql';
|
||||
|
||||
-- Create triggers to auto-update updated_at
|
||||
CREATE TRIGGER update_users_updated_at
|
||||
BEFORE UPDATE ON users
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
CREATE TRIGGER update_projects_updated_at
|
||||
BEFORE UPDATE ON projects
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
|
||||
CREATE TRIGGER update_tasks_updated_at
|
||||
BEFORE UPDATE ON tasks
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
@@ -1,23 +0,0 @@
|
||||
-- Update users table for authentication system
|
||||
-- Add new columns and update existing ones
|
||||
|
||||
-- First, add the new columns
|
||||
ALTER TABLE users
|
||||
ADD COLUMN password_hash VARCHAR(255),
|
||||
ADD COLUMN is_admin BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
-- Update existing users to have a placeholder password hash
|
||||
-- (This is safe since there shouldn't be any real users yet)
|
||||
UPDATE users SET password_hash = '$2b$10$placeholder' WHERE password_hash IS NULL;
|
||||
|
||||
-- Make password_hash required
|
||||
ALTER TABLE users ALTER COLUMN password_hash SET NOT NULL;
|
||||
|
||||
-- Remove the old password column if it exists
|
||||
ALTER TABLE users DROP COLUMN IF EXISTS password;
|
||||
|
||||
-- Create index on email for faster lookups
|
||||
CREATE INDEX IF NOT EXISTS idx_users_email ON users(email);
|
||||
|
||||
-- Create index on is_admin for admin queries
|
||||
CREATE INDEX IF NOT EXISTS idx_users_is_admin ON users(is_admin);
|
||||
@@ -1,2 +0,0 @@
|
||||
-- Add 'inreview' to task_status enum
|
||||
ALTER TYPE task_status ADD VALUE 'inreview';
|
||||
@@ -1,2 +0,0 @@
|
||||
-- Add git_repo_path field to projects table
|
||||
ALTER TABLE projects ADD COLUMN git_repo_path VARCHAR(500) NOT NULL DEFAULT '';
|
||||
@@ -1,2 +0,0 @@
|
||||
-- Add unique constraint to git_repo_path to prevent duplicate repository paths
|
||||
ALTER TABLE projects ADD CONSTRAINT unique_git_repo_path UNIQUE (git_repo_path);
|
||||
@@ -1,33 +0,0 @@
|
||||
-- Create task_attempt_status enum
|
||||
CREATE TYPE task_attempt_status AS ENUM ('init', 'inprogress', 'paused');
|
||||
|
||||
-- Create task_attempts table
|
||||
CREATE TABLE task_attempts (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
task_id UUID NOT NULL REFERENCES tasks(id) ON DELETE CASCADE,
|
||||
worktree_path VARCHAR(255) NOT NULL,
|
||||
base_commit VARCHAR(255),
|
||||
merge_commit VARCHAR(255),
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Create task_attempt_activities table
|
||||
CREATE TABLE task_attempt_activities (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
task_attempt_id UUID NOT NULL REFERENCES task_attempts(id) ON DELETE CASCADE,
|
||||
status task_attempt_status NOT NULL DEFAULT 'init',
|
||||
note TEXT,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX idx_task_attempts_task_id ON task_attempts(task_id);
|
||||
CREATE INDEX idx_task_attempt_activities_task_attempt_id ON task_attempt_activities(task_attempt_id);
|
||||
CREATE INDEX idx_task_attempt_activities_status ON task_attempt_activities(status);
|
||||
CREATE INDEX idx_task_attempt_activities_created_at ON task_attempt_activities(created_at);
|
||||
|
||||
-- Create triggers to auto-update updated_at
|
||||
CREATE TRIGGER update_task_attempts_updated_at
|
||||
BEFORE UPDATE ON task_attempts
|
||||
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
|
||||
@@ -1,2 +0,0 @@
|
||||
-- Add executor_config column to task_attempts table
|
||||
ALTER TABLE task_attempts ADD COLUMN executor_config JSONB;
|
||||
@@ -1,4 +0,0 @@
|
||||
-- Add stdout and stderr columns to task_attempts table
|
||||
ALTER TABLE task_attempts
|
||||
ADD COLUMN stdout TEXT,
|
||||
ADD COLUMN stderr TEXT;
|
||||
@@ -1,18 +0,0 @@
|
||||
-- Change executor_config column to executor (string) in task_attempts table
|
||||
|
||||
-- Add the new executor column
|
||||
ALTER TABLE task_attempts ADD COLUMN executor TEXT;
|
||||
|
||||
-- Convert existing executor_config data to executor names
|
||||
-- This assumes the existing JSONB data has a structure we can extract from
|
||||
UPDATE task_attempts
|
||||
SET executor = CASE
|
||||
WHEN executor_config IS NULL THEN NULL
|
||||
WHEN executor_config->>'type' = 'Echo' THEN 'echo'
|
||||
WHEN executor_config->>'type' = 'Claude' THEN 'claude'
|
||||
ELSE 'echo' -- Default fallback
|
||||
END
|
||||
WHERE executor_config IS NOT NULL;
|
||||
|
||||
-- Drop the old executor_config column
|
||||
ALTER TABLE task_attempts DROP COLUMN executor_config;
|
||||
@@ -1,16 +0,0 @@
|
||||
-- Remove users table and all references to it
|
||||
|
||||
-- Drop the trigger on users table
|
||||
DROP TRIGGER IF EXISTS update_users_updated_at ON users;
|
||||
|
||||
-- Drop indexes related to users
|
||||
DROP INDEX IF EXISTS idx_users_email;
|
||||
DROP INDEX IF EXISTS idx_users_is_admin;
|
||||
|
||||
-- Drop the foreign key constraint and column from projects table
|
||||
ALTER TABLE projects DROP CONSTRAINT projects_owner_id_fkey;
|
||||
DROP INDEX IF EXISTS idx_projects_owner_id;
|
||||
ALTER TABLE projects DROP COLUMN owner_id;
|
||||
|
||||
-- Drop the users table
|
||||
DROP TABLE IF EXISTS users;
|
||||
99
backend/migrations/20250617183714_init.sql
Normal file
99
backend/migrations/20250617183714_init.sql
Normal file
@@ -0,0 +1,99 @@
|
||||
-- Turn on FK support (important for SQLite)
|
||||
PRAGMA foreign_keys = ON;
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- 1. Core lookup “enums” (via CHECK constraints)
|
||||
-------------------------------------------------------------------------------
|
||||
-- task_status values
|
||||
-- ('todo','inprogress','done','cancelled','inreview')
|
||||
|
||||
-- task_attempt_status values
|
||||
-- ('init','inprogress','paused')
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- 2. Tables
|
||||
-------------------------------------------------------------------------------
|
||||
CREATE TABLE projects (
|
||||
id TEXT PRIMARY KEY, -- supply UUID in app
|
||||
name TEXT NOT NULL,
|
||||
git_repo_path TEXT NOT NULL DEFAULT '' UNIQUE,
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE tasks (
|
||||
id TEXT PRIMARY KEY,
|
||||
project_id TEXT NOT NULL,
|
||||
title TEXT NOT NULL,
|
||||
description TEXT,
|
||||
status TEXT NOT NULL DEFAULT 'todo'
|
||||
CHECK (status IN ('todo','inprogress','done','cancelled','inreview')),
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE task_attempts (
|
||||
id TEXT PRIMARY KEY,
|
||||
task_id TEXT NOT NULL,
|
||||
worktree_path TEXT NOT NULL,
|
||||
base_commit TEXT,
|
||||
merge_commit TEXT,
|
||||
executor TEXT, -- final column name (no JSONB)
|
||||
stdout TEXT,
|
||||
stderr TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE task_attempt_activities (
|
||||
id TEXT PRIMARY KEY,
|
||||
task_attempt_id TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'init'
|
||||
CHECK (status IN ('init','inprogress','paused')),
|
||||
note TEXT,
|
||||
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (task_attempt_id) REFERENCES task_attempts(id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- 3. Indexes
|
||||
-------------------------------------------------------------------------------
|
||||
CREATE INDEX idx_tasks_project_id ON tasks(project_id);
|
||||
CREATE INDEX idx_tasks_status ON tasks(status);
|
||||
CREATE INDEX idx_task_attempts_task_id ON task_attempts(task_id);
|
||||
CREATE INDEX idx_task_attempt_activities_attempt_id ON task_attempt_activities(task_attempt_id);
|
||||
CREATE INDEX idx_task_attempt_activities_status ON task_attempt_activities(status);
|
||||
CREATE INDEX idx_task_attempt_activities_created_at ON task_attempt_activities(created_at);
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
-- 4. updated_at auto-maintenance triggers
|
||||
-- (fires only when caller hasn’t manually changed updated_at)
|
||||
-------------------------------------------------------------------------------
|
||||
-- Projects
|
||||
CREATE TRIGGER trg_projects_updated_at
|
||||
AFTER UPDATE ON projects
|
||||
FOR EACH ROW
|
||||
WHEN NEW.updated_at = OLD.updated_at
|
||||
BEGIN
|
||||
UPDATE projects SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
|
||||
-- Tasks
|
||||
CREATE TRIGGER trg_tasks_updated_at
|
||||
AFTER UPDATE ON tasks
|
||||
FOR EACH ROW
|
||||
WHEN NEW.updated_at = OLD.updated_at
|
||||
BEGIN
|
||||
UPDATE tasks SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
|
||||
-- Task attempts
|
||||
CREATE TRIGGER trg_task_attempts_updated_at
|
||||
AFTER UPDATE ON task_attempts
|
||||
FOR EACH ROW
|
||||
WHEN NEW.updated_at = OLD.updated_at
|
||||
BEGIN
|
||||
UPDATE task_attempts SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||
END;
|
||||
Reference in New Issue
Block a user