Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/database/migrations/2026_12_03_000200_create_domain_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ CREATE TABLE credit_transactions (
updated_at timestamp with time zone DEFAULT now() NOT NULL,
project_id bigint,
open_source_credits bigint DEFAULT 0 NOT NULL,
-- The build a charge is for (one row per build charge step); NULL for purchases, grants and gallery days.
build_id bigint,
-- A gallery day's roll-up: one row per (organization, project, day), its amount grown as images are served.
day date,
CONSTRAINT credit_transactions_kind_check CHECK ((kind = ANY (ARRAY['purchase'::text, 'grant'::text, 'build'::text, 'render'::text, 'diff'::text, 'summary'::text, 'refund'::text, 'adjustment'::text, 'gallery'::text])))
);

Expand Down Expand Up @@ -747,6 +751,8 @@ CREATE INDEX credit_transactions_org_created ON credit_transactions USING btree
CREATE INDEX credit_transactions_project ON credit_transactions USING btree (project_id, created_at);

CREATE UNIQUE INDEX credit_transactions_purchase_once ON credit_transactions USING btree (organization_id, reference) WHERE (kind = 'purchase'::text);
CREATE UNIQUE INDEX credit_transactions_gallery_day ON credit_transactions USING btree (organization_id, project_id, day) WHERE (kind = 'gallery'::text);
CREATE INDEX credit_transactions_build_idx ON credit_transactions USING btree (build_id) WHERE build_id IS NOT NULL;

CREATE INDEX feedback_account_created ON feedback USING btree (account, created_at);

Expand Down Expand Up @@ -915,6 +921,11 @@ CREATE INDEX build_groups_source_idx ON build_groups USING btree (source_build_i
CREATE INDEX snapshots_build_group_idx ON snapshots USING btree (build_id, group_key);

-- Hot paths and foreign keys (every delete of a parent row checks these columns).
CREATE INDEX baselines_review_idx ON baselines USING btree (review_id) WHERE review_id IS NOT NULL;
CREATE INDEX baselines_approved_by_idx ON baselines USING btree (approved_by) WHERE approved_by IS NOT NULL;
CREATE INDEX builds_created_by_idx ON builds USING btree (created_by_user_id) WHERE created_by_user_id IS NOT NULL;
CREATE INDEX comments_user_idx ON comments USING btree (user_id) WHERE user_id IS NOT NULL;
CREATE INDEX comment_threads_resolved_by_idx ON comment_threads USING btree (resolved_by) WHERE resolved_by IS NOT NULL;
CREATE INDEX snapshots_render_idx ON snapshots USING btree (render_id) WHERE render_id IS NOT NULL;

CREATE INDEX snapshots_source_blob_idx ON snapshots USING btree (source_blob) WHERE source_blob IS NOT NULL;
Expand Down Expand Up @@ -1055,6 +1066,9 @@ CREATE TABLE downloads (
CREATE INDEX downloads_build_filter ON downloads USING btree (build_id, filter_key, created_at DESC);
CREATE INDEX downloads_created_brin ON downloads USING brin (created_at);

ALTER TABLE ONLY credit_transactions
ADD CONSTRAINT credit_transactions_build_id_fkey FOREIGN KEY (build_id) REFERENCES builds(id) ON DELETE SET NULL;

-- Project tokens (the auth migration) belong to a project.
ALTER TABLE ONLY project_tokens
ADD CONSTRAINT project_tokens_project_id_fkey FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE;
Expand Down
16 changes: 16 additions & 0 deletions app/src/domain/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ pub async fn create(project: &Project, params: &CreateParams, creator: Option<i6
if params.commit.is_empty() || params.branch.is_empty() {
return invalid("commit and branch are required");
}
let id_like = |s: &str| (1..=64).contains(&s.len()) && s.bytes().all(|b| b.is_ascii_alphanumeric());
if !id_like(&params.commit) {
return invalid("commit must be 1 to 64 letters and digits (a commit SHA)");
}
if params.parent_commits.iter().any(|c| !id_like(c)) {
return invalid("parent_commits must be commit SHAs");
}
if params.branch.len() > 255 || params.branch.chars().any(char::is_control) {
return invalid("branch must be at most 255 characters");
}
if params.name.trim().is_empty() || params.name.len() > 100 {
return invalid("name must be 1 to 100 characters");
}
if params.nonce.as_ref().is_some_and(|n| n.is_empty() || n.len() > 200) {
return invalid("nonce must be 1 to 200 characters");
}
if !(1..=1000).contains(&params.shard_total) {
return invalid("shard_total must be 1 to 1000");
}
Expand Down
Loading
Loading