Skip to content

Commit 719e859

Browse files
committed
app/: the downloads table (sc-8869, #47) in the domain baseline, with its model
1 parent bbcd872 commit 719e859

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

‎app/database/migrations/2026_12_03_000200_create_domain_tables.rs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! The domain tables (sc-8900, the data side), as docs/design-storage.md lays them out: organizations, projects,
22
//! builds, snapshots and their pages, page texts by hash, build groups read from earlier builds (the
3-
//! `effective_snapshots` view), baselines, renders, diffs, blobs, reviews, comments and the credit ledger.
3+
//! `effective_snapshots` view), baselines, renders, diffs, blobs, reviews, comments, bulk downloads and the credit ledger.
44
//!
55
//! Raw SQL: the schema builder has no views, partial or BRIN indexes, or lz4 compression. `parent_commits`,
66
//! `shards_finalized` and `reviews.snapshot_ids` are JSON arrays, since Laravel Rust 0.1.4 has no PostgreSQL array
@@ -1035,6 +1035,26 @@ CREATE VIEW effective_snapshots AS
10351035
-- A build's visualci.yml item is its own: never read from another build.
10361036
WHERE g.source_build_id IS NOT NULL AND s.platform <> 'visualci';
10371037
1038+
-- Bulk downloads of a build's images (sc-8869): one tar.zst per build and filter, reused within the hour.
1039+
CREATE TABLE downloads (
1040+
id bigserial PRIMARY KEY,
1041+
pid uuid NOT NULL UNIQUE,
1042+
build_id bigint NOT NULL REFERENCES builds(id) ON DELETE CASCADE,
1043+
filter jsonb NOT NULL,
1044+
filter_key text NOT NULL,
1045+
state text DEFAULT 'pending'::text NOT NULL,
1046+
object_key text,
1047+
files integer DEFAULT 0 NOT NULL,
1048+
bytes bigint DEFAULT 0 NOT NULL,
1049+
summary jsonb DEFAULT '{}'::jsonb NOT NULL,
1050+
error text,
1051+
ready_at timestamp with time zone,
1052+
created_at timestamp with time zone DEFAULT now() NOT NULL,
1053+
updated_at timestamp with time zone DEFAULT now() NOT NULL
1054+
);
1055+
CREATE INDEX downloads_build_filter ON downloads USING btree (build_id, filter_key, created_at DESC);
1056+
CREATE INDEX downloads_created_brin ON downloads USING brin (created_at);
1057+
10381058
-- Project tokens (the auth migration) belong to a project.
10391059
ALTER TABLE ONLY project_tokens
10401060
ADD CONSTRAINT project_tokens_project_id_fkey FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;

‎app/src/models/downloads.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use laravel::model::model;
2+
use laravel::str::Uuid;
3+
use laravel::time::Timestamp;
4+
5+
/// A bulk download of a build's images (sc-8869): a tar.zst in the bucket, built by a job.
6+
#[model(table = "downloads")]
7+
pub struct Download {
8+
pub id: i64,
9+
pub pid: Uuid,
10+
pub build_id: i64,
11+
pub filter: serde_json::Value,
12+
pub filter_key: String,
13+
#[default]
14+
pub state: String,
15+
pub object_key: Option<String>,
16+
#[default]
17+
pub files: i32,
18+
#[default]
19+
pub bytes: i64,
20+
#[default]
21+
pub summary: serde_json::Value,
22+
pub error: Option<String>,
23+
pub ready_at: Option<Timestamp>,
24+
pub created_at: Timestamp,
25+
pub updated_at: Timestamp,
26+
}

‎app/src/models/mod.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod comment_threads;
1010
mod comments;
1111
mod credit_transactions;
1212
mod diffs;
13+
mod downloads;
1314
mod feedback;
1415
mod ignored_changes;
1516
mod memberships;
@@ -35,6 +36,7 @@ pub use comment_threads::CommentThread;
3536
pub use comments::Comment;
3637
pub use credit_transactions::CreditTransaction;
3738
pub use diffs::Diff;
39+
pub use downloads::Download;
3840
pub use feedback::Feedback;
3941
pub use ignored_changes::IgnoredChange;
4042
pub use memberships::Membership;

0 commit comments

Comments
 (0)