Implements a comprehensive relational schema for storing GitLab data with full audit trail and raw payload preservation. Migration 001_initial.sql establishes core metadata tables: - projects: Tracked GitLab projects with paths and namespace - sync_watermarks: Cursor-based incremental sync state per project - schema_migrations: Migration tracking with checksums for integrity Migration 002_issues.sql creates the issues data model: - issues: Core issue data with timestamps, author, state, counts - labels: Project-specific label definitions with colors/descriptions - issue_labels: Many-to-many junction for issue-label relationships - milestones: Project milestones with state and due dates - discussions: Threaded discussions linked to issues/MRs - notes: Individual notes within discussions with full metadata - raw_payloads: Compressed original API responses keyed by entity Migration 003_indexes.sql adds performance indexes: - Covering indexes for common query patterns (state, updated_at) - Composite indexes for filtered queries (project + state) Migration 004_discussions_payload.sql extends discussions: - Adds raw_payload column for discussion-level API preservation - Enables debugging and data recovery from original responses Migration 005_assignees_milestone_duedate.sql completes the model: - issue_assignees: Many-to-many for multiple assignees per issue - Adds milestone_id, due_date columns to issues table - Indexes for assignee and milestone filtering Schema supports both incremental sync and full historical queries. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
44 lines
1.8 KiB
SQL
44 lines
1.8 KiB
SQL
-- Migration 005: Add assignees, milestone, and due_date support
|
|
-- Schema version: 5
|
|
|
|
-- Add new columns to issues table
|
|
ALTER TABLE issues ADD COLUMN due_date TEXT; -- YYYY-MM-DD format, nullable
|
|
ALTER TABLE issues ADD COLUMN milestone_id INTEGER; -- Local milestone ID (FK to milestones.id)
|
|
ALTER TABLE issues ADD COLUMN milestone_title TEXT; -- Denormalized for quick display
|
|
|
|
-- Milestones table (captures key fields for filtering and display)
|
|
CREATE TABLE IF NOT EXISTS milestones (
|
|
id INTEGER PRIMARY KEY,
|
|
gitlab_id INTEGER NOT NULL,
|
|
project_id INTEGER NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
|
iid INTEGER NOT NULL, -- Project-scoped milestone number
|
|
title TEXT NOT NULL,
|
|
description TEXT,
|
|
state TEXT, -- 'active' or 'closed'
|
|
due_date TEXT, -- YYYY-MM-DD
|
|
web_url TEXT,
|
|
UNIQUE(project_id, gitlab_id)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_milestones_project ON milestones(project_id);
|
|
CREATE INDEX IF NOT EXISTS idx_milestones_state ON milestones(project_id, state);
|
|
|
|
-- Issue assignees junction table (issues can have multiple assignees)
|
|
CREATE TABLE IF NOT EXISTS issue_assignees (
|
|
issue_id INTEGER NOT NULL REFERENCES issues(id) ON DELETE CASCADE,
|
|
username TEXT NOT NULL,
|
|
PRIMARY KEY (issue_id, username)
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_issue_assignees_username ON issue_assignees(username);
|
|
|
|
-- Index for due_date filtering
|
|
CREATE INDEX IF NOT EXISTS idx_issues_due_date ON issues(due_date);
|
|
|
|
-- Index for milestone filtering
|
|
CREATE INDEX IF NOT EXISTS idx_issues_milestone ON issues(milestone_id);
|
|
|
|
-- Update schema version
|
|
INSERT INTO schema_version (version, applied_at, description)
|
|
VALUES (5, strftime('%s', 'now') * 1000, 'Add assignees, milestone, and due_date support');
|