Forge
csharp3407750f
1using AgentForge.Abstractions;
2
3namespace AgentForge.Plugin.Ci;
4
5internal static class ForgeCiSchemaBootstrap
6{
7 internal static void Apply(IForgeMigrationContext context)
8 {
9 if (!context.TableExists("ci_definitions"))
10 {
11 context.ExecuteSql("""
12 CREATE TABLE "ci_definitions" (
13 "Id" TEXT NOT NULL PRIMARY KEY,
14 "RepoId" TEXT NOT NULL,
15 "Name" TEXT NOT NULL,
16 "BodyJson" TEXT NOT NULL,
17 "CreatedAt" TEXT NOT NULL,
18 "UpdatedAt" TEXT NOT NULL,
19 "CreatedBy" TEXT NOT NULL DEFAULT '',
20 FOREIGN KEY ("RepoId") REFERENCES "repos" ("Id") ON DELETE CASCADE,
21 UNIQUE ("RepoId", "Name")
22 );
23 """);
24
25 context.ExecuteSql("""
26 CREATE INDEX "IX_ci_definitions_RepoId" ON "ci_definitions" ("RepoId");
27 """);
28 }
29
30 if (!context.TableExists("ci_pipeline_runs"))
31 {
32 context.ExecuteSql("""
33 CREATE TABLE "ci_pipeline_runs" (
34 "Id" TEXT NOT NULL PRIMARY KEY,
35 "RepoId" TEXT NOT NULL,
36 "DefinitionName" TEXT NOT NULL,
37 "Ref" TEXT NOT NULL DEFAULT 'main',
38 "Commit" TEXT NOT NULL DEFAULT '',
39 "MrNumber" INTEGER NULL,
40 "Status" TEXT NOT NULL DEFAULT 'pending',
41 "PlanJson" TEXT NOT NULL,
42 "QueuedBy" TEXT NOT NULL DEFAULT '',
43 "CreatedAt" TEXT NOT NULL,
44 "UpdatedAt" TEXT NOT NULL,
45 "StartedAt" TEXT NULL,
46 "FinishedAt" TEXT NULL,
47 FOREIGN KEY ("RepoId") REFERENCES "repos" ("Id") ON DELETE CASCADE
48 );
49 """);
50
51 context.ExecuteSql("""
52 CREATE INDEX "IX_ci_pipeline_runs_RepoId" ON "ci_pipeline_runs" ("RepoId");
53 """);
54
55 context.ExecuteSql("""
56 CREATE INDEX "IX_ci_pipeline_runs_RepoId_CreatedAt" ON "ci_pipeline_runs" ("RepoId", "CreatedAt");
57 """);
58 }
59
60 if (!context.TableExists("ci_step_runs"))
61 {
62 context.ExecuteSql("""
63 CREATE TABLE "ci_step_runs" (
64 "Id" TEXT NOT NULL PRIMARY KEY,
65 "RunId" TEXT NOT NULL,
66 "NodeId" TEXT NOT NULL,
67 "TaskId" TEXT NOT NULL,
68 "DisplayName" TEXT NOT NULL,
69 "OrderIndex" INTEGER NOT NULL,
70 "Status" TEXT NOT NULL DEFAULT 'pending',
71 "LogText" TEXT NOT NULL DEFAULT '',
72 "StartedAt" TEXT NULL,
73 "FinishedAt" TEXT NULL,
74 FOREIGN KEY ("RunId") REFERENCES "ci_pipeline_runs" ("Id") ON DELETE CASCADE,
75 UNIQUE ("RunId", "OrderIndex")
76 );
77 """);
78
79 context.ExecuteSql("""
80 CREATE INDEX "IX_ci_step_runs_RunId" ON "ci_step_runs" ("RunId");
81 """);
82 }
83
84 context.ApplyPendingMigrations();
85 }
86}
87
View only · write via MCP/CIDE