bunch of migration files, iteration 1
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
-- internal/db/migrations/2026_00_00_000000_create_audit_log_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "audit_log" ------------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "audit_log" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"initiated_by" Integer NOT NULL,
|
||||||
|
"webhook_action" Boolean NOT NULL DEFAULT FALSE,
|
||||||
|
"resource_type" Text NOT NULL,
|
||||||
|
"resource_id" Integer NOT NULL,
|
||||||
|
"action_type" Text NOT NULL,
|
||||||
|
"summary" Text,
|
||||||
|
"previous_values" Text,
|
||||||
|
"new_values" Text
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- CREATE INDEX "idx_audit_resource" ---------------------------
|
||||||
|
CREATE INDEX IF NOT EXISTS "idx_audit_resource"
|
||||||
|
ON "audit_log" ( "resource_type", "resource_id" )
|
||||||
|
;
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- CREATE INDEX "idx_audit_initiator" --------------------------
|
||||||
|
CREATE INDEX IF NOT EXISTS "idx_audit_initiator"
|
||||||
|
ON "audit_log" ( "initiated_by", "created_at" )
|
||||||
|
;
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- CREATE INDEX "idx_audit_created" ----------------------------
|
||||||
|
CREATE INDEX IF NOT EXISTS "idx_audit_created"
|
||||||
|
ON "audit_log" ( "created_at" )
|
||||||
|
;
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000000_create_users_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "users" ----------------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "users" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"username" Text NOT NULL,
|
||||||
|
"is_admin" Boolean DEFAULT FALSE,
|
||||||
|
"name" Text NOT NULL,
|
||||||
|
"email" Text NOT NULL,
|
||||||
|
"password" Text,
|
||||||
|
"avatar_url" Text,
|
||||||
|
"provider" Text NOT NULL DEFAULT 'local',
|
||||||
|
"provider_id" Text,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" DateTime,
|
||||||
|
"deleted_at" DateTime,
|
||||||
|
CONSTRAINT "unique_username" UNIQUE ( username ),
|
||||||
|
CONSTRAINT "unique_email" UNIQUE ( email ) );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- CREATE INDEX "idx_users_provider" ---------------------------
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS "idx_users_provider"
|
||||||
|
ON "users"( "provider", "provider_id" )
|
||||||
|
WHERE "provider_id" IS NOT NULL;
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- INSERT "SYSTEM" USER ----------------------------------------
|
||||||
|
INSERT INTO `users`
|
||||||
|
(`username`,`is_admin`,`name`,`email`,`avatar_url`)
|
||||||
|
VALUES
|
||||||
|
("system", true, "System User", "system@localhost", "")
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- INSERT "ZOMBIE" USER ----------------------------------------
|
||||||
|
INSERT INTO `users`
|
||||||
|
(`username`,`is_admin`,`name`,`email`,`avatar_url`)
|
||||||
|
VALUES
|
||||||
|
("zombie", false, "Zombie", "zombie@localhost", "")
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000010_create_projects_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "projects" ------------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "projects"(
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"creator_id" Integer NOT NULL,
|
||||||
|
"owner_id" Integer NOT NULL,
|
||||||
|
"git_repository_url" Text,
|
||||||
|
"title" Text NOT NULL,
|
||||||
|
"description" Text,
|
||||||
|
"status" Text,
|
||||||
|
"priority" Text,
|
||||||
|
"start_date" DateTime,
|
||||||
|
"target_date" DateTime,
|
||||||
|
"completed_at" DateTime,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" DateTime,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000011_create_project_user_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "project_user" ---------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "project_user" (
|
||||||
|
"project_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"invited_by_user_id" Integer,
|
||||||
|
"role" Text NOT NULL DEFAULT 'member',
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime,
|
||||||
|
CONSTRAINT "idx_project_user" UNIQUE ( project_id, user_id ) );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000011_create_project_labels_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "project_labels" -------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "project_labels" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"project_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"label" Text NOT NULL,
|
||||||
|
"color" Text NOT NULL DEFAULT '#42f5ce',
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime,
|
||||||
|
CONSTRAINT "idx_project_labels" UNIQUE ( project_id, label ) );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000013_create_project_links_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "project_links" --------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "project_links" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"project_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"remote_url" Text NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000014_create_project_attachments_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "project_attachments" --------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "project_attachments" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"project_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"path" TEXT NOT NULL,
|
||||||
|
"preview_path" TEXT NOT NULL,
|
||||||
|
"filesize" Integer NOT NULL DEFAULT 0,
|
||||||
|
"mimetype" TEXT NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000015_create_project_favorites_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "project_favorites" ----------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "project_favorites" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"project_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"favorited_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime,
|
||||||
|
CONSTRAINT "idx_project_user" UNIQUE ( project_id, user_id ) );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
-- internal/db/migrations/2026_01_00_000007_create_project_dependencies_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "project_dependencies" -----------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "project_dependencies" (
|
||||||
|
"source_project_id" Integer NOT NULL,
|
||||||
|
"blocking_project_id" Integer NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT "idx_dependant_project" UNIQUE ( source_project_id, blocking_project_id )
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000020_create_issues_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issues" ---------------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issues" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"creator_id" Integer NOT NULL,
|
||||||
|
"assignee_id" Integer,
|
||||||
|
"project_id" Integer NOT NULL,
|
||||||
|
"project_issue_id" Integer NOT NULL,
|
||||||
|
"title" Text,
|
||||||
|
"description" Text,
|
||||||
|
"status" Text,
|
||||||
|
"priority" Text,
|
||||||
|
"start_date" DateTime,
|
||||||
|
"target_date" DateTime,
|
||||||
|
"completed_at" DateTime,
|
||||||
|
"parent_issue_id" Integer,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" DateTime,
|
||||||
|
"deleted_at" DateTime,
|
||||||
|
CONSTRAINT "uni_project_issue_id" UNIQUE ( project_id, project_issue_id )
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- CREATE INDEX "index_creator_id" -----------------------------
|
||||||
|
CREATE INDEX IF NOT EXISTS "index_creator_id" ON "issues"( "creator_id" );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- CREATE INDEX "index_project_id" -----------------------------
|
||||||
|
CREATE INDEX IF NOT EXISTS "index_project_id" ON "issues"( "project_id" );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
|
-- CREATE INDEX "index_assignee_id" ----------------------------
|
||||||
|
CREATE INDEX IF NOT EXISTS "index_assignee_id" ON "issues"( "assignee_id" );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000021_create_issue_labels_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issue_labels" ---------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issue_labels" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"issue_id" Integer NOT NULL,
|
||||||
|
"project_label_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime,
|
||||||
|
CONSTRAINT "idx_issue_labels" UNIQUE ( issue_id, project_label_id ) );
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000022_create_issue_links_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issue_links" ----------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issue_links" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"issue_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"remote_url" Text NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000023_create_issue_attachments_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issue_attachments" ----------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issue_attachments" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"issue_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"path" TEXT NOT NULL,
|
||||||
|
"preview_path" TEXT NOT NULL,
|
||||||
|
"filesize" Integer NOT NULL DEFAULT 0,
|
||||||
|
"mimetype" TEXT NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000005_create_issue_blockers_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issue_blockers" -------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issue_blockers" (
|
||||||
|
"source_issue_id" Integer NOT NULL,
|
||||||
|
"blocking_issue_id" Integer NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT "idx_blocking_issue" UNIQUE ( source_issue_id, blocking_issue_id )
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000024_create_issue_comments_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issue_comments" -------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issue_comments" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"issue_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"body" TEXT NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updated_at" DateTime,
|
||||||
|
"resolved_at" DateTime,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000106_create_issue_comment_links_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issue_comment_links" --------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issue_comment_links" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"issue_comment_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"remote_url" Text NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
-- internal/db/migrations/2026_01_01_000107_create_issue_comment_attachments_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "issue_comment_attachments" --------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "issue_comment_attachments" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"issue_comment_id" Integer NOT NULL,
|
||||||
|
"user_id" Integer NOT NULL,
|
||||||
|
"path" TEXT NOT NULL,
|
||||||
|
"preview_path" TEXT NOT NULL,
|
||||||
|
"filesize" Integer NOT NULL DEFAULT 0,
|
||||||
|
"mimetype" TEXT NOT NULL,
|
||||||
|
"created_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"deleted_at" DateTime
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
-- internal/db/migrations/2026_01_02_000001_create_webhook_receipts_table.sql
|
||||||
|
|
||||||
|
-- CREATE TABLE "webhook_receipts" -------------------------------
|
||||||
|
CREATE TABLE IF NOT EXISTS "webhook_receipts" (
|
||||||
|
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||||
|
"raw_payload" Text NOT NULL,
|
||||||
|
"source" Text NOT NULL,
|
||||||
|
"event_type" Text NOT NULL,
|
||||||
|
"delivery_id" Text NOT NULL,
|
||||||
|
"received_at" DateTime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"processing_status" Text NOT NULL DEFAULT 'pending',
|
||||||
|
"failure_reason" Text,
|
||||||
|
CONSTRAINT "unique_delivery_id" UNIQUE ( delivery_id )
|
||||||
|
);
|
||||||
|
-- -------------------------------------------------------------
|
||||||
|
|
||||||
Reference in New Issue
Block a user