diff --git a/app/database/migrations/0001_01_01_000000_create_users_table.rs b/app/database/migrations/0001_01_01_000000_create_users_table.rs deleted file mode 100644 index 3d663832..00000000 --- a/app/database/migrations/0001_01_01_000000_create_users_table.rs +++ /dev/null @@ -1,33 +0,0 @@ -use laravel::db::AnyTransaction; - -/// People, and their sessions. Everyone signs in through a forge (GitHub or GitLab), whose accounts are in -/// `identities`: no passwords, no "remember me" tokens. -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.schema() - .create("users", |table| { - table.id(); - table.uuid("pid").unique(); - table.string("name"); - table.string("email").unique(); - table.timestamp("email_verified_at").nullable(); - table.text("avatar_url").nullable(); - // VisualCI's own team: the admin MCP endpoint and staff pages - table.boolean("staff").default(false); - // How they signed up ("github", "github, from an MCP client's sign-in"), for the team's sign-up notice - table.text("signup_via").nullable(); - table.timestamps(); - }) - .await?; - - tx.schema() - .create("sessions", |table| { - table.string("id").primary(); - // The signed-in user's pid: their auth id (`User::auth_id`) - table.uuid("user_id").nullable().index(); - table.string("ip_address").length(45).nullable(); - table.text("user_agent").nullable(); - table.long_text("payload"); - table.timestamp("last_activity").index(); - }) - .await -} diff --git a/app/database/migrations/2026_12_03_000200_create_domain_tables.rs b/app/database/migrations/0001_01_01_000000_initial_schema.rs similarity index 75% rename from app/database/migrations/2026_12_03_000200_create_domain_tables.rs rename to app/database/migrations/0001_01_01_000000_initial_schema.rs index 3e176dcf..ded68f3d 100644 --- a/app/database/migrations/2026_12_03_000200_create_domain_tables.rs +++ b/app/database/migrations/0001_01_01_000000_initial_schema.rs @@ -1,21 +1,193 @@ -//! The domain tables (sc-8900, the data side), as docs/design-storage.md lays them out: organizations, projects, -//! builds, snapshots and their pages, page texts by hash, build groups read from earlier builds (the -//! `effective_snapshots` view), baselines, renders, diffs, blobs, reviews, comments, bulk downloads and the credit ledger. +//! VisualCI's schema. //! -//! Raw SQL: the schema builder has no views, partial or BRIN indexes, or lz4 compression. `parent_commits`, -//! `shards_finalized` and `reviews.snapshot_ids` are JSON arrays, since Laravel Rust 0.1.4 has no PostgreSQL array -//! columns. +//! People and their sessions, the cache and the queue, forge accounts and tokens, and the waitlist come from the +//! schema builder. Everyone signs in through a forge (GitHub or GitLab), whose accounts are in `identities`: no +//! passwords, no "remember me" tokens. +//! +//! The domain tables (sc-8900, the data side) are raw SQL, as docs/design-storage.md lays them out: organizations, +//! projects, builds, snapshots and their pages, page texts by hash, build groups read from earlier builds (the +//! `effective_snapshots` view), baselines, renders, diffs, blobs, reviews, comments, bulk downloads, the credit +//! ledger, the emails outbox, invitations and the CLI's device sign-in. The schema builder has no views, partial or +//! BRIN indexes, lz4 compression or `timestamp with time zone` columns. `parent_commits`, `shards_finalized` and +//! `reviews.snapshot_ids` are JSON arrays, since Laravel Rust 0.1.4 has no PostgreSQL array columns. use laravel::db::AnyTransaction; pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { + tx.schema() + .create("users", |table| { + table.id(); + table.uuid("pid").unique(); + table.string("name"); + table.string("email").unique(); + table.timestamp("email_verified_at").nullable(); + table.text("avatar_url").nullable(); + // VisualCI's own team: the admin MCP endpoint and staff pages + table.boolean("staff").default(false); + // How they signed up ("github", "github, from an MCP client's sign-in"), for the team's sign-up notice + table.text("signup_via").nullable(); + table.timestamps(); + // Their email choices + table.boolean("email_low_credits").default(true); + table.boolean("email_receipts").default(true); + // When the team got the sign-up notice: `timestamp with time zone`, which the schema builder can't make, + // so SCHEMA changes its type + table.timestamp("signup_notified_at").nullable(); + // "How did you hear about VisualCI?", asked once after sign-up + table.boolean("heard_about_pending").default(false); + table.text("heard_about_source").nullable(); + table.text("heard_about_detail").nullable(); + }) + .await?; + + tx.schema() + .create("sessions", |table| { + table.string("id").primary(); + // The signed-in user's pid: their auth id (`User::auth_id`) + table.uuid("user_id").nullable().index(); + table.string("ip_address").length(45).nullable(); + table.text("user_agent").nullable(); + table.long_text("payload"); + table.timestamp("last_activity").index(); + }) + .await?; + + // The database cache store + tx.schema() + .create("cache", |table| { + table.string("key").primary(); + table.medium_text("value"); + table.timestamp("expiration").index(); + }) + .await?; + + tx.schema() + .create("cache_locks", |table| { + table.string("key").primary(); + table.string("owner"); + table.timestamp("expiration").index(); + }) + .await?; + + // The database queue: jobs, failed jobs and job batches + tx.schema() + .create("jobs", |table| { + table.id(); + table.string("queue").index(); + table.long_text("payload"); + table.integer("attempts").default(0); + table.timestamp("reserved_at").nullable(); + table.timestamp("available_at"); + table.timestamp("created_at"); + }) + .await?; + + tx.schema() + .create("failed_jobs", |table| { + table.id(); + table.string("job_id").length(36).unique(); + table.string("connection"); + table.string("queue"); + table.long_text("payload"); + table.long_text("error"); + table.timestamp("failed_at"); + + table.index(["connection", "queue", "failed_at"]); + }) + .await?; + + tx.schema() + .create("job_batches", |table| { + table.string("id").length(36).primary(); + table.string("name").nullable(); + table.integer("total_jobs"); + table.integer("pending_jobs"); + table.integer("failed_jobs"); + table.long_text("options"); + table.timestamp("created_at"); + table.timestamp("cancelled_at").nullable(); + table.timestamp("finished_at").nullable(); + }) + .await?; + + tx.schema() + .create("job_batch_jobs", |table| { + table.string("batch_id").length(36); + table.string("job_id").length(36); + table.string("status").length(16); + + table.primary(["batch_id", "job_id"]); + }) + .await?; + + tx.schema() + .create("identities", |table| { + table.id(); + table.foreign_id("user_id").constrained().cascade_on_delete(); + // "github" or "gitlab"; `site` is a self-managed GitLab's host, empty for gitlab.com and GitHub + table.string("forge"); + table.string("site").default(""); + table.string("forge_user_id"); + table.string("login"); + table.timestamps(); + table.unique(["forge", "site", "forge_user_id"]); + }) + .await?; + + // Personal access tokens (`vcu_…`): whatever their user can do, in every organization they belong to + tx.schema() + .create("user_tokens", |table| { + table.id(); + table.foreign_id("user_id").constrained().cascade_on_delete(); + table.string("name"); + // SHA-256 of the token, hex; the token itself is shown once + table.string("token_hash").unique(); + table.string("token_prefix"); + table.timestamp("last_used_at").nullable(); + table.timestamps(); + }) + .await?; + + // Closed sign-ups: someone new who signs in is written here instead of getting an account + tx.schema() + .create("waitlist", |table| { + table.id(); + table.string("forge"); + table.string("site").default(""); + table.string("forge_user_id"); + table.string("login"); + table.text("name").nullable(); + table.text("email").nullable(); + // "web", or "mcp: " + table.text("source"); + table.timestamps(); + table.unique(["forge", "site", "forge_user_id"]); + }) + .await?; + tx.query(SCHEMA).unprepared().await?; - Ok(()) + + // Project tokens (`vci_…`): CI's, for one project + tx.schema() + .create("project_tokens", |table| { + table.id(); + table.big_integer("project_id").index(); + table.string("name"); + table.string("token_hash").unique(); + table.string("token_prefix"); + table.timestamp("last_used_at").nullable(); + table.timestamps(); + table + .foreign(["project_id"]) + .references("projects", ["id"]) + .cascade_on_delete() + .name("project_tokens_project_id_fkey"); + }) + .await } const SCHEMA: &str = r#" --- VisualCI's whole schema, in one migration: storage was rebuilt from scratch on 3 Dec 2026 (sc-8868, sc-8890), --- with no data or migrations kept from before. New migrations go after this one. +ALTER TABLE users ALTER COLUMN signup_notified_at TYPE timestamp with time zone; CREATE TABLE admin_audit ( id bigint NOT NULL, @@ -74,7 +246,11 @@ CREATE TABLE blobs ( width integer, height integer, created_at timestamp with time zone DEFAULT now() NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL + updated_at timestamp with time zone DEFAULT now() NOT NULL, + -- Retention marks a blob before deleting its object, and deletes the row only while it's still marked. + -- Registering the hash again clears the mark (and has the file uploaded again), so a build reusing a file while a + -- prune runs keeps it. + deleting boolean DEFAULT false NOT NULL ); CREATE TABLE branch_checks ( @@ -237,7 +413,10 @@ CREATE TABLE diffs ( result jsonb NOT NULL, overlay_blob text, created_at timestamp with time zone DEFAULT now() NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL + updated_at timestamp with time zone DEFAULT now() NOT NULL, + -- When a comparison last reused the cached diff. Retention leaves the overlay of a diff reused in the last day + -- alone, since the build reusing it isn't in the prune's keep sets. + used_at timestamp with time zone ); CREATE SEQUENCE diffs_id_seq @@ -411,6 +590,11 @@ CREATE TABLE projects ( linked_by bigint, tokens_can_approve boolean DEFAULT true NOT NULL, repository_id text, + -- The gallery URLs last purged as published, so a screenshot that drops out of the gallery is purged too. + gallery_urls jsonb DEFAULT '[]'::jsonb NOT NULL, + -- Whether VisualCI comments on a pull request whose builds are all unchanged. Off by default: such a pull request + -- gets only the passing check. + comment_when_unchanged boolean DEFAULT false NOT NULL, CONSTRAINT projects_ci_mode_check CHECK ((ci_mode = ANY (ARRAY['review'::text, 'strict'::text, 'wait'::text]))) ); @@ -440,6 +624,13 @@ CREATE TABLE renders ( render_ms bigint, project_id bigint, claim_token_hash text, + -- The PNGs the render uploaded through its own uploads, by hash: "blob" for one it uploaded to the blob itself, + -- "proof" for one already stored, which it uploaded to a proof key instead. Completing the render may name only + -- these as page images, so a renderer can't name another tenant's PNG by its hash. + uploads jsonb DEFAULT '{}'::jsonb NOT NULL, + -- When a snapshot last reused the render. Retention leaves a recently reused render's images and texts alone, + -- since the build reusing it isn't in the prune's keep sets. + used_at timestamp with time zone, CONSTRAINT renders_state_check CHECK ((state = ANY (ARRAY['queued'::text, 'rendering'::text, 'done'::text, 'failed'::text]))) ); @@ -973,6 +1164,12 @@ CREATE INDEX builds_created_brin ON builds USING brin (created_at); CREATE INDEX blobs_created_brin ON blobs USING brin (created_at); +CREATE INDEX blobs_deleting ON blobs USING btree (sha256) WHERE deleting; + +CREATE INDEX renders_used_at ON renders USING btree (used_at) WHERE used_at IS NOT NULL; + +CREATE INDEX diffs_used_at ON diffs USING btree (used_at) WHERE used_at IS NOT NULL; + CREATE INDEX renders_created_brin ON renders USING brin (created_at); CREATE INDEX texts_created_brin ON texts USING brin (created_at); @@ -1069,7 +1266,88 @@ 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; +-- Gallery purges that used up their retries, counted in `/status`. +CREATE TABLE gallery_purge_failures ( + id bigserial PRIMARY KEY, + project_id bigint REFERENCES projects(id) ON DELETE CASCADE, + build_id bigint REFERENCES builds(id) ON DELETE SET NULL, + urls jsonb NOT NULL, + error text NOT NULL, + created_at timestamp with time zone DEFAULT now() NOT NULL +); +CREATE INDEX gallery_purge_failures_created ON gallery_purge_failures USING btree (created_at); + +-- The emails outbox. +CREATE TABLE emails ( + id BIGSERIAL PRIMARY KEY, + kind TEXT NOT NULL, + dedupe_key TEXT NOT NULL UNIQUE, + organization_id BIGINT REFERENCES organizations(id) ON DELETE CASCADE, + user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, + recipient TEXT NOT NULL, + data JSONB NOT NULL, + subject TEXT, + text_body TEXT, + html_body TEXT, + state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending', 'sent', 'failed')), + attempts INTEGER NOT NULL DEFAULT 0, + last_error TEXT, + claimed_at TIMESTAMPTZ, + sent_at TIMESTAMPTZ, + dismissed_at TIMESTAMPTZ, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now() +); +CREATE INDEX emails_pending ON emails (created_at) WHERE state = 'pending'; +CREATE INDEX emails_organization ON emails (organization_id, created_at); +CREATE INDEX emails_failed ON emails (id) WHERE state = 'failed' AND dismissed_at IS NULL; + +-- People who haven't had the team's sign-up notice yet. +CREATE INDEX users_signup_unnotified ON users (id) WHERE signup_notified_at IS NULL; + +-- Invitations to an organization, by email or by a login on a forge. `for_user_id` is the account it's for when one +-- existed when it was sent, so it shows on their side; it waits for them to accept. +CREATE TABLE invitations ( + id BIGSERIAL PRIMARY KEY, + pid UUID NOT NULL UNIQUE, + organization_id BIGINT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE, + email TEXT, + forge TEXT, + login TEXT, + role TEXT NOT NULL CHECK (role IN ('admin', 'member', 'read')), + invited_by BIGINT REFERENCES users(id) ON DELETE SET NULL, + accepted_by BIGINT REFERENCES users(id) ON DELETE SET NULL, + accepted_at TIMESTAMPTZ, + for_user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMPTZ NOT NULL DEFAULT now(), + updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), + CHECK ((email IS NOT NULL) <> (login IS NOT NULL)), + CHECK ((login IS NULL) = (forge IS NULL)) +); +CREATE UNIQUE INDEX invitations_pending_email ON invitations (organization_id, lower(email)) + WHERE accepted_at IS NULL AND email IS NOT NULL; +CREATE UNIQUE INDEX invitations_pending_login ON invitations (organization_id, forge, lower(login)) + WHERE accepted_at IS NULL AND login IS NOT NULL; +CREATE INDEX invitations_for_user ON invitations (for_user_id) WHERE accepted_at IS NULL; + +-- `visualci login`'s device-code sign-in: the device code is stored hashed; a code gives one token, once. +CREATE TABLE device_logins ( + id BIGSERIAL PRIMARY KEY, + device_code_hash TEXT NOT NULL UNIQUE, + user_code TEXT NOT NULL UNIQUE, + -- What's asking, shown on the approval page: "visualci CLI on ada-laptop". + client_name TEXT NOT NULL, + -- Who asked for it (behind the trusted proxies, the address they report), shown on the approval page and counted + -- for the per-address limit. + requester_ip TEXT, + last_polled_at TIMESTAMPTZ, + user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, + approved_at TIMESTAMPTZ, + denied_at TIMESTAMPTZ, + -- When the CLI collected its token. + consumed_at TIMESTAMPTZ, + expires_at TIMESTAMPTZ NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT now() +); +CREATE INDEX device_logins_requester ON device_logins (requester_ip, created_at); "#; diff --git a/app/database/migrations/0001_01_01_000001_create_cache_table.rs b/app/database/migrations/0001_01_01_000001_create_cache_table.rs deleted file mode 100644 index e26110c1..00000000 --- a/app/database/migrations/0001_01_01_000001_create_cache_table.rs +++ /dev/null @@ -1 +0,0 @@ -laravel::cache::tables!(); diff --git a/app/database/migrations/0001_01_01_000002_create_jobs_table.rs b/app/database/migrations/0001_01_01_000002_create_jobs_table.rs deleted file mode 100644 index 8e80c3bc..00000000 --- a/app/database/migrations/0001_01_01_000002_create_jobs_table.rs +++ /dev/null @@ -1 +0,0 @@ -laravel::queue::tables!(); diff --git a/app/database/migrations/2026_12_03_000100_create_auth_tables.rs b/app/database/migrations/2026_12_03_000100_create_auth_tables.rs deleted file mode 100644 index 9ad341ed..00000000 --- a/app/database/migrations/2026_12_03_000100_create_auth_tables.rs +++ /dev/null @@ -1,63 +0,0 @@ -use laravel::db::AnyTransaction; - -/// Forge accounts, personal and project tokens, and the waitlist (sc-8900, the auth side). `project_tokens.project_id` -/// gets its foreign key once the domain tables exist. -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.schema() - .create("identities", |table| { - table.id(); - table.foreign_id("user_id").constrained().cascade_on_delete(); - // "github" or "gitlab"; `site` is a self-managed GitLab's host, empty for gitlab.com and GitHub - table.string("forge"); - table.string("site").default(""); - table.string("forge_user_id"); - table.string("login"); - table.timestamps(); - table.unique(["forge", "site", "forge_user_id"]); - }) - .await?; - - // Personal access tokens (`vcu_…`): whatever their user can do, in every organization they belong to - tx.schema() - .create("user_tokens", |table| { - table.id(); - table.foreign_id("user_id").constrained().cascade_on_delete(); - table.string("name"); - // SHA-256 of the token, hex; the token itself is shown once - table.string("token_hash").unique(); - table.string("token_prefix"); - table.timestamp("last_used_at").nullable(); - table.timestamps(); - }) - .await?; - - // Project tokens (`vci_…`): CI's, for one project - tx.schema() - .create("project_tokens", |table| { - table.id(); - table.big_integer("project_id").index(); - table.string("name"); - table.string("token_hash").unique(); - table.string("token_prefix"); - table.timestamp("last_used_at").nullable(); - table.timestamps(); - }) - .await?; - - // Closed sign-ups: someone new who signs in is written here instead of getting an account - tx.schema() - .create("waitlist", |table| { - table.id(); - table.string("forge"); - table.string("site").default(""); - table.string("forge_user_id"); - table.string("login"); - table.text("name").nullable(); - table.text("email").nullable(); - // "web", or "mcp: " - table.text("source"); - table.timestamps(); - table.unique(["forge", "site", "forge_user_id"]); - }) - .await -} diff --git a/app/database/migrations/2026_12_03_000300_create_emails_table.rs b/app/database/migrations/2026_12_03_000300_create_emails_table.rs deleted file mode 100644 index 240e0138..00000000 --- a/app/database/migrations/2026_12_03_000300_create_emails_table.rs +++ /dev/null @@ -1,37 +0,0 @@ -use laravel::db::AnyTransaction; - -/// The emails outbox (ported as today's), and each person's email choices and sign-up notice. -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.query( - "CREATE TABLE emails ( - id BIGSERIAL PRIMARY KEY, - kind TEXT NOT NULL, - dedupe_key TEXT NOT NULL UNIQUE, - organization_id BIGINT REFERENCES organizations(id) ON DELETE CASCADE, - user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, - recipient TEXT NOT NULL, - data JSONB NOT NULL, - subject TEXT, - text_body TEXT, - html_body TEXT, - state TEXT NOT NULL DEFAULT 'pending' CHECK (state IN ('pending', 'sent', 'failed')), - attempts INTEGER NOT NULL DEFAULT 0, - last_error TEXT, - claimed_at TIMESTAMPTZ, - sent_at TIMESTAMPTZ, - dismissed_at TIMESTAMPTZ, - created_at TIMESTAMPTZ NOT NULL DEFAULT now(), - updated_at TIMESTAMPTZ NOT NULL DEFAULT now() - ); - CREATE INDEX emails_pending ON emails (created_at) WHERE state = 'pending'; - CREATE INDEX emails_organization ON emails (organization_id, created_at); - CREATE INDEX emails_failed ON emails (id) WHERE state = 'failed' AND dismissed_at IS NULL; - ALTER TABLE users - ADD COLUMN email_low_credits BOOLEAN NOT NULL DEFAULT true, - ADD COLUMN email_receipts BOOLEAN NOT NULL DEFAULT true, - ADD COLUMN signup_notified_at TIMESTAMPTZ;", - ) - .unprepared() - .await?; - Ok(()) -} diff --git a/app/database/migrations/2026_12_03_000300_render_uploads_blob_deleting_gallery_urls.rs b/app/database/migrations/2026_12_03_000300_render_uploads_blob_deleting_gallery_urls.rs deleted file mode 100644 index 27e7ee3a..00000000 --- a/app/database/migrations/2026_12_03_000300_render_uploads_blob_deleting_gallery_urls.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Columns the renderer API, retention and the gallery need (#81's review): -//! -//! - `blobs.deleting`: retention marks a blob before deleting its object, and deletes the row only while it's still -//! marked. Registering the hash again clears the mark (and has the file uploaded again), so a build reusing a file -//! while a prune runs keeps it. -//! - `renders.uploads`: the PNGs a render uploaded through its own uploads, by hash: `"blob"` for one it uploaded to -//! the blob itself, `"proof"` for one already stored, which it uploaded to a proof key instead. Completing the render -//! may name only these as page images, so a renderer can't name another tenant's PNG by its hash. -//! - `renders.used_at`: when a snapshot last reused the render. Retention leaves a recently reused render's images and -//! texts alone, since the build reusing it isn't in the prune's keep sets. -//! - `projects.gallery_urls`: the gallery URLs last purged as published, so a screenshot that drops out of the gallery -//! is purged too. -//! - `gallery_purge_failures`: purges that used up their retries, counted in `/status`. - -use laravel::db::AnyTransaction; - -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.query(SCHEMA).unprepared().await?; - Ok(()) -} - -const SCHEMA: &str = r" -ALTER TABLE blobs ADD COLUMN deleting boolean DEFAULT false NOT NULL; -CREATE INDEX blobs_deleting ON blobs USING btree (sha256) WHERE deleting; - -ALTER TABLE renders ADD COLUMN uploads jsonb DEFAULT '{}'::jsonb NOT NULL; -ALTER TABLE renders ADD COLUMN used_at timestamp with time zone; -CREATE INDEX renders_used_at ON renders USING btree (used_at) WHERE used_at IS NOT NULL; - -ALTER TABLE projects ADD COLUMN gallery_urls jsonb DEFAULT '[]'::jsonb NOT NULL; - -CREATE TABLE gallery_purge_failures ( - id bigserial PRIMARY KEY, - project_id bigint REFERENCES projects(id) ON DELETE CASCADE, - build_id bigint REFERENCES builds(id) ON DELETE SET NULL, - urls jsonb NOT NULL, - error text NOT NULL, - created_at timestamp with time zone DEFAULT now() NOT NULL -); -CREATE INDEX gallery_purge_failures_created ON gallery_purge_failures USING btree (created_at); -"; diff --git a/app/database/migrations/2026_12_03_000400_create_invitations_table.rs b/app/database/migrations/2026_12_03_000400_create_invitations_table.rs deleted file mode 100644 index 3ca537ef..00000000 --- a/app/database/migrations/2026_12_03_000400_create_invitations_table.rs +++ /dev/null @@ -1,33 +0,0 @@ -use laravel::db::AnyTransaction; - -/// Invitations to an organization, by email or by a login on a forge (ported as today's). `for_user_id` is the -/// account it's for when one existed when it was sent, so it shows on their side; it waits for them to accept. -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.query( - "CREATE TABLE invitations ( - id BIGSERIAL PRIMARY KEY, - pid UUID NOT NULL UNIQUE, - organization_id BIGINT NOT NULL REFERENCES organizations(id) ON DELETE CASCADE, - email TEXT, - forge TEXT, - login TEXT, - role TEXT NOT NULL CHECK (role IN ('admin', 'member', 'read')), - invited_by BIGINT REFERENCES users(id) ON DELETE SET NULL, - accepted_by BIGINT REFERENCES users(id) ON DELETE SET NULL, - accepted_at TIMESTAMPTZ, - for_user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, - created_at TIMESTAMPTZ NOT NULL DEFAULT now(), - updated_at TIMESTAMPTZ NOT NULL DEFAULT now(), - CHECK ((email IS NOT NULL) <> (login IS NOT NULL)), - CHECK ((login IS NULL) = (forge IS NULL)) - ); - CREATE UNIQUE INDEX invitations_pending_email ON invitations (organization_id, lower(email)) - WHERE accepted_at IS NULL AND email IS NOT NULL; - CREATE UNIQUE INDEX invitations_pending_login ON invitations (organization_id, forge, lower(login)) - WHERE accepted_at IS NULL AND login IS NOT NULL; - CREATE INDEX invitations_for_user ON invitations (for_user_id) WHERE accepted_at IS NULL;", - ) - .unprepared() - .await?; - Ok(()) -} diff --git a/app/database/migrations/2026_12_03_000400_diffs_used_at.rs b/app/database/migrations/2026_12_03_000400_diffs_used_at.rs deleted file mode 100644 index be42b880..00000000 --- a/app/database/migrations/2026_12_03_000400_diffs_used_at.rs +++ /dev/null @@ -1,14 +0,0 @@ -//! `diffs.used_at`: when a comparison last reused the cached diff. Retention leaves the overlay of a diff reused in the -//! last day alone, since the build reusing it isn't in the prune's keep sets. - -use laravel::db::AnyTransaction; - -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.query(SCHEMA).unprepared().await?; - Ok(()) -} - -const SCHEMA: &str = r" -ALTER TABLE diffs ADD COLUMN used_at timestamp with time zone; -CREATE INDEX diffs_used_at ON diffs USING btree (used_at) WHERE used_at IS NOT NULL; -"; diff --git a/app/database/migrations/2026_12_03_000500_add_heard_about_to_users.rs b/app/database/migrations/2026_12_03_000500_add_heard_about_to_users.rs deleted file mode 100644 index a46492d1..00000000 --- a/app/database/migrations/2026_12_03_000500_add_heard_about_to_users.rs +++ /dev/null @@ -1,15 +0,0 @@ -use laravel::db::AnyTransaction; - -/// "How did you hear about VisualCI?" (asked once after sign-up), ported as today's. -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.query( - "ALTER TABLE users - ADD COLUMN heard_about_pending BOOLEAN NOT NULL DEFAULT false, - ADD COLUMN heard_about_source TEXT, - ADD COLUMN heard_about_detail TEXT; - CREATE INDEX users_signup_unnotified ON users (id) WHERE signup_notified_at IS NULL;", - ) - .unprepared() - .await?; - Ok(()) -} diff --git a/app/database/migrations/2026_12_03_000500_projects_comment_when_unchanged.rs b/app/database/migrations/2026_12_03_000500_projects_comment_when_unchanged.rs deleted file mode 100644 index c12e663b..00000000 --- a/app/database/migrations/2026_12_03_000500_projects_comment_when_unchanged.rs +++ /dev/null @@ -1,11 +0,0 @@ -//! `projects.comment_when_unchanged` (c2da705, #90): whether VisualCI comments on a pull request whose builds are all -//! unchanged. Off by default, for every project: such a pull request gets only the passing check. - -use laravel::db::AnyTransaction; - -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.query("ALTER TABLE projects ADD COLUMN comment_when_unchanged boolean DEFAULT false NOT NULL") - .unprepared() - .await?; - Ok(()) -} diff --git a/app/database/migrations/2026_12_03_000600_create_device_logins_table.rs b/app/database/migrations/2026_12_03_000600_create_device_logins_table.rs deleted file mode 100644 index 4bcab92a..00000000 --- a/app/database/migrations/2026_12_03_000600_create_device_logins_table.rs +++ /dev/null @@ -1,30 +0,0 @@ -use laravel::db::AnyTransaction; - -/// `visualci login`'s device-code sign-in (ported as today's): the device code is stored hashed; a code gives one -/// token, once. -pub async fn migrate(tx: &mut AnyTransaction<'_>) -> laravel::Result<()> { - tx.query( - "CREATE TABLE device_logins ( - id BIGSERIAL PRIMARY KEY, - device_code_hash TEXT NOT NULL UNIQUE, - user_code TEXT NOT NULL UNIQUE, - -- What's asking, shown on the approval page: \"visualci CLI on ada-laptop\". - client_name TEXT NOT NULL, - -- Who asked for it (behind the trusted proxies, the address they report), shown on the approval page and - -- counted for the per-address limit. - requester_ip TEXT, - last_polled_at TIMESTAMPTZ, - user_id BIGINT REFERENCES users(id) ON DELETE CASCADE, - approved_at TIMESTAMPTZ, - denied_at TIMESTAMPTZ, - -- When the CLI collected its token. - consumed_at TIMESTAMPTZ, - expires_at TIMESTAMPTZ NOT NULL, - created_at TIMESTAMPTZ NOT NULL DEFAULT now() - ); - CREATE INDEX device_logins_requester ON device_logins (requester_ip, created_at);", - ) - .unprepared() - .await?; - Ok(()) -} diff --git a/docs/design-storage.md b/docs/design-storage.md index ed8bcbc1..a1efc3c6 100644 --- a/docs/design-storage.md +++ b/docs/design-storage.md @@ -5,7 +5,7 @@ suite rewrote every snapshot and page row whether or not anything changed. VisualCI's server is being rebuilt on Laravel Rust (sc-8900) on a fresh database. No old data is carried over except the tokens agents and CI already use, seeded at cutover. The domain tables below are -`app/database/migrations/2026_12_03_000200_create_domain_tables.rs`. The design itself doesn't depend on a framework. +`app/database/migrations/0001_01_01_000000_initial_schema.rs`. The design itself doesn't depend on a framework. ## Numbers that motivated it