flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/services/projects/src/rename.ts

19 lines961 bytesCodeBlame
1/**
2 * A workspace renamed: its projects move to the slug it has now. Each
3 * statement takes the current slug and one stale slug, and changes nothing
4 * once the rows have moved, so a repeated or late delivery is harmless.
5 */
6
7export type Statement = { sql: string; params: string[] };
8
9export function renameStatements(stale: string[], current: string): Statement[] {
10 return stale.flatMap((old) => [
11 // A project of the same slug made under the new name in the moment
12 // before this ran keeps its place; the older one stays put and is
13 // reported.
14 { sql: "UPDATE OR IGNORE projects SET workspace = ? WHERE workspace = ?", params: [current, old] },
15 { sql: "UPDATE projects SET repo_namespace = ? WHERE repo_namespace = ?", params: [current, old] },
16 { sql: "UPDATE OR IGNORE backfilled SET workspace = ? WHERE workspace = ?", params: [current, old] },
17 { sql: "DELETE FROM backfilled WHERE workspace = ?", params: [old] },
18 ]);
19}