🗃️ migrate: drop tables and columns of removed features; one boot sweep deletes their leftover files (wiki repos, exports, package and OCI blobs)
Browse files at this commitac8a15b178a3942a3cb6caf677b60f8240683978Parent: 0621a317 changed files +136 -4
- crates/forge-core/migrations/0078_remove_features.sql +27 -0
- crates/forge-core/src/store/migrate.rs +4 -0
- crates/forge-git/src/repo.rs +0 -3
- crates/forge-web-app/src/leftovers.rs +102 -0
- crates/forge-web-app/src/lib.rs +1 -0
- crates/forge-web/src/boot.rs +1 -0
- docs/architecture.md +1 -1
crates/forge-core/migrations/0078_remove_features.sqladded+27 -0
| @@ -0,0 +1,27 @@ | ||
| 1 | +DROP TABLE IF EXISTS discussion_notifications; | |
| 2 | +DROP TABLE IF EXISTS discussion_comments; | |
| 3 | +DROP TABLE IF EXISTS discussions; | |
| 4 | +DROP TABLE IF EXISTS snippet_revisions; | |
| 5 | +DROP TABLE IF EXISTS snippet_files; | |
| 6 | +DROP TABLE IF EXISTS snippets; | |
| 7 | +DROP TABLE IF EXISTS advisory_notifications; | |
| 8 | +DROP TABLE IF EXISTS repo_alerts; | |
| 9 | +DROP TABLE IF EXISTS repo_dependencies; | |
| 10 | +DROP TABLE IF EXISTS advisories; | |
| 11 | +DROP TABLE IF EXISTS import_map; | |
| 12 | +DROP TABLE IF EXISTS import_events; | |
| 13 | +DROP TABLE IF EXISTS import_jobs; | |
| 14 | +DROP TABLE IF EXISTS data_exports; | |
| 15 | +DROP TABLE IF EXISTS oci_manifest_refs; | |
| 16 | +DROP TABLE IF EXISTS oci_tags; | |
| 17 | +DROP TABLE IF EXISTS oci_manifests; | |
| 18 | +DROP TABLE IF EXISTS oci_blobs; | |
| 19 | +DROP TABLE IF EXISTS package_versions; | |
| 20 | +DROP TABLE IF EXISTS packages; | |
| 21 | +DROP TABLE IF EXISTS push_subscriptions; | |
| 22 | +DROP TABLE IF EXISTS web_push_keys; | |
| 23 | +ALTER TABLE repos DROP COLUMN wiki_enabled; | |
| 24 | +ALTER TABLE repos DROP COLUMN discussions_enabled; | |
| 25 | +DELETE FROM reactions WHERE target_kind IN ('discussion', 'discussion_comment'); | |
| 26 | +DELETE FROM server_settings WHERE key LIKE 'advisories.%'; | |
| 27 | +DELETE FROM replication_status WHERE subject LIKE '%.wiki'; |
crates/forge-core/src/store/migrate.rsmodified+4 -0
| @@ -143,6 +143,10 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ | ||
| 143 | 143 | 77, |
| 144 | 144 | include_str!("../../migrations/0077_runner_stopped_at.sql"), |
| 145 | 145 | ), |
| 146 | + ( | |
| 147 | + 78, | |
| 148 | + include_str!("../../migrations/0078_remove_features.sql"), | |
| 149 | + ), | |
| 146 | 150 | ]; |
| 147 | 151 | |
| 148 | 152 | pub fn latest_schema_version() -> u32 { |
crates/forge-git/src/repo.rsmodified+0 -3
| @@ -107,9 +107,6 @@ pub fn list_trash(data_dir: &Path) -> Result<Vec<TrashEntry>> { | ||
| 107 | 107 | let Ok(deleted_at) = ts.parse::<u64>() else { |
| 108 | 108 | continue; |
| 109 | 109 | }; |
| 110 | - if id.ends_with(".wiki") { | |
| 111 | - continue; | |
| 112 | - } | |
| 113 | 110 | entries.push(TrashEntry { |
| 114 | 111 | path: path.clone(), |
| 115 | 112 | repo_id: id.to_owned(), |
crates/forge-web-app/src/leftovers.rsadded+102 -0
| @@ -0,0 +1,102 @@ | ||
| 1 | +use std::path::Path; | |
| 2 | +use std::time::SystemTime; | |
| 3 | + | |
| 4 | +use crate::state::AppState; | |
| 5 | + | |
| 6 | +const BLOB_PREFIXES: [&str; 2] = ["oci", "packages"]; | |
| 7 | + | |
| 8 | +pub fn spawn(state: AppState) { | |
| 9 | + tokio::spawn(async move { sweep(&state).await }); | |
| 10 | +} | |
| 11 | + | |
| 12 | +async fn sweep(state: &AppState) { | |
| 13 | + sweep_dirs(&state.config.data_dir).await; | |
| 14 | + sweep_blobs(state).await; | |
| 15 | +} | |
| 16 | + | |
| 17 | +async fn sweep_dirs(data_dir: &Path) { | |
| 18 | + remove_dir(&data_dir.join("exports")).await; | |
| 19 | + remove_matching(&data_dir.join(forge_git::repo::TRASH_DIR), |name| { | |
| 20 | + name.contains(".wiki-") | |
| 21 | + }) | |
| 22 | + .await; | |
| 23 | + for shard in sub_dirs(&data_dir.join("repos")).await { | |
| 24 | + for inner in sub_dirs(&shard).await { | |
| 25 | + remove_matching(&inner, |name| name.ends_with(".wiki.git")).await; | |
| 26 | + } | |
| 27 | + } | |
| 28 | +} | |
| 29 | + | |
| 30 | +async fn sweep_blobs(state: &AppState) { | |
| 31 | + for prefix in BLOB_PREFIXES { | |
| 32 | + let keys = match state.blobs.keys_older_than(prefix, SystemTime::now()).await { | |
| 33 | + Ok(keys) => keys, | |
| 34 | + Err(e) => { | |
| 35 | + tracing::error!(error = %e, prefix, "leftovers: listing blobs failed"); | |
| 36 | + continue; | |
| 37 | + } | |
| 38 | + }; | |
| 39 | + for key in keys { | |
| 40 | + if let Err(e) = state.blobs.delete(&key).await { | |
| 41 | + tracing::error!(error = %e, key, "leftovers: deleting blob failed"); | |
| 42 | + } | |
| 43 | + } | |
| 44 | + } | |
| 45 | +} | |
| 46 | + | |
| 47 | +async fn sub_dirs(dir: &Path) -> Vec<std::path::PathBuf> { | |
| 48 | + let mut dirs = Vec::new(); | |
| 49 | + let Ok(mut entries) = tokio::fs::read_dir(dir).await else { | |
| 50 | + return dirs; | |
| 51 | + }; | |
| 52 | + while let Ok(Some(entry)) = entries.next_entry().await { | |
| 53 | + if entry.file_type().await.is_ok_and(|t| t.is_dir()) { | |
| 54 | + dirs.push(entry.path()); | |
| 55 | + } | |
| 56 | + } | |
| 57 | + dirs | |
| 58 | +} | |
| 59 | + | |
| 60 | +async fn remove_matching(dir: &Path, matches: impl Fn(&str) -> bool) { | |
| 61 | + for path in sub_dirs(dir).await { | |
| 62 | + if path | |
| 63 | + .file_name() | |
| 64 | + .and_then(|n| n.to_str()) | |
| 65 | + .is_some_and(&matches) | |
| 66 | + { | |
| 67 | + remove_dir(&path).await; | |
| 68 | + } | |
| 69 | + } | |
| 70 | +} | |
| 71 | + | |
| 72 | +async fn remove_dir(path: &Path) { | |
| 73 | + match tokio::fs::remove_dir_all(path).await { | |
| 74 | + Ok(()) => tracing::info!(path = %path.display(), "leftovers: removed"), | |
| 75 | + Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} | |
| 76 | + Err(e) => tracing::error!(error = %e, path = %path.display(), "leftovers: removing failed"), | |
| 77 | + } | |
| 78 | +} | |
| 79 | + | |
| 80 | +#[cfg(test)] | |
| 81 | +mod tests { | |
| 82 | + use super::*; | |
| 83 | + | |
| 84 | + #[tokio::test] | |
| 85 | + async fn removes_wiki_repos_and_trash_but_keeps_repos() { | |
| 86 | + let dir = tempfile::tempdir().unwrap(); | |
| 87 | + let shard = dir.path().join("repos/01/ab"); | |
| 88 | + let keep = shard.join("01abcdefghjkmnpqrstvwxyz01.git"); | |
| 89 | + let wiki = shard.join("01abcdefghjkmnpqrstvwxyz01.wiki.git"); | |
| 90 | + let trash = dir.path().join("trash"); | |
| 91 | + let trash_keep = trash.join("01abcdefghjkmnpqrstvwxyz01-1.git"); | |
| 92 | + let trash_wiki = trash.join("01abcdefghjkmnpqrstvwxyz01.wiki-1.git"); | |
| 93 | + for d in [&keep, &wiki, &trash_keep, &trash_wiki] { | |
| 94 | + std::fs::create_dir_all(d).unwrap(); | |
| 95 | + } | |
| 96 | + std::fs::create_dir_all(dir.path().join("exports/x")).unwrap(); | |
| 97 | + sweep_dirs(dir.path()).await; | |
| 98 | + assert!(keep.exists() && trash_keep.exists()); | |
| 99 | + assert!(!wiki.exists() && !trash_wiki.exists()); | |
| 100 | + assert!(!dir.path().join("exports").exists()); | |
| 101 | + } | |
| 102 | +} |
crates/forge-web-app/src/lib.rsmodified+1 -0
| @@ -20,6 +20,7 @@ pub mod git_http; | ||
| 20 | 20 | pub mod hook_cmd; |
| 21 | 21 | pub mod internal; |
| 22 | 22 | pub mod layers; |
| 23 | +pub mod leftovers; | |
| 23 | 24 | pub mod lfs; |
| 24 | 25 | pub mod lfs_pointer; |
| 25 | 26 | pub mod live; |
crates/forge-web/src/boot.rsmodified+1 -0
| @@ -146,6 +146,7 @@ pub async fn serve( | ||
| 146 | 146 | forge_web_app::ci::reaper::spawn(state.clone()); |
| 147 | 147 | forge_web_app::merge_queue::spawn_resume(state.clone()); |
| 148 | 148 | forge_web_app::prune::spawn(state.clone()); |
| 149 | + forge_web_app::leftovers::spawn(state.clone()); | |
| 149 | 150 | forge_web_account::pages::admin_health::spawn_repo_size(state.clone()); |
| 150 | 151 | forge_web_app::ci::scheduled::spawn(state.clone()); |
| 151 | 152 |
docs/architecture.mdmodified+1 -1
| @@ -547,7 +547,7 @@ Known gaps: | ||
| 547 | 547 | - `range-diff` for "what changed since the last review." AGit (`refs/for/<branch>`) is considered later. |
| 548 | 548 | - Live pages: the pull list and every pull tab (conversation, commits, files) update while open. Each has an event stream (`/{o}/{r}/pulls/events`, `/{o}/{r}/pulls/{n}/events`) that sends `changed` when a write changes what the page shows. A POST under the pulls paths, a push, a commit status for the head, and a mergeability or auto-merge run each wake it. The page re-reads in place and keeps typed text, focus and open inline forms; the Files tab keeps the file in view at the same offset. Streams are in-process, event driven, and never poll. Topics live in `live.rs`; the bump helpers are in `pages/pull_live.rs`. |
| 549 | 549 | |
| 550 | -### Webhooks, push mirrors, replication, backups, export | |
| 550 | +### Webhooks, push mirrors, replication, backups | |
| 551 | 551 | |
| 552 | 552 | - Webhooks: HMAC-SHA256 signature over the raw body, delivery id header, 10s timeout, retry queue, delivery log. |
| 553 | 553 | - Pull mirrors on an interval with a minimum; push mirrors with sealed credentials, run after each push with backoff. SSRF rules from section 9 apply. |