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