Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Aug 28, 2025

https://linear.app/discourse-graphs/issue/ENG-801/compile-database-before-dev
Took on much of the scope of ENG-799

  • Precompile dbDotEnv so database does not have to be built beforehand
  • Introduce SUPABASE_USE_DB=none. (Now the default value.)
  • dev and build in database will not activate supabase if that is set.

Summary by CodeRabbit

  • New Features
    • Added support to run the app without a database (now the default), automatically skipping local DB setup when not needed.
  • Documentation
    • Updated usage scenarios to include “Developing without the database.”
    • Clarified local development steps, including how to opt into a local database.
  • Chores
    • Streamlined build and development workflows for database-related tasks.
    • Separated schema generation into its own task for clearer, faster builds.

@linear
Copy link

linear bot commented Aug 28, 2025

@supabase
Copy link

supabase bot commented Aug 28, 2025

This pull request has been ignored for the connected project zytfjzqyijgagqxrzbmz because there are no changes detected in packages/database/supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@maparent maparent requested a review from mdroidian August 28, 2025 09:30
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this suggest we need to have docker/supabase running to run roam dev?

We want to try and avoid this if at all possible.

@maparent
Copy link
Collaborator Author

It's the current situation, and I agree it's definitely not ideal, and thinking about how to avoid this in ENG-799.
ENG-781 is also relevant.
I still think this PR makes sense as a temporary patch until it's solved.

@mdroidian
Copy link
Contributor

mdroidian commented Aug 28, 2025

Why is it the current situation? What changed to make it the current situation (as it was not recently). Is it avoidable? If not, why not?

@maparent
Copy link
Collaborator Author

Replied elsewhere.

Make build depend on building the schema, but not check-types.
(Still thinking about the pros and cons here)
Introduce SUPABASE_USE_DB=none. (Now the default value.)
dev and build in database will not activate supabase if that is set.
@maparent maparent requested a review from mdroidian August 28, 2025 19:08
@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 28, 2025

📝 Walkthrough

Walkthrough

Introduces a “none” database variant and makes it the default. Updates db environment utilities and exports to support it, adds a dev script that compiles and conditionally serves, modifies the build script to early-exit for “none”, adjusts Turbo tasks to isolate schema generation, and updates documentation accordingly.

Changes

Cohort / File(s) Summary
Docs update
packages/database/README.md
Adds a fourth usage scenario “Developing without the database”, notes SUPABASE_USE_DB=none as default, and instructs setting SUPABASE_USE_DB=local for local DB dev.
Package exports and scripts
packages/database/package.json
Points ./dbDotEnv export to src/* (types/require/default). Adds scripts: dev (tsx scripts/dev.ts), compile, serve, build simplified to tsc, and build-schema (build + genenv local).
Dev workflow script
packages/database/scripts/dev.ts
New script: compiles, checks variant via getVariant(), exits if “none”; otherwise runs serve. Skips on Vercel.
Build flow changes
packages/database/scripts/build.ts
Uses getVariant(); if “none”, logs and exits before Supabase start/migrations/type-gen; otherwise retains prior flow.
Env utilities (JS + d.ts)
packages/database/src/dbDotEnv.js, packages/database/src/dbDotEnv.d.ts
Adds “none” variant, makes it default, validates variants, returns null env file for “none”; removes TS annotations and unused import; declares getVariant, envFilePath, envContents, config in d.ts.
Turbo pipeline
turbo.json
Moves src/dbTypes.ts to new build-schema task with its own inputs/outputs; removes it from build outputs; removes deploy.dependsOn.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant DevScript as scripts/dev.ts
  participant Env as dbDotEnv.getVariant()
  participant Serve as npm run serve
  participant Compile as npm run compile

  Dev->>DevScript: npm run dev
  DevScript->>Compile: Build TS (local only)
  DevScript->>Env: getVariant()
  alt variant == "none"
    DevScript-->>Dev: Log "Not using the database" and exit 0
  else variant in {local, branch, production}
    DevScript->>Serve: Start local database services
  end
Loading
sequenceDiagram
  autonumber
  actor CI as CI/Local
  participant BuildScript as scripts/build.ts
  participant Env as dbDotEnv.getVariant()
  participant SB as Supabase CLI
  participant Types as Generate db types

  CI->>BuildScript: build-schema
  BuildScript->>Env: getVariant()
  alt variant == "none"
    BuildScript-->>CI: Log and exit 0 (skip DB ops)
  else
    BuildScript->>SB: supabase start
    BuildScript->>SB: supabase migrations up
    BuildScript->>Types: Generate src/dbTypes.ts
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/database/README.md (2)

44-48: Update steps to reflect new build-schema task

README still says types are generated during “turbo build”, but turbo.json moves this to “build-schema”. Please align docs.

-7. `turbo build`, which will do the following:
+7. `turbo run build-schema`, which will do the following:
   1. Start Supabase
   2. Apply the new migration locally
-  3. Regenerate the types file with `supabase gen types typescript --local > src/dbTypes.ts`
-  4. Copy it where appropriate
+  3. Regenerate the types file with `supabase gen types typescript --local --schema public > src/dbTypes.ts`
+  4. Copy it where appropriate

70-72: Typo: duplicated word

“another other terminal” → “another terminal”.

-2. In another other terminal, `cd` to this directory (`packages/database`) and run the tests with `npm run test`
+2. In another terminal, `cd` to this directory (`packages/database`) and run the tests with `npm run test`
packages/database/scripts/build.ts (1)

1-29: Use ESM-safe __dirname & stop Supabase in finally

Import fileURLToPath from "url" and derive __filename/__dirname via import.meta.url. Wrap the Supabase start/migrations sequence in a try…finally, tracking a started flag to invoke supabase stop and avoid orphaned containers:

import { fileURLToPath } from "url";
import { dirname, join } from "path";
import { execSync } from "node:child_process";
import { writeFileSync } from "fs";
import { getVariant } from "@repo/database/dbDotEnv";

const __filename = fileURLToPath(import.meta.url);
const __dirname  = dirname(__filename);
const projectRoot = join(__dirname, "..");

if (process.env.HOME !== "/vercel") {
  const variant = getVariant();
  if (variant === "none") {
    console.log("Not using the database");
    process.exit(0);
  }

  let started = false;
  try {
    execSync("supabase start",        { cwd: projectRoot, stdio: "inherit" });
    started = true;
    execSync("supabase migrations up",{ cwd: projectRoot, stdio: "inherit" });
    const stdout = execSync(
      "supabase gen types typescript --local --schema public",
      { encoding: "utf8", cwd: projectRoot }
    );
    writeFileSync(
      join(projectRoot, "src", "dbTypes.ts"),
      "// Generated by supabase -- do not edit\n" + stdout
    );
  } finally {
    if (started) {
      try { execSync("supabase stop", { cwd: projectRoot, stdio: "inherit" }); }
      catch {}
    }
  }
}
🧹 Nitpick comments (7)
packages/database/README.md (4)

3-9: Clarify the “no DB” default and add a quick-start note

Consider adding a one-liner like “Default: SUPABASE_USE_DB=none; nothing DB-related runs during dev/build” to make the behavior unmistakable for newcomers. Also mention how to override at runtime (e.g., SUPABASE_USE_DB=local turbo dev).


12-15: Grammar/style: Docker capitalization and clearer phrasing

  • “within docker” → “in Docker”.
  • “It does mean you will have a fresh database with minimal data.” → “This means you’ll have a fresh, minimally seeded database.”
-Normal scenario: Your backend and frontend will work against a database instance within docker.
-It does mean you will have a fresh database with minimal data.
+Normal scenario: Your backend and frontend will work against a database instance in Docker.
+This means you’ll have a fresh, minimally seeded database.

24-26: Minor copy edit

“its url” → “its URL”.

-2. You can use the Supabase studio to look over things; its url is given by the database section of `supabase start`.
+2. You can use the Supabase Studio to look over things; its URL is shown in the database section of `supabase start`.

91-93: Minor copy edit

“set up vercel” → “Set up Vercel”. Capitalize brand and fix verb form.

-But in most other cases, you will want your code to talk to the production database. set up vercel as above, and set `SUPABASE_USE_DB=production` in your console before running `turbo dev`.
+But in most other cases, you will want your code to talk to the production database. Set up Vercel as above, and set `SUPABASE_USE_DB=production` in your console before running `turbo dev`.
packages/database/src/dbDotEnv.js (1)

29-33: Minor: null check can be simplified after getVariant() change

With CI returning "none", variant === null is no longer needed.

-  const variant = getVariant();
-  if (variant === null || variant === "none") return null;
+  const variant = getVariant();
+  if (variant === "none") return null;
packages/database/package.json (2)

45-48: Optionally gate “serve” behind SUPABASE_USE_DB.

If “none” is default, avoid starting Supabase by default in serve. Keeps behavior consistent with PR intent.

-    "serve": "supabase start && tsx scripts/createEnv.mts && supabase functions serve",
+    "serve": "node -e \"const v=process.env.SUPABASE_USE_DB||'none'; if(v==='none'){console.log('SUPABASE_USE_DB=none: skipping supabase'); process.exit(0)} else process.exit(1)\" || (supabase start && tsx scripts/createEnv.mts && supabase functions serve)",

Confirm this aligns with how you intend to use serve locally/CI.


53-55: DRY build script and verify build-schema semantics.

Alias build to compile to avoid divergence; ensure genenv -- local is desired when SUPABASE_USE_DB=none.

-    "build": "tsc",
+    "build": "npm run compile",

If build-schema should no-op when SUPABASE_USE_DB=none, mirror the guard used in serve.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 35a2d55 and 1031927.

📒 Files selected for processing (7)
  • packages/database/README.md (1 hunks)
  • packages/database/package.json (2 hunks)
  • packages/database/scripts/build.ts (1 hunks)
  • packages/database/scripts/dev.ts (1 hunks)
  • packages/database/src/dbDotEnv.d.ts (1 hunks)
  • packages/database/src/dbDotEnv.js (1 hunks)
  • turbo.json (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-07-22T01:50:20.253Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-22T01:50:20.253Z
Learning: In packages/database/scripts/create_env.ts, the Vercel CLI integration uses both vercel/sdk for deployment queries and vercel CLI for environment variable pulling, with support for different variants (local, branch, production, all) and proper team/project configuration with discourse-graphs defaults.

Applied to files:

  • packages/database/scripts/dev.ts
  • packages/database/scripts/build.ts
  • packages/database/src/dbDotEnv.d.ts
  • packages/database/package.json
📚 Learning: 2025-05-22T23:48:45.450Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/scripts/deploy.ts:0-0
Timestamp: 2025-05-22T23:48:45.450Z
Learning: The database deployment script in packages/database/scripts/deploy.ts requires that the branch is 'main' and pristine (no uncommitted or unpushed changes) before allowing deployment to proceed.

Applied to files:

  • packages/database/scripts/dev.ts
📚 Learning: 2025-06-25T18:03:52.669Z
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#241
File: packages/database/tsconfig.json:3-7
Timestamp: 2025-06-25T18:03:52.669Z
Learning: The packages/database directory in the discourse-graph repository has a unique structure as a database schema/migration package. It contains doc/, scripts/, supabase/ directories and TypeScript files at the root level, but no typical src/, test/, dist/, or node_modules directories. The current tsconfig.json with "include": ["."] and "exclude": ["supabase"] is appropriate for this structure.

Applied to files:

  • packages/database/package.json
🪛 LanguageTool
packages/database/README.md

[grammar] ~12-~12: There might be a mistake here.
Context: ...ainst a database instance within docker. It does mean you will have a fresh datab...

(QB_NEW_EN)

🔇 Additional comments (3)
turbo.json (2)

66-66: Ensure build precedes deploy
Verify your CI workflows enforce the build step before running turbo deploy, since removing the explicit dependsOn could allow deployment without a prior build.


47-51: build-schema is correctly wired
Both website and roam depend on @repo/database, so they automatically inherit its build-schema task via the Turbo pipeline and have the DB types available.

packages/database/scripts/dev.ts (1)

10-16: Scripts verified—no changes needed
Both compile (“tsc”) and serve (“supabase start && tsx scripts/createEnv.mts && supabase functions serve”) are defined in packages/database/package.json. The serve command is never invoked when SUPABASE_USE_DB=none, and compile simply runs the TypeScript compiler, so no DB access occurs.

@mdroidian mdroidian merged commit 6bcad0d into main Aug 28, 2025
4 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Aug 28, 2025
@mdroidian mdroidian deleted the eng-801-compile-database-before-dev branch August 28, 2025 20:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants