diff --git a/.env.example b/.env.example index f0ab138..46004c0 100644 --- a/.env.example +++ b/.env.example @@ -34,6 +34,8 @@ MIGRATE_ON_START=false # ── Attachments ────────────────────────────────────────────────────────────── # local: files on disk under STORAGE_LOCAL_DIR (default DATA_DIR/uploads) # s3: any S3-compatible store (AWS S3, Cloudflare R2, Garage, SeaweedFS, MinIO) +# postgres: in the database itself, for small instances on hosts without a persistent disk +# (free tiers). Counts against the database size; keep MAX_UPLOAD_BYTES modest. STORAGE_DRIVER=local STORAGE_LOCAL_DIR= S3_ENDPOINT= diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88002c1..119d8ce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -68,7 +68,15 @@ jobs: node-version: 22 cache: pnpm - run: pnpm install --frozen-lockfile - - run: pnpm --filter @reprodrop/e2e exec playwright install --with-deps chromium + # Ubuntu's package mirrors time out now and then; retry instead of failing the run. + - name: Install Chromium for Playwright + run: | + for attempt in 1 2 3; do + pnpm --filter @reprodrop/e2e exec playwright install --with-deps chromium && exit 0 + echo "Attempt $attempt failed; retrying in 20 s" + sleep 20 + done + exit 1 - run: pnpm --filter @reprodrop/e2e build - run: pnpm --filter @reprodrop/e2e e2e - uses: actions/upload-artifact@v4 diff --git a/.github/workflows/site.yml b/.github/workflows/site.yml index ccc64df..edceeba 100644 --- a/.github/workflows/site.yml +++ b/.github/workflows/site.yml @@ -46,7 +46,15 @@ jobs: node-version: 22 cache: pnpm - run: pnpm install --frozen-lockfile - - run: pnpm --filter @reprodrop/site exec playwright install --with-deps chromium + # Ubuntu's package mirrors time out now and then; retry instead of failing the run. + - name: Install Chromium for Playwright + run: | + for attempt in 1 2 3; do + pnpm --filter @reprodrop/site exec playwright install --with-deps chromium && exit 0 + echo "Attempt $attempt failed; retrying in 20 s" + sleep 20 + done + exit 1 # Tested without analytics, so the tests can prove the page makes no third-party requests. - run: pnpm --filter @reprodrop/site build - run: pnpm --filter @reprodrop/site test:site diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5c0d3..c598992 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ release process. ## [Unreleased] +### Added + +- `STORAGE_DRIVER=postgres` keeps attachments in the database, for hosts without a persistent disk + such as free tiers that wipe the filesystem on restart. +- Free hosting on Render and Neon: a `render.yaml` blueprint and a guide + (`docs/self-hosting/render.md`). On Render, `APP_URL` defaults to the service's public address. + ## [0.1.2] - 2026-12-01 ### Highlights diff --git a/apps/api/src/create-context.ts b/apps/api/src/create-context.ts index 5b7ea32..eb16069 100644 --- a/apps/api/src/create-context.ts +++ b/apps/api/src/create-context.ts @@ -1,9 +1,10 @@ -import { createDatabase, type DatabaseHandle } from "@reprodrop/database"; +import { createDatabase, type Database, type DatabaseHandle } from "@reprodrop/database"; import { HttpJiraClient, MockJira, type FetchLike } from "@reprodrop/jira"; import type { AppConfig } from "./config"; import type { AppContext } from "./context"; import { TokenCipher } from "./lib/crypto"; import { LocalStorage, type Storage } from "./storage"; +import { PostgresStorage } from "./storage/postgres"; import { S3Storage } from "./storage/s3"; export interface ContextOverrides { @@ -13,7 +14,8 @@ export interface ContextOverrides { database?: DatabaseHandle; } -export function createStorage(config: AppConfig): Storage { +export function createStorage(config: AppConfig, db: Database): Storage { + if (config.STORAGE_DRIVER === "postgres") return new PostgresStorage(db); if (config.STORAGE_DRIVER === "s3") { return new S3Storage({ bucket: config.S3_BUCKET!, @@ -36,7 +38,7 @@ export function createContext( const ctx: AppContext = { config, db: database.db, - storage: overrides.storage ?? createStorage(config), + storage: overrides.storage ?? createStorage(config, database.db), cipher: new TokenCipher(config.encryptionKey, config.previousEncryptionKeys), jira: { createClient: (getAccessToken) => new HttpJiraClient({ getAccessToken, fetch: jiraFetch }), diff --git a/apps/api/src/storage/index.ts b/apps/api/src/storage/index.ts index 9757c01..88bea86 100644 --- a/apps/api/src/storage/index.ts +++ b/apps/api/src/storage/index.ts @@ -5,7 +5,7 @@ import type { Readable } from "node:stream"; /** Where attachment bytes live. Metadata always lives in Postgres. */ export interface Storage { - readonly driver: "local" | "s3" | "memory"; + readonly driver: "local" | "s3" | "postgres" | "memory"; put(key: string, data: Buffer, contentType: string): Promise; get(key: string): Promise; delete(key: string): Promise; diff --git a/apps/api/src/storage/postgres.ts b/apps/api/src/storage/postgres.ts new file mode 100644 index 0000000..d1a8bf2 --- /dev/null +++ b/apps/api/src/storage/postgres.ts @@ -0,0 +1,46 @@ +import { Readable } from "node:stream"; +import { eq, sql } from "drizzle-orm"; +import { attachmentBlobs, type Database } from "@reprodrop/database"; +import { assertSafeKey, type Storage } from "./index"; + +/** + * Keeps attachment bytes in Postgres, in the `attachment_blobs` table. + * + * Meant for small instances on hosts without a persistent disk (free tiers that wipe the + * filesystem on restart), so screenshots survive as long as the database does. Every byte counts + * against the database's size, so keep MAX_UPLOAD_BYTES and the retention period modest. For + * larger instances use local storage on a persistent volume, or S3. + */ +export class PostgresStorage implements Storage { + readonly driver = "postgres" as const; + + constructor(private readonly db: Database) {} + + async put(key: string, data: Buffer, contentType: string): Promise { + assertSafeKey(key); + await this.db + .insert(attachmentBlobs) + .values({ key, contentType, data }) + .onConflictDoUpdate({ target: attachmentBlobs.key, set: { data, contentType } }); + } + + async get(key: string): Promise { + assertSafeKey(key); + const [row] = await this.db + .select({ data: attachmentBlobs.data }) + .from(attachmentBlobs) + .where(eq(attachmentBlobs.key, key)) + .limit(1); + if (!row) throw Object.assign(new Error("Not found"), { code: "ENOENT" }); + return Readable.from(row.data); + } + + async delete(key: string): Promise { + assertSafeKey(key); + await this.db.delete(attachmentBlobs).where(eq(attachmentBlobs.key, key)); + } + + async check(): Promise { + await this.db.execute(sql`select 1 from attachment_blobs limit 1`); + } +} diff --git a/apps/api/test/helpers.ts b/apps/api/test/helpers.ts index 7620c31..fd2cdef 100644 --- a/apps/api/test/helpers.ts +++ b/apps/api/test/helpers.ts @@ -63,7 +63,7 @@ export async function resetDatabase(ctx: AppContext): Promise { await ctx.db.execute(sql` truncate table audit_logs, share_links, jira_issues, oauth_states, integration_tokens, integrations, report_attachments, report_events, reports, projects, api_tokens, sessions, organization_members, - organizations, users restart identity cascade + organizations, users, attachment_blobs restart identity cascade `); } diff --git a/apps/api/test/storage-postgres.test.ts b/apps/api/test/storage-postgres.test.ts new file mode 100644 index 0000000..00f7c35 --- /dev/null +++ b/apps/api/test/storage-postgres.test.ts @@ -0,0 +1,55 @@ +import type { Readable } from "node:stream"; +import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest"; +import { sql } from "drizzle-orm"; +import { createDatabase, type DatabaseHandle } from "@reprodrop/database"; +import { PostgresStorage } from "../src/storage/postgres"; +import { TEST_DATABASE_URL } from "./global-setup"; + +async function read(stream: Readable): Promise { + const chunks: Buffer[] = []; + for await (const chunk of stream) chunks.push(Buffer.from(chunk)); + return Buffer.concat(chunks); +} + +describe("PostgresStorage", () => { + let handle: DatabaseHandle; + let storage: PostgresStorage; + + beforeAll(() => { + handle = createDatabase(TEST_DATABASE_URL, { max: 2 }); + storage = new PostgresStorage(handle.db); + }); + afterAll(() => handle.close()); + beforeEach(() => handle.db.execute(sql`truncate table attachment_blobs`)); + + it("stores, reads back, overwrites and deletes bytes", async () => { + const key = "org-1/report-1/shot-1.png"; + const bytes = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x00, 0xff, 0x10]); + await storage.put(key, bytes, "image/png"); + expect(await read(await storage.get(key))).toEqual(bytes); + + const replaced = Buffer.from("second version"); + await storage.put(key, replaced, "image/png"); + expect(await read(await storage.get(key))).toEqual(replaced); + + await storage.delete(key); + await expect(storage.get(key)).rejects.toMatchObject({ code: "ENOENT" }); + }); + + it("reports a missing key the way the other drivers do", async () => { + await expect(storage.get("org-1/missing.png")).rejects.toMatchObject({ code: "ENOENT" }); + await expect(storage.delete("org-1/missing.png")).resolves.toBeUndefined(); + }); + + it("refuses unsafe keys", async () => { + await expect(storage.put("../escape.png", Buffer.from("x"), "image/png")).rejects.toThrow( + /unsafe storage key/, + ); + await expect(storage.get("a//b.png")).rejects.toThrow(/unsafe storage key/); + }); + + it("passes the health check once the table exists", async () => { + await expect(storage.check()).resolves.toBeUndefined(); + expect(storage.driver).toBe("postgres"); + }); +}); diff --git a/docs/self-hosting/production.md b/docs/self-hosting/production.md index 5470fba..b024f7d 100644 --- a/docs/self-hosting/production.md +++ b/docs/self-hosting/production.md @@ -26,6 +26,7 @@ replica behind a load balancer. With local disk storage, run a single replica wi 3. **Database.** Use a managed Postgres (13+) or your own with backups and point-in-time recovery. Set `DATABASE_URL`, including `?sslmode=require` if your provider needs it. 4. **Attachments.** Use object storage for durability and multiple replicas: + ```env STORAGE_DRIVER=s3 S3_BUCKET=reprodrop-attachments @@ -34,8 +35,15 @@ replica behind a load balancer. With local disk storage, run a single replica wi S3_SECRET_ACCESS_KEY=… # S3_ENDPOINT=https://.r2.cloudflarestorage.com (R2, Garage, SeaweedFS, MinIO…) ``` + Keep the bucket private. Give the key only `s3:PutObject`, `s3:GetObject`, `s3:DeleteObject` on the bucket and `s3:ListBucket` for the health check. + + On a host without a persistent disk, for example a free tier that wipes the filesystem on + restart, `STORAGE_DRIVER=postgres` keeps attachments in the database instead. It suits small + instances: every screenshot counts against the database size, so keep `MAX_UPLOAD_BYTES` and + retention modest. See [render.md](render.md). + 5. **Sign-ups.** After your team has joined, set `ALLOW_SIGNUP=false`. Admins add members from Settings → Members. 6. **Extension origin.** Publish the extension privately and set diff --git a/docs/self-hosting/render.md b/docs/self-hosting/render.md new file mode 100644 index 0000000..f3969c7 --- /dev/null +++ b/docs/self-hosting/render.md @@ -0,0 +1,55 @@ +# Free hosting on Render and Neon + +Runs ReproDrop at no cost: the published Docker image on Render's free web service, with Neon's free +Postgres. Good for trying ReproDrop, a small team, or a demo. For anything you depend on, use +[production.md](production.md). + +## What to expect + +- **The server sleeps.** Render's free service stops after about 15 minutes without traffic, and the + next request takes about a minute while it starts. If a submission fails while it wakes, submit + again from the review page: it resumes where it stopped instead of creating a duplicate. +- **Attachments live in the database.** The free service's disk is wiped on every restart, so + [render.yaml](../../render.yaml) sets `STORAGE_DRIVER=postgres` and keeps screenshots in Postgres. + Uploads are capped at 2 MB each (`MAX_UPLOAD_BYTES`). +- **Neon's free plan holds 0.5 GB.** Reports are small, but screenshots add up. Keep the retention + period short (the **Privacy** page) and watch the size in Neon's dashboard. +- **No backups or uptime guarantee** on either free plan. + +## 1. Create the database (Neon) + +1. Sign up at [neon.tech](https://neon.tech) and create a project. Pick the region closest to + Render's Virginia region (AWS us-east-1). +2. Open **Connect**, turn **Connection pooling** off, and copy the connection string. It looks like + `postgresql://user:password@ep-….us-east-1.aws.neon.tech/neondb?sslmode=require`. Keep it secret. + +## 2. Deploy the server (Render) + +1. Sign up at [render.com](https://render.com). +2. Open . Render reads + [render.yaml](../../render.yaml) and shows one free web service, `reprodrop`. +3. Paste the Neon connection string into **DATABASE_URL**, then **Apply**. Render generates + `APP_SECRET` and `ENCRYPTION_KEY` itself, and `APP_URL` defaults to the service's address + (`https://reprodrop-….onrender.com`). +4. When the deploy finishes, open the service URL and create the first account. The database is + migrated on start, and `/api/health` reports `"storage": "ok"`. + +Don't change `APP_SECRET` or `ENCRYPTION_KEY` later. Sessions and stored Jira credentials depend on +them. + +## 3. Connect the extension + +In the extension's settings, set the server address to the service URL, and paste an API token +created under **Settings → API tokens**. + +## Running it for other people + +`ALLOW_SIGNUP` is `true` in the blueprint, so anyone with the URL can create an account. If the +server is only for your team, set it to `false` in Render's **Environment** tab once everyone has +joined. If you keep sign-up open, you're operating a service that holds other people's bug reports: +publish who runs it and how long data is kept, keep retention short, and expect to remove abuse. + +## Updating + +The blueprint pins an image version. To update, change the image tag under **Settings → Image** in +Render (for example `ghcr.io/patchyard/reprodrop:0.1.4`) and deploy. Migrations run on start. diff --git a/e2e/scripts/start-server.mjs b/e2e/scripts/start-server.mjs index f142008..79ef3ec 100644 --- a/e2e/scripts/start-server.mjs +++ b/e2e/scripts/start-server.mjs @@ -52,6 +52,8 @@ const child = spawn(process.execPath, [server], { APP_URL: process.env.E2E_APP_URL ?? `http://127.0.0.1:${port}`, DATABASE_URL: databaseUrl.toString(), DATA_DIR: dataDir, + // E2E_STORAGE_DRIVER=postgres runs the suite with attachments stored in the database. + STORAGE_DRIVER: process.env.E2E_STORAGE_DRIVER ?? "local", WEB_DIST_DIR: web, MIGRATIONS_DIR: path.join(root, "infra/migrations"), MIGRATE_ON_START: "true", diff --git a/infra/migrations/0001_attachment_blobs.sql b/infra/migrations/0001_attachment_blobs.sql new file mode 100644 index 0000000..84b754e --- /dev/null +++ b/infra/migrations/0001_attachment_blobs.sql @@ -0,0 +1,6 @@ +CREATE TABLE "attachment_blobs" ( + "key" text PRIMARY KEY NOT NULL, + "content_type" text NOT NULL, + "data" "bytea" NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL +); diff --git a/infra/migrations/meta/0001_snapshot.json b/infra/migrations/meta/0001_snapshot.json new file mode 100644 index 0000000..c9c3158 --- /dev/null +++ b/infra/migrations/meta/0001_snapshot.json @@ -0,0 +1,2215 @@ +{ + "id": "6942b444-0e44-41d3-a29f-381ce25d8f6a", + "prevId": "2082ab08-4042-4e80-b52d-5da0e116d5f8", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.api_tokens": { + "name": "api_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_prefix": { + "name": "token_prefix", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "api_tokens_hash_unique": { + "name": "api_tokens_hash_unique", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "api_tokens_org_user_idx": { + "name": "api_tokens_org_user_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "api_tokens_organization_id_organizations_id_fk": { + "name": "api_tokens_organization_id_organizations_id_fk", + "tableFrom": "api_tokens", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "api_tokens_user_id_users_id_fk": { + "name": "api_tokens_user_id_users_id_fk", + "tableFrom": "api_tokens", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.attachment_blobs": { + "name": "attachment_blobs", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit_logs": { + "name": "audit_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "target_id": { + "name": "target_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "audit_logs_org_created_idx": { + "name": "audit_logs_org_created_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "audit_logs_organization_id_organizations_id_fk": { + "name": "audit_logs_organization_id_organizations_id_fk", + "tableFrom": "audit_logs", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "audit_logs_actor_id_users_id_fk": { + "name": "audit_logs_actor_id_users_id_fk", + "tableFrom": "audit_logs", + "tableTo": "users", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.integration_tokens": { + "name": "integration_tokens", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "integration_id": { + "name": "integration_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "access_token_enc": { + "name": "access_token_enc", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "refresh_token_enc": { + "name": "refresh_token_enc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "integration_tokens_integration_unique": { + "name": "integration_tokens_integration_unique", + "columns": [ + { + "expression": "integration_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "integration_tokens_integration_id_integrations_id_fk": { + "name": "integration_tokens_integration_id_integrations_id_fk", + "tableFrom": "integration_tokens", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.integrations": { + "name": "integrations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "integration_provider", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "integration_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'connected'" + }, + "external_account_id": { + "name": "external_account_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "external_account_name": { + "name": "external_account_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "config": { + "name": "config", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "connected_by_id": { + "name": "connected_by_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "integrations_org_provider_unique": { + "name": "integrations_org_provider_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "integrations_organization_id_organizations_id_fk": { + "name": "integrations_organization_id_organizations_id_fk", + "tableFrom": "integrations", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "integrations_connected_by_id_users_id_fk": { + "name": "integrations_connected_by_id_users_id_fk", + "tableFrom": "integrations", + "tableTo": "users", + "columnsFrom": [ + "connected_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.jira_issues": { + "name": "jira_issues", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "integration_id": { + "name": "integration_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cloud_id": { + "name": "cloud_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issue_id": { + "name": "issue_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issue_key": { + "name": "issue_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "issue_url": { + "name": "issue_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "project_key": { + "name": "project_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attachments_uploaded": { + "name": "attachments_uploaded", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "attachment_errors": { + "name": "attachment_errors", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by_id": { + "name": "created_by_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "jira_issues_report_unique": { + "name": "jira_issues_report_unique", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "jira_issues_org_idx": { + "name": "jira_issues_org_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "jira_issues_organization_id_organizations_id_fk": { + "name": "jira_issues_organization_id_organizations_id_fk", + "tableFrom": "jira_issues", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "jira_issues_report_id_reports_id_fk": { + "name": "jira_issues_report_id_reports_id_fk", + "tableFrom": "jira_issues", + "tableTo": "reports", + "columnsFrom": [ + "report_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "jira_issues_integration_id_integrations_id_fk": { + "name": "jira_issues_integration_id_integrations_id_fk", + "tableFrom": "jira_issues", + "tableTo": "integrations", + "columnsFrom": [ + "integration_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "jira_issues_created_by_id_users_id_fk": { + "name": "jira_issues_created_by_id_users_id_fk", + "tableFrom": "jira_issues", + "tableTo": "users", + "columnsFrom": [ + "created_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.oauth_states": { + "name": "oauth_states", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "state_hash": { + "name": "state_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "integration_provider", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "consumed_at": { + "name": "consumed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "oauth_states_hash_unique": { + "name": "oauth_states_hash_unique", + "columns": [ + { + "expression": "state_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "oauth_states_user_id_users_id_fk": { + "name": "oauth_states_user_id_users_id_fk", + "tableFrom": "oauth_states", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "oauth_states_organization_id_organizations_id_fk": { + "name": "oauth_states_organization_id_organizations_id_fk", + "tableFrom": "oauth_states", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organization_members": { + "name": "organization_members", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "member_role", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "organization_members_org_user_unique": { + "name": "organization_members_org_user_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "organization_members_user_idx": { + "name": "organization_members_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "organization_members_organization_id_organizations_id_fk": { + "name": "organization_members_organization_id_organizations_id_fk", + "tableFrom": "organization_members", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "organization_members_user_id_users_id_fk": { + "name": "organization_members_user_id_users_id_fk", + "tableFrom": "organization_members", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.organizations": { + "name": "organizations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_personal": { + "name": "is_personal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "report_counter": { + "name": "report_counter", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "retention_days": { + "name": "retention_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 90 + }, + "allow_share_links": { + "name": "allow_share_links", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "max_share_link_hours": { + "name": "max_share_link_hours", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 168 + }, + "excluded_url_patterns": { + "name": "excluded_url_patterns", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "organizations_slug_unique": { + "name": "organizations_slug_unique", + "columns": [ + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.projects": { + "name": "projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "projects_org_slug_unique": { + "name": "projects_org_slug_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "projects_organization_id_organizations_id_fk": { + "name": "projects_organization_id_organizations_id_fk", + "tableFrom": "projects", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.report_attachments": { + "name": "report_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "attachment_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'screenshot'" + }, + "client_ref": { + "name": "client_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "storage_key": { + "name": "storage_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "filename": { + "name": "filename", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "width": { + "name": "width", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "offset_ms": { + "name": "offset_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "report_attachments_report_idx": { + "name": "report_attachments_report_idx", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "report_attachments_storage_key_unique": { + "name": "report_attachments_storage_key_unique", + "columns": [ + { + "expression": "storage_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "report_attachments_organization_id_organizations_id_fk": { + "name": "report_attachments_organization_id_organizations_id_fk", + "tableFrom": "report_attachments", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "report_attachments_report_id_reports_id_fk": { + "name": "report_attachments_report_id_reports_id_fk", + "tableFrom": "report_attachments", + "tableTo": "reports", + "columnsFrom": [ + "report_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.report_events": { + "name": "report_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "report_event_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "offset_ms": { + "name": "offset_ms", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "report_events_report_seq_unique": { + "name": "report_events_report_seq_unique", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "report_events_report_type_idx": { + "name": "report_events_report_type_idx", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "report_events_organization_id_organizations_id_fk": { + "name": "report_events_organization_id_organizations_id_fk", + "tableFrom": "report_events", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "report_events_report_id_reports_id_fk": { + "name": "report_events_report_id_reports_id_fk", + "tableFrom": "report_events", + "tableTo": "reports", + "columnsFrom": [ + "report_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reports": { + "name": "reports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "reporter_id": { + "name": "reporter_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "expected_result": { + "name": "expected_result", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "actual_result": { + "name": "actual_result", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "steps": { + "name": "steps", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "status": { + "name": "status", + "type": "report_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "source": { + "name": "source", + "type": "report_source", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'extension'" + }, + "page_url": { + "name": "page_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "page_title": { + "name": "page_title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "browser_name": { + "name": "browser_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "browser_version": { + "name": "browser_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "os_name": { + "name": "os_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "os_version": { + "name": "os_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "viewport_width": { + "name": "viewport_width", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "viewport_height": { + "name": "viewport_height", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "device_pixel_ratio": { + "name": "device_pixel_ratio", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "environment": { + "name": "environment", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "console_error_count": { + "name": "console_error_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "network_error_count": { + "name": "network_error_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "playwright_script": { + "name": "playwright_script", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "recorded_at": { + "name": "recorded_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "reports_org_number_unique": { + "name": "reports_org_number_unique", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reports_org_created_idx": { + "name": "reports_org_created_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reports_org_status_idx": { + "name": "reports_org_status_idx", + "columns": [ + { + "expression": "organization_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reports_project_idx": { + "name": "reports_project_idx", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reports_deleted_idx": { + "name": "reports_deleted_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reports_organization_id_organizations_id_fk": { + "name": "reports_organization_id_organizations_id_fk", + "tableFrom": "reports", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reports_project_id_projects_id_fk": { + "name": "reports_project_id_projects_id_fk", + "tableFrom": "reports", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reports_reporter_id_users_id_fk": { + "name": "reports_reporter_id_users_id_fk", + "tableFrom": "reports", + "tableTo": "users", + "columnsFrom": [ + "reporter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sessions": { + "name": "sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "active_organization_id": { + "name": "active_organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "csrf_token": { + "name": "csrf_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sessions_user_idx": { + "name": "sessions_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "sessions_expires_idx": { + "name": "sessions_expires_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "sessions_active_organization_id_organizations_id_fk": { + "name": "sessions_active_organization_id_organizations_id_fk", + "tableFrom": "sessions", + "tableTo": "organizations", + "columnsFrom": [ + "active_organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.share_links": { + "name": "share_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "organization_id": { + "name": "organization_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by_id": { + "name": "created_by_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_accessed_at": { + "name": "last_accessed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "access_count": { + "name": "access_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "share_links_token_hash_unique": { + "name": "share_links_token_hash_unique", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "share_links_report_idx": { + "name": "share_links_report_idx", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "share_links_organization_id_organizations_id_fk": { + "name": "share_links_organization_id_organizations_id_fk", + "tableFrom": "share_links", + "tableTo": "organizations", + "columnsFrom": [ + "organization_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "share_links_report_id_reports_id_fk": { + "name": "share_links_report_id_reports_id_fk", + "tableFrom": "share_links", + "tableTo": "reports", + "columnsFrom": [ + "report_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "share_links_created_by_id_users_id_fk": { + "name": "share_links_created_by_id_users_id_fk", + "tableFrom": "share_links", + "tableTo": "users", + "columnsFrom": [ + "created_by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_email_unique": { + "name": "users_email_unique", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.attachment_kind": { + "name": "attachment_kind", + "schema": "public", + "values": [ + "screenshot" + ] + }, + "public.report_event_type": { + "name": "report_event_type", + "schema": "public", + "values": [ + "click", + "input", + "navigation", + "console", + "network", + "screenshot", + "recording", + "viewport" + ] + }, + "public.integration_provider": { + "name": "integration_provider", + "schema": "public", + "values": [ + "jira" + ] + }, + "public.integration_status": { + "name": "integration_status", + "schema": "public", + "values": [ + "connected", + "needs_reauth", + "error" + ] + }, + "public.member_role": { + "name": "member_role", + "schema": "public", + "values": [ + "owner", + "admin", + "member" + ] + }, + "public.report_source": { + "name": "report_source", + "schema": "public", + "values": [ + "extension", + "api", + "demo" + ] + }, + "public.report_status": { + "name": "report_status", + "schema": "public", + "values": [ + "open", + "in_progress", + "resolved", + "closed" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/infra/migrations/meta/_journal.json b/infra/migrations/meta/_journal.json index 99bdfe2..8b5679b 100644 --- a/infra/migrations/meta/_journal.json +++ b/infra/migrations/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1796119636083, "tag": "0000_init", "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1796136890050, + "tag": "0001_attachment_blobs", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/config/src/index.test.ts b/packages/config/src/index.test.ts index 19cd594..8553132 100644 --- a/packages/config/src/index.test.ts +++ b/packages/config/src/index.test.ts @@ -20,6 +20,18 @@ describe("parseEnv", () => { expect(env.jiraMode).toBe("live"); }); + it("uses Render's public address when APP_URL isn't set", () => { + const { DATABASE_URL } = base; + const env = parseEnv({ DATABASE_URL, RENDER_EXTERNAL_URL: "https://reprodrop.onrender.com" }); + expect(env.APP_URL).toBe("https://reprodrop.onrender.com"); + const explicit = parseEnv({ ...base, RENDER_EXTERNAL_URL: "https://reprodrop.onrender.com" }); + expect(explicit.APP_URL).toBe("http://localhost:3000"); + }); + + it("accepts the postgres storage driver", () => { + expect(parseEnv({ ...base, STORAGE_DRIVER: "postgres" }).STORAGE_DRIVER).toBe("postgres"); + }); + it("treats empty values as unset", () => { const env = parseEnv({ ...base, PORT: "", JIRA_CLIENT_ID: "" }); expect(env.PORT).toBe(3000); diff --git a/packages/config/src/index.ts b/packages/config/src/index.ts index 78f08d4..20b6e0e 100644 --- a/packages/config/src/index.ts +++ b/packages/config/src/index.ts @@ -38,7 +38,7 @@ export const envSchema = z ALLOW_SIGNUP: booleanString.default(true), WEB_DIST_DIR: optionalString, - STORAGE_DRIVER: z.enum(["local", "s3"]).default("local"), + STORAGE_DRIVER: z.enum(["local", "s3", "postgres"]).default("local"), STORAGE_LOCAL_DIR: optionalString, S3_ENDPOINT: optionalString, S3_REGION: z.string().default("us-east-1"), @@ -138,6 +138,9 @@ export function parseEnv(source: Record): ResolvedCo const cleaned = Object.fromEntries( Object.entries(source).filter(([, v]) => v !== undefined && v !== ""), ); + // Render sets RENDER_EXTERNAL_URL to the service's public address; use it when APP_URL isn't set. + if (!cleaned.APP_URL && cleaned.RENDER_EXTERNAL_URL) + cleaned.APP_URL = cleaned.RENDER_EXTERNAL_URL; const result = envSchema.safeParse(cleaned); if (!result.success) { throw new ConfigError( diff --git a/packages/database/src/schema.ts b/packages/database/src/schema.ts index 57781d5..e8ae4f2 100644 --- a/packages/database/src/schema.ts +++ b/packages/database/src/schema.ts @@ -1,6 +1,7 @@ import { sql } from "drizzle-orm"; import { boolean, + customType, index, integer, jsonb, @@ -453,6 +454,23 @@ export const auditLogs = pgTable( (t) => [index("audit_logs_org_created_idx").on(t.organizationId, t.createdAt)], ); +const bytea = customType<{ data: Buffer; driverData: Buffer }>({ + dataType: () => "bytea", +}); + +/** + * Attachment bytes for the `postgres` storage driver (STORAGE_DRIVER=postgres), used on hosts + * whose disk doesn't survive a restart. It's a storage backend, not tenant data: rows are only + * reached by storage key through the Storage interface, after `report_attachments` (which + * carries `organization_id`) has authorized the request. + */ +export const attachmentBlobs = pgTable("attachment_blobs", { + key: text("key").primaryKey(), + contentType: text("content_type").notNull(), + data: bytea("data").notNull(), + createdAt: createdAt(), +}); + export type User = typeof users.$inferSelect; export type Organization = typeof organizations.$inferSelect; export type OrganizationMember = typeof organizationMembers.$inferSelect; @@ -466,5 +484,6 @@ export type IntegrationToken = typeof integrationTokens.$inferSelect; export type JiraIssue = typeof jiraIssues.$inferSelect; export type ShareLink = typeof shareLinks.$inferSelect; export type AuditLog = typeof auditLogs.$inferSelect; +export type AttachmentBlob = typeof attachmentBlobs.$inferSelect; export type ApiToken = typeof apiTokens.$inferSelect; export type Session = typeof sessions.$inferSelect; diff --git a/render.yaml b/render.yaml new file mode 100644 index 0000000..9e78e72 --- /dev/null +++ b/render.yaml @@ -0,0 +1,34 @@ +# Render Blueprint: ReproDrop as one free web service, running the published Docker image. +# +# The database is external. Neon's free Postgres works well: paste its connection string when +# Render asks for DATABASE_URL. Render generates the two secrets, and APP_URL defaults to the +# service's public address. Attachments are stored in Postgres because the free tier's disk is +# wiped on every restart. Full guide: docs/self-hosting/render.md +services: + - type: web + name: reprodrop + runtime: image + image: + url: ghcr.io/patchyard/reprodrop:0.1.3 + plan: free + region: virginia + healthCheckPath: /api/health + envVars: + - key: DATABASE_URL + sync: false + - key: APP_SECRET + generateValue: true + - key: ENCRYPTION_KEY + generateValue: true + - key: AUTO_GENERATE_SECRETS + value: "false" + - key: STORAGE_DRIVER + value: postgres + - key: MAX_UPLOAD_BYTES + value: "2097152" + - key: TRUST_PROXY + value: "true" + - key: ALLOW_SIGNUP + value: "true" + - key: MIGRATE_ON_START + value: "true"