Skip to content
78 linesCodeBlameRaw
1//! A workspace renamed: rows kept under its old slug move to the one it
2//! has now. See `g1t_kit::rename`.
3
4/// `?1` is the current slug, `?2` a stale one.
5pub const STATEMENTS: &[&str] = &[
6 "UPDATE settings SET owner = ?1 WHERE scope = 'workspace' AND owner = ?2",
7 "UPDATE jobs SET namespace = ?1 WHERE namespace = ?2",
8 "UPDATE cache_entries SET namespace = ?1 WHERE namespace = ?2",
9 "UPDATE cache_days SET namespace = ?1 WHERE namespace = ?2",
10 "UPDATE artifacts SET namespace = ?1 WHERE namespace = ?2",
11 "UPDATE workspace_actions_settings SET namespace = ?1 WHERE namespace = ?2",
12 "UPDATE workflows SET repo = ?1 || substr(repo, length(?2) + 1) WHERE substr(repo, 1, length(?2) + 1) = ?2 || '/'",
13 "UPDATE runs SET repo = ?1 || substr(repo, length(?2) + 1) WHERE substr(repo, 1, length(?2) + 1) = ?2 || '/'",
14];
15
16/// A repository renamed or transferred (see `g1t_kit::transfer`): its
17/// workflows, its runs and their jobs go with it. Its own secrets and
18/// variables are kept by its id (or its project's), so they go with it
19/// too; the old workspace's stop reaching it. A workspace's rows name the
20/// projects they reach by slug, not repositories, so a rename leaves them.
21pub const TRANSFERRED: &[&str] = &[
22 "UPDATE workflows SET repo = ?1 WHERE repo_id = ?5 AND repo = ?2",
23 "UPDATE runs SET repo = ?1 WHERE repo_id = ?5 AND repo = ?2",
24 "UPDATE jobs SET namespace = ?3 WHERE repo_id = ?5 AND namespace = ?4",
25 "UPDATE cache_entries SET namespace = ?3 WHERE repo_id = ?5 AND namespace = ?4",
26 "UPDATE artifacts SET namespace = ?3 WHERE repo_id = ?5 AND namespace = ?4",
27];
28
29/// A repository purged (see `g1t_kit::lifecycle`): its workflows, runs,
30/// jobs and their logs go, and secrets and variables still kept under its
31/// id (from before projects held them). `?1` its id. A project's own rows
32/// stay with the project.
33pub const PURGED: &[&str] = &[
34 "DELETE FROM logs WHERE job_id IN (SELECT id FROM jobs WHERE repo_id = ?1)",
35 "DELETE FROM jobs WHERE repo_id = ?1",
36 "DELETE FROM runs WHERE repo_id = ?1",
37 "DELETE FROM workflows WHERE repo_id = ?1",
38 "DELETE FROM synced WHERE repo_id = ?1",
39 "DELETE FROM settings WHERE scope <> 'workspace' AND owner = ?1",
40 "DELETE FROM environments WHERE repo_id = ?1",
41 "DELETE FROM environment_gates WHERE repo_id = ?1",
42 // Its cache's objects are deleted from R2 by the next sweep, then the rows.
43 "UPDATE cache_entries SET status = 'expired' WHERE repo_id = ?1",
44 // Its artifacts too, and its own settings.
45 "UPDATE artifacts SET status = 'expired' WHERE repo_id = ?1",
46 "DELETE FROM repo_settings WHERE repo_id = ?1",
47];
48
49/// A workspace deleted: its own secrets and variables go. `?1` its slug.
50pub const DELETED: &[&str] = &[
51 "DELETE FROM settings WHERE scope = 'workspace' AND owner = ?1",
52 "DELETE FROM workspace_actions_settings WHERE namespace = ?1",
53];
54
55#[cfg(test)]
56mod tests {
57 use super::{DELETED, PURGED, STATEMENTS, TRANSFERRED};
58
59 #[test]
60 fn every_statement_takes_the_two_slugs() {
61 for sql in STATEMENTS {
62 assert_eq!(g1t_kit::rename::parameters(sql), 2, "{sql}");
63 }
64 }
65
66 #[test]
67 fn transfer_and_deletion_statements_take_what_they_name() {
68 for sql in TRANSFERRED {
69 assert!((1..=5).contains(&g1t_kit::transfer::parameters(sql)), "{sql}");
70 }
71 for sql in DELETED {
72 assert_eq!(g1t_kit::rename::parameters(sql), 1, "{sql}");
73 }
74 for sql in PURGED {
75 assert_eq!(g1t_kit::transfer::parameters(sql), 1, "{sql}");
76 }
77 }
78}