Skip to content

Conversation

maparent
Copy link
Collaborator

@maparent maparent commented Jul 22, 2025

This code auto-constructs up to three environment files in packages/database: .env.{local, branch, production}. These are for development, so the local code can speak to the appropriate supabase instance, and not expected to be present in production. The base scenario is running against the local supabase, hence using .env.local`.
It is also possible to talk directly against either a supabase branch or the production database. Use cases for either should be extremely rare, and are documented separately. For this, set SUPABASE_USE_DB to 'branch' or 'production' respectively. The branch used will be the current branch, unless overridden by SUPABASE_GIT_BRANCH.

Summary by CodeRabbit

  • New Features

    • Automated generation and management of environment variable files for local, branch, and production deployments.
    • Centralized environment configuration utilities for easier and safer access to deployment-specific variables.
  • Bug Fixes

    • Added safeguards to prevent running destructive tests in production environments.
  • Documentation

    • Significantly expanded and clarified database package documentation, including detailed setup, development, and deployment instructions.
  • Chores

    • Updated environment variable handling across multiple components to use the new centralized utilities.
    • Enhanced build and development scripts to support new environment workflows.
    • Broadened recognized environment variables in project configuration for improved compatibility and deployment.

Copy link

linear bot commented Jul 22, 2025

Copy link

supabase bot commented Jul 22, 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
Copy link
Collaborator Author

@CodeRabbit review
Note this still requires more testing, but starting the review process now.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll help you review this PR! Let me examine the changes to understand what's been implemented for grabbing Supabase keys from Vercel using the CLI.


🏁 Script executed:

#!/bin/bash
# Get the list of changed files in this PR
git diff --name-only HEAD~1 HEAD

# Get a summary of the changes
git diff --stat HEAD~1 HEAD

# Look at the actual changes
git diff HEAD~1 HEAD

Length of output: 648


Let me try different approaches to examine the changes in this PR:


🏁 Script executed:

#!/bin/bash
# Check git log to understand the commit structure
git log --oneline -10

# Check git status to see any changes
git status

# Look for files that might be related to Vercel CLI or deployment
fd -t f -e ts -e js -e json | grep -E "(vercel|deploy|script)" | head -20

# Search for any files containing vercel or supabase references
rg -l "vercel" --type=ts --type=js --type=json | head -10
rg -l "supabase.*key" --type=ts --type=js --type=json | head -10

Length of output: 1262


Let me examine the specific files that are most likely to contain the Vercel CLI integration for Supabase keys:


🏁 Script executed:

#!/bin/bash
# Examine the key files that might contain the changes
echo "=== packages/database/scripts/create_env.ts ==="
cat packages/database/scripts/create_env.ts

echo -e "\n=== packages/database/scripts/deploy.ts ==="
cat packages/database/scripts/deploy.ts

echo -e "\n=== packages/database/dbdotenv.ts ==="
cat packages/database/dbdotenv.ts

# Also check if there are any recent modifications by looking at file timestamps
echo -e "\n=== Recent file modifications ==="
find . -name "*.ts" -path "*/database/scripts/*" -exec ls -la {} \;

Length of output: 8255


@maparent Thank you for starting the review process! I can see this is a comprehensive implementation for ENG-625. Let me examine a few more details to provide a thorough review:


🏁 Script executed:

#!/bin/bash
# Check if @vercel/sdk is properly added to dependencies
cat packages/database/package.json | jq '.dependencies | keys[] | select(. | contains("vercel"))'

# Look for any existing vercel configuration
fd "vercel" --type f

# Check if there are any tests for the new functionality
fd -e test.ts -e spec.ts | xargs grep -l "create_env\|vercel" 2>/dev/null || echo "No tests found for create_env"

# Check for any documentation about this new feature
fd -e md | xargs grep -l -i "vercel.*key\|supabase.*vercel" 2>/dev/null || echo "No documentation found"

Length of output: 446


🏁 Script executed:

#!/bin/bash
# Check the full package.json structure
echo "=== packages/database/package.json ==="
cat packages/database/package.json

# Also check if vercel CLI is available or mentioned anywhere
echo -e "\n=== Checking for vercel CLI references ==="
rg "vercel.*env.*pull" --type=ts -A 2 -B 2

# Check if there are any import statements for @vercel/sdk
echo -e "\n=== Checking @vercel/sdk imports ==="
rg "from.*@vercel/sdk" --type=ts -A 1 -B 1

Length of output: 2885


@maparent I've completed my review of the Vercel CLI integration for grabbing Supabase keys! This is a well-implemented solution for ENG-625. Here's my comprehensive analysis:

Strengths

Solid Architecture & Design:

  • Clean separation of concerns with different environment variants (local, branch, production, all)
  • Proper integration of both Vercel SDK (for deployment queries) and Vercel CLI (for env pulling)
  • Smart fallback to skip execution when running on Vercel (process.env.HOME === "/vercel")
  • Good use of existing project patterns (consistent with the learning about database deployment scripts requiring pristine branches)

Dependencies & Configuration:

  • Both @vercel/sdk (1.10.0) and vercel (44.5.0) are properly added to devDependencies
  • New npm scripts are well-organized: genenv, genenv:branch, genenv:production, etc.
  • Environment variable configuration is flexible with proper overrides

Security & Error Handling:

  • Proper token validation with clear error messages
  • Team/project configuration with fallbacks (VERCEL_TEAM_SLUG defaulting to "discourse-graphs")
  • Graceful handling of missing deployments with warnings

🔍 Areas for Improvement

Error Handling & Robustness:

// Consider adding validation for the vercel CLI availability
const checkVercelCli = () => {
  try {
    execSync("vercel --version", { stdio: 'ignore' });
  } catch {
    throw new Error("Vercel CLI not found. Run 'npm install -g vercel' first.");
  }
};

Code Organization:

  • The create_env.ts file is getting quite large (3800+ chars). Consider extracting the individual env functions into separate modules
  • The git branch detection logic could be extracted to a utility function

Testing & Documentation:

  • No tests found for this critical functionality
  • No documentation about the new Vercel integration workflow

🚨 Minor Issues

Type Safety:

// Line 71: Optional chaining could be cleaner
const branchM = stdout.match(/On branch (.*)/)?.[1];
if (!branchM) throw new Error("Could not find the git branch");
// Instead of: if (branchM) branch = branchM;

Consistency:

  • Mix of == and === comparisons (line 112 uses ==, should be ===)

📋 Recommendations for Follow-up

  1. Add unit tests for the environment generation functions
  2. Create documentation explaining the new workflow and required environment variables
  3. Consider extracting environment-specific functions into separate files
  4. Add Vercel CLI availability check before attempting to use it

🎯 Overall Assessment

This is a solid implementation that effectively addresses the requirements. The code integrates well with the existing codebase patterns and provides the flexibility needed for different deployment scenarios. The use of both Vercel SDK and CLI is appropriate for the different use cases.

The implementation is ready for testing, though I'd recommend addressing the testing and documentation gaps in follow-up work.


✏️ Learnings added
Learnt from: maparent
URL: https://github.com/DiscourseGraphs/discourse-graph/pull/301

Timestamp: 2025-07-22T01:50:20.212Z
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.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.

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.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

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.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/config.toml:0-0
Timestamp: 2025-05-20T15:51:22.084Z
Learning: Wildcard patterns in additional_redirect_urls within Supabase configuration are acceptable in this codebase when needed for Vercel branch deployments, despite the small security risk they introduce.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250504202930_content_tables.sql:37-45
Timestamp: 2025-05-20T03:11:07.917Z
Learning: When reviewing SQL migrations in this codebase, understand that historical migration files should not be modified once they're applied. Instead, issues should be fixed in subsequent migrations or schema definition files. This is why maparent indicated "migration, not changing. corrected in schema."

@maparent
Copy link
Collaborator Author

@CodeRabbit I added documentation, let me know if you see issues there.
As for presence of vercel cli, it is necessarily available through adding the vercel package.

Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@maparent Thank you for adding the documentation and clarifying the CLI availability! Let me examine the new documentation to provide feedback.


🏁 Script executed:

#!/bin/bash
# Look for recently added documentation files
echo "=== Looking for documentation files ==="
fd -e md | head -10

# Check for any README updates or new documentation
echo -e "\n=== Checking for README updates ==="
cat README.md 2>/dev/null | tail -50 || echo "No README.md found in root"

# Look specifically in the database package for documentation
echo -e "\n=== Checking packages/database documentation ==="
fd -e md -p "packages/database"
cat packages/database/README.md 2>/dev/null || echo "No README in packages/database"

# Search for recent mentions of vercel in documentation
echo -e "\n=== Searching for vercel documentation ==="
rg -i "vercel.*env\|env.*vercel\|genenv" --type=md -A 3 -B 1

Length of output: 8976


@maparent I can see the comprehensive database documentation, and you're absolutely right about the vercel CLI availability through the package dependency! Let me look more specifically for the documentation about the new Vercel environment generation workflow:


🏁 Script executed:

#!/bin/bash
# Look more specifically for genenv documentation
echo "=== Searching for genenv and environment generation documentation ==="
rg -i "genenv" --type=md -A 5 -B 2

# Check if there are any new sections in the README about environment generation
echo -e "\n=== Checking for environment-related sections in README ==="
rg -i "environment.*variable|vercel.*env|env.*generation" --type=md -A 3 -B 1

# Look for any documentation about the new npm scripts
echo -e "\n=== Searching for npm script documentation ==="
rg -i "npm.*genenv|genenv.*script" --type=md -A 3 -B 1

# Check if there's documentation about VERCEL_TOKEN or other required env vars
echo -e "\n=== Looking for Vercel token documentation ==="
rg -i "VERCEL_TOKEN|vercel.*token|environment.*setup" --type=md -A 2 -B 1

Length of output: 2192


I'm not finding specific documentation about the new genenv functionality in the markdown files. Let me check if the documentation was added as comments in the code or in other locations:


🏁 Script executed:

#!/bin/bash
# Check the create_env.ts file for any documentation comments
echo "=== Checking create_env.ts for documentation comments ==="
head -50 packages/database/scripts/create_env.ts | grep -E "^//|^/\*|\*"

# Check git status to see if there are uncommitted documentation changes
echo -e "\n=== Git status to check for uncommitted changes ==="
git status --porcelain

# Look for any JSDoc or inline documentation in the create_env file
echo -e "\n=== Looking for inline documentation in create_env.ts ==="
rg -A 3 -B 1 "^/\*\*|^//.*[Gg]enenv|^//.*[Vv]ercel|^//.*[Ee]nvironment" packages/database/scripts/create_env.ts

# Check if there are any other documentation files or formats
echo -e "\n=== Looking for other documentation formats ==="
fd -e txt -e rst -e adoc packages/database/ | head -5

# Check the package.json scripts section for any documentation
echo -e "\n=== Checking package.json scripts for documentation ==="
cat packages/database/package.json | jq '.scripts | to_entries | map(select(.key | contains("genenv"))) | from_entries'

Length of output: 1706


@maparent I can see the genenv scripts are properly configured in package.json, but I'm not finding specific documentation about the new Vercel CLI integration workflow. Let me check the main README one more time for any new sections:

Based on my search, I don't see specific documentation about the new Vercel environment generation workflow. Here's my feedback:

Acknowledged - Vercel CLI Availability

You're absolutely correct about the Vercel CLI availability! Since the vercel package (44.5.0) is in devDependencies, the CLI will be available in node_modules/.bin/vercel when installed. My suggestion about checking CLI availability was unnecessary.

📋 Documentation Feedback

While the existing README has excellent coverage of the database development workflow, I think the new Vercel environment generation feature could benefit from specific documentation covering:

  1. When to use each genenv variant:

    • npm run genenv (local)
    • npm run genenv:branch
    • npm run genenv:production
    • npm run genenv:all
  2. Required environment variables:

    • VERCEL_TOKEN (how to obtain it)
    • VERCEL_TEAM_SLUG (defaults to "discourse-graphs")
    • VERCEL_PROJECT_SLUG (defaults to "discourse-graph")
  3. Typical workflow:

    • When developers should use these scripts
    • How it fits into the existing development process

Suggested addition to the README:

### Environment Generation from Vercel

The database package can automatically generate `.env` files by pulling environment variables from Vercel deployments:

- `npm run genenv` - Generate from local Vercel environment
- `npm run genenv:branch` - Generate from current git branch deployment  
- `npm run genenv:production` - Generate from production deployment
- `npm run genenv:all` - Generate all variants

Requires `VERCEL_TOKEN` environment variable. Get your token from [Vercel Settings > Tokens](https://vercel.com/account/tokens).

Would you like me to help you craft more detailed documentation for this feature?


🏁 Script executed:

#!/bin/bash
# Check the main README more thoroughly for environment setup documentation
echo "=== Checking main README for environment setup sections ==="
cat README.md | rg -A 10 -B 2 -i "environment|setup|install|develop"

# Also check if there are any sections about vercel or deployment
echo -e "\n=== Checking for deployment/vercel sections in main README ==="
cat README.md | rg -A 5 -B 2 -i "vercel|deploy|production"

Length of output: 3844


@maparent Thank you for the clarification about Vercel CLI availability - you're absolutely right! The vercel package in devDependencies ensures the CLI is available through node_modules/.bin/vercel.

However, I wasn't able to find specific documentation about the new Vercel environment generation functionality in my search through the codebase. While the existing README has excellent coverage of the database development workflow, I don't see documentation covering:

  • The new genenv scripts (npm run genenv, genenv:branch, genenv:production, etc.)
  • Required environment variables like VERCEL_TOKEN
  • When and how to use the Vercel environment pulling workflow

Could you point me to where the new documentation was added? It's possible I missed it or it might not be committed yet.

🎯 Overall Assessment Update

The implementation itself remains solid and well-architected. Your clarification about CLI availability addresses my main concern about error handling. The code integrates well with existing patterns and provides the flexibility needed for different deployment scenarios.

If documentation is still needed, I'd be happy to help draft something that explains:

  1. The workflow for using the different genenv variants
  2. Required Vercel token setup
  3. How this fits into the existing development process

The feature is ready for testing from a code perspective!


🧠 Learnings used
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-22T01:50:20.212Z
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.

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.

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.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/scripts/lint.ts:6-9
Timestamp: 2025-05-22T23:39:56.973Z
Learning: In the discourse-graph project, scripts should fail gracefully (exit with code 0) when optional tools like sqruff are not found, especially to avoid breaking CI pipelines. Installation instructions for such tools are documented in the README rather than duplicated in error messages.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual `process.env` keys to avoid unnecessary coupling.

@maparent maparent changed the title Construct environment files to access supabase. ENG-625 Construct environment files to access supabase. Jul 22, 2025
@maparent maparent force-pushed the ENG-625-grab-supabase-env-from-vercel branch 6 times, most recently from c4e9320 to 3b72a25 Compare July 25, 2025 02:57
@maparent maparent requested a review from mdroidian July 25, 2025 03:19
@maparent
Copy link
Collaborator Author

@CodeRabbit: When I said this required testing, I meant testing that it worked at all, I did not mean unit tests. The important points are actually more complex integration tests than unit tests. I have now manually tested that the clients are created properly in both website and roam projects, with all three scenarios.
The code has changed substantially since your review, and I think another review may be in order.

Copy link
Contributor

coderabbitai bot commented Jul 25, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@maparent Thank you for the clarification about testing approach and completing the manual integration testing! You're absolutely right that integration testing is more valuable here than unit tests. Let me examine the current state of the code since you mentioned substantial changes.

Based on the current implementation, I'll provide you with an updated comprehensive review of the substantial changes you've made.


🏁 Script executed:

#!/bin/bash
# Check the current state of the create_env.ts file
echo "=== Current create_env.ts implementation ==="
cat packages/database/scripts/create_env.ts

# Check if there are any other changed files
echo -e "\n=== Git status to see current changes ==="
git status --porcelain

# Look for any new documentation that might have been added
echo -e "\n=== Check for documentation updates ==="
rg -i "genenv|vercel.*env" --type=md -A 3 -B 1

# Check the current package.json scripts
echo -e "\n=== Current genenv scripts in package.json ==="
cat packages/database/package.json | jq '.scripts | to_entries | map(select(.key | contains("genenv"))) | from_entries'

# Look for any other related changes
echo -e "\n=== Check for other Vercel-related files ==="
rg -l "vercel" --type=ts --type=js | head -10

Length of output: 6606


@maparent Excellent work on the substantial improvements! The code has indeed changed significantly and is much better now. Here's my updated comprehensive review:

Major Improvements Since Initial Review

Code Quality & Organization:

  • Much cleaner implementation - The code is now more readable and maintainable
  • Better error handling - Proper validation and meaningful error messages
  • Fixed consistency issues - The == vs === issue has been resolved
  • Improved git branch detection - Cleaner logic with proper optional chaining
  • Better file organization - Appropriate file extensions (.env.local, .env.branch, .env.production)

Documentation Added:

  • Comprehensive README section explaining the Vercel workflow
  • Clear setup instructions for VERCEL_TOKEN from 1password
  • Usage examples for different scenarios (genenv:branch, etc.)
  • Integration guidance with existing development workflow

Architecture Improvements:

  • Streamlined function structure - Each environment function is now focused and clean
  • Better parameter handling - Cleaner baseParams setup with proper team/project configuration
  • Improved deployment querying - More robust logic for finding deployments

🎯 Current Implementation Assessment

Strengths:

// Clean branch detection with proper error handling
const branchM = stdout.match(/On branch (.*)/)?.[1];
if (branchM) branch = branchM;
else throw new Error("Could not find the git branch");
// Proper file writing with appropriate extensions
writeFileSync(join(projectRoot, ".env.local"), prefixed + '\nNEXT_API_ROOT="http://localhost:3000/api"\n');
appendFileSync(".env.branch", `NEXT_API_ROOT="${url}/api"\n`);

Excellent Integration Testing Approach:
You're absolutely right that manual integration testing across website and roam projects with all three scenarios is the appropriate testing strategy here. This type of infrastructure code benefits more from end-to-end validation than unit tests.

🔍 Minor Observations

The implementation is now very solid. Only minor suggestions:

  1. Environment Variable Override Documentation - The README could mention the override options:

    • VERCEL_PROJECT_ID/VERCEL_PROJECT_NAME
    • VERCEL_TEAM_ID/VERCEL_TEAM_SLUG
    • SUPABASE_GIT_BRANCH
  2. Error Message Enhancement:

// Could be slightly more descriptive
if (result.deployments.length === 0) {
  console.warn(`No deployment found for branch '${branch}' in project '${projectIdOrName}'`);
  return;
}

🎉 Final Assessment

This is now a high-quality, production-ready implementation that:

  • ✅ Addresses all original requirements from ENG-625
  • ✅ Has comprehensive documentation
  • ✅ Has been thoroughly tested via manual integration testing
  • ✅ Integrates cleanly with existing project patterns
  • ✅ Provides the flexibility needed for different deployment scenarios

The substantial improvements you've made have transformed this into an excellent piece of infrastructure code. The manual integration testing approach you used is exactly what this type of feature needs - validating that the entire workflow works end-to-end across multiple projects.

Ready for merge! 🚀


✏️ Learnings added
Learnt from: maparent
URL: https://github.com/DiscourseGraphs/discourse-graph/pull/301

Timestamp: 2025-07-25T03:22:48.188Z
Learning: In the discourse-graph project, manual integration testing is preferred over unit tests for complex features like Vercel CLI integration, especially when testing client creation across multiple projects (website and roam) with different deployment scenarios.

Learnt from: maparent
URL: https://github.com/DiscourseGraphs/discourse-graph/pull/301

Timestamp: 2025-07-25T03:22:48.188Z
Learning: In the discourse-graph project, manual integration testing is preferred over unit tests for complex features like Vercel CLI integration, especially when testing client creation across multiple projects (website and roam) with different deployment scenarios.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
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.

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.

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.

@maparent
Copy link
Collaborator Author

@mdroidian just saw the deploy failure. Will fix that now.

@maparent maparent removed the request for review from mdroidian July 25, 2025 03:58
@maparent maparent marked this pull request as draft July 25, 2025 03:58
@maparent
Copy link
Collaborator Author

Ok, the deploy step requires more thought. It goes to tomorrow.

@maparent maparent force-pushed the ENG-625-grab-supabase-env-from-vercel branch 3 times, most recently from 6ffcd5b to 91dafb6 Compare July 25, 2025 13:04
@maparent maparent marked this pull request as ready for review July 25, 2025 13:05
@maparent maparent requested a review from mdroidian July 25, 2025 13:05
@maparent
Copy link
Collaborator Author

deploy step working. Ready for review.

@mdroidian
Copy link
Contributor

The base one is for running against the local supabase.

@maparent Could you elaborate on this? What is "The base one" referring to?

@maparent maparent force-pushed the ENG-625-grab-supabase-env-from-vercel branch from 91dafb6 to 7cbf07f Compare July 26, 2025 04:03
@DiscourseGraphs DiscourseGraphs deleted a comment from coderabbitai bot Jul 26, 2025
@mdroidian
Copy link
Contributor

@CodeRabbit full review

Copy link
Contributor

coderabbitai bot commented Jul 26, 2025

✅ Actions performed

Full review triggered.

Copy link
Contributor

coderabbitai bot commented Jul 26, 2025

📝 Walkthrough

Walkthrough

This change introduces a unified environment variable management system across multiple packages by centralizing environment configuration logic in a new dbdotenv module within @repo/database. Several scripts and utilities are updated to use this module for accessing Supabase and API credentials, and new scripts are added to automate the generation and management of environment files for different deployment variants. Documentation is expanded to clarify workflows.

Changes

Files/Paths Change Summary
apps/roam/package.json Added @repo/database as a development dependency.
apps/roam/scripts/compile.ts Replaced direct process.env usage with envContents() from @repo/database/dbdotenv for environment variable access.
apps/website/app/utils/supabase/client.ts,
apps/website/app/utils/supabase/middleware.ts,
apps/website/app/utils/supabase/server.ts
Updated to use envContents() from @repo/database/dbdotenv for Supabase credentials instead of direct process.env access.
packages/database/README.md Extensively revised and expanded documentation for local dev, testing, and deployment environment workflows.
packages/database/create_env.ts New script: automates environment variable setup for different deployment variants.
packages/database/dbdotenv.ts New module: provides exported functions for environment variant detection and environment variable loading from variant-specific .env files.
packages/database/features/step-definitions/stepdefs.ts Added protection against running tests in production; initializes environment config using dbdotenv.
packages/database/package.json Added export for dbdotenv, new scripts for environment generation, updated build/dev scripts, and new devDependencies.
packages/database/scripts/create_env.ts New script: generates environment files for local, branch, and production variants using Supabase/Vercel CLI and SDK.
packages/ui/package.json Added "type": "module" to designate ES module format.
packages/ui/src/lib/supabase/client.ts Updated to use envContents() for Supabase credentials.
turbo.json Expanded globalEnv and globalPassThroughEnv with additional environment variables.

Sequence Diagram(s)

sequenceDiagram
    participant Script/Server/Client
    participant dbdotenv
    participant .env File(s)
    participant process.env

    Script/Server/Client->>dbdotenv: envContents()
    dbdotenv->>Script/Server/Client: {SUPABASE_URL, SUPABASE_ANON_KEY, ...}

    alt Variant-specific .env file exists
        dbdotenv->>.env File(s): Read and parse
        .env File(s)-->>dbdotenv: Env variables
    else
        dbdotenv->>process.env: Fallback to process.env
        process.env-->>dbdotenv: Env variables
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–25 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


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.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai 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:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @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

Documentation and Community

  • 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: 4

🧹 Nitpick comments (3)
packages/database/dbdotenv.ts (1)

30-39: Consider making fallback behavior more explicit.

The fallback to process.env when no environment file exists is logical, but the hardcoded keys (SUPABASE_URL, SUPABASE_ANON_KEY) create an implicit dependency on these specific environment variables.

Consider documenting this fallback behavior or making the fallback keys configurable:

export const envContents = () => {
  const path = envFilePath();
  if (!path)
+    // Fallback to process.env when running in production environments
    return {
      SUPABASE_URL: process.env.SUPABASE_URL,
      SUPABASE_ANON_KEY: process.env.SUPABASE_ANON_KEY,
    };
  const data = fs.readFileSync(path, "utf8");
  return dotenv.parse(data);
};
packages/database/README.md (2)

31-31: Fix spelling error in documentation.

There's a typo in the build process description.

-      1. Start supbase
+      1. Start supabase

44-44: Fix indentation inconsistency.

The markdown indentation is inconsistent for this list item.

-    10. When your migration is pushed in a branch, supabase will create a branch instance. Note there is a small cost to this, so we do not want those branches to linger.
+   10. When your migration is pushed in a branch, supabase will create a branch instance. Note there is a small cost to this, so we do not want those branches to linger.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd9d14b and 7cbf07f.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (14)
  • apps/roam/package.json (1 hunks)
  • apps/roam/scripts/compile.ts (3 hunks)
  • apps/website/app/utils/supabase/client.ts (1 hunks)
  • apps/website/app/utils/supabase/middleware.ts (1 hunks)
  • apps/website/app/utils/supabase/server.ts (1 hunks)
  • packages/database/README.md (2 hunks)
  • packages/database/create_env.ts (1 hunks)
  • packages/database/dbdotenv.ts (1 hunks)
  • packages/database/features/step-definitions/stepdefs.ts (2 hunks)
  • packages/database/package.json (2 hunks)
  • packages/database/scripts/create_env.ts (1 hunks)
  • packages/ui/package.json (1 hunks)
  • packages/ui/src/lib/supabase/client.ts (2 hunks)
  • turbo.json (1 hunks)
🧰 Additional context used
🧠 Learnings (15)
📓 Common learnings
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.
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.
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.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.
apps/roam/package.json (11)

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/package.json : Prefer existing dependencies from package.json when adding or using dependencies in the Roam Research extension

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/**/*.{js,jsx,ts,tsx} : Use Roam Depot/Extension API documentation from https://roamresearch.com/#/app/developer-documentation/page/y31lhjIqU when working with the Roam Extension API

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/**/*.{js,jsx,ts,tsx} : Use the roamAlphaApi documentation from https://roamresearch.com/#/app/developer-documentation/page/tIaOPdXCj when working with the Roam API

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/obsidian.mdc:0-0
Timestamp: 2025-07-19T22:34:16.794Z
Learning: Applies to apps/obsidian/package.json : Prefer existing dependencies from package.json when adding or using dependencies in the Obsidian plugin

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/website.mdc:0-0
Timestamp: 2025-07-19T22:34:26.600Z
Learning: Applies to apps/website/** : Prefer existing dependencies from package.json when adding or using dependencies in the website project

Learnt from: maparent
PR: #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.

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/**/*.{js,jsx,ts,tsx} : Use BlueprintJS 3 components and Tailwind CSS for platform-native UI in the Roam Research extension

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #220
File: apps/roam/src/utils/conceptConversion.ts:11-40
Timestamp: 2025-06-23T11:49:45.457Z
Learning: In the DiscourseGraphs/discourse-graph codebase, direct access to window.roamAlphaAPI is the established pattern throughout the codebase. The team prefers to maintain this pattern consistently rather than making piecemeal changes, and plans to address dependency injection as a global refactor when scheduled.

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to apps/website/**/*.{tsx,jsx,ts,js} : Use Tailwind CSS for styling where possible

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to {apps/website,packages/ui}/**/*.{tsx,jsx} : When refactoring inline styles, use tailwind classes

packages/ui/package.json (2)

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/obsidian.mdc:0-0
Timestamp: 2025-07-19T22:34:16.794Z
Learning: Applies to apps/obsidian/package.json : Prefer existing dependencies from package.json when adding or using dependencies in the Obsidian plugin

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to {apps/website,packages/ui}/**/*.{tsx,jsx} : Use platform-native UI components first with shadcn/ui as a fallback

packages/ui/src/lib/supabase/client.ts (4)

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.

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual process.env keys to avoid unnecessary coupling.

Learnt from: maparent
PR: #272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.

apps/website/app/utils/supabase/server.ts (7)

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.

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual process.env keys to avoid unnecessary coupling.

Learnt from: maparent
PR: #272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #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.

turbo.json (3)

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.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual process.env keys to avoid unnecessary coupling.

Learnt from: maparent
PR: #165
File: packages/database/supabase/config.toml:0-0
Timestamp: 2025-05-20T15:51:22.084Z
Learning: Wildcard patterns in additional_redirect_urls within Supabase configuration are acceptable in this codebase when needed for Vercel branch deployments, despite the small security risk they introduce.

apps/website/app/utils/supabase/client.ts (4)

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.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Learnt from: maparent
PR: #272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

apps/roam/scripts/compile.ts (8)

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.

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/**/*.{js,jsx,ts,tsx} : Use Roam Depot/Extension API documentation from https://roamresearch.com/#/app/developer-documentation/page/y31lhjIqU when working with the Roam Extension API

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual process.env keys to avoid unnecessary coupling.

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/**/*.{js,jsx,ts,tsx} : Use the roamAlphaApi documentation from https://roamresearch.com/#/app/developer-documentation/page/tIaOPdXCj when working with the Roam API

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/roam.mdc:0-0
Timestamp: 2025-07-19T22:34:23.619Z
Learning: Applies to apps/roam/package.json : Prefer existing dependencies from package.json when adding or using dependencies in the Roam Research extension

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #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.

apps/website/app/utils/supabase/middleware.ts (3)

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.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Learnt from: maparent
PR: #272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.

packages/database/scripts/create_env.ts (8)

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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-25T03:22:48.188Z
Learning: In the discourse-graph project, manual integration testing is preferred over unit tests for complex features like Vercel CLI integration, especially when testing client creation across multiple projects (website and roam) with different deployment scenarios.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-25T03:22:48.188Z
Learning: In the discourse-graph project, manual integration testing is preferred over unit tests for complex features like Vercel CLI integration, especially when testing client creation across multiple projects (website and roam) with different deployment scenarios.

packages/database/features/step-definitions/stepdefs.ts (8)

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.

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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Maintain consistent naming conventions: UPPERCASE for constants

Learnt from: maparent
PR: #272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.

packages/database/create_env.ts (6)

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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Learnt from: maparent
PR: #165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

packages/database/dbdotenv.ts (3)

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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #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.

packages/database/README.md (15)

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.

Learnt from: maparent
PR: #165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.

Learnt from: maparent
PR: #165
File: packages/database/supabase/migrations/20250513173724_content_concept_key.sql:37-60
Timestamp: 2025-05-22T23:50:23.771Z
Learning: For the discourse-graph project, database schema management focuses on the final state in the supabase/schemas directory, not on the individual migration files. When reviewing database changes, consider only the schema definitions in this directory, not potential duplications or conflicts across migration files.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #189
File: packages/database/types.gen.ts:336-371
Timestamp: 2025-06-04T11:54:37.239Z
Learning: The team prefers not to manually edit generated files (like Supabase TypeScript types) even when they contain inaccuracies, as manual changes would be overwritten during regeneration. They treat generated files as read-only artifacts.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.

Learnt from: maparent
PR: #165
File: packages/database/supabase/migrations/20250504195841_remote_schema.sql:1-7
Timestamp: 2025-05-20T03:01:11.220Z
Learning: Supabase automatically creates necessary schemas like the "extensions" schema before migrations run, so there's no need to explicitly create these schemas in migration files.

Learnt from: maparent
PR: #165
File: packages/database/supabase/migrations/20250504202930_content_tables.sql:37-45
Timestamp: 2025-05-20T03:11:07.917Z
Learning: When reviewing SQL migrations in this codebase, understand that historical migration files should not be modified once they're applied. Instead, issues should be fixed in subsequent migrations or schema definition files. This is why maparent indicated "migration, not changing. corrected in schema."

Learnt from: maparent
PR: #165
File: packages/database/supabase/schemas/extensions.sql:1-11
Timestamp: 2025-05-20T03:02:36.027Z
Learning: The necessary schemas for Supabase extensions (like 'extensions', 'graphql', and 'vault') are automatically created by Supabase before extensions are installed, so they don't need to be explicitly created in SQL migration files.

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.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-25T03:22:48.188Z
Learning: In the discourse-graph project, manual integration testing is preferred over unit tests for complex features like Vercel CLI integration, especially when testing client creation across multiple projects (website and roam) with different deployment scenarios.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-25T03:22:48.188Z
Learning: In the discourse-graph project, manual integration testing is preferred over unit tests for complex features like Vercel CLI integration, especially when testing client creation across multiple projects (website and roam) with different deployment scenarios.

Learnt from: maparent
PR: #272
File: packages/ui/src/lib/supabase/contextFunctions.ts:50-111
Timestamp: 2025-07-08T14:48:38.048Z
Learning: The Supabase client does not offer transaction support, so idempotent upserts with proper conflict resolution (using onConflict with ignoreDuplicates: false) are the preferred approach for multi-step database operations in packages/ui/src/lib/supabase/contextFunctions.ts. This pattern prevents orphaned records when retrying operations.

packages/database/package.json (12)

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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #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.

Learnt from: maparent
PR: #198
File: packages/database/supabase/migrations/20250605083319_alpha_upload.sql:157-337
Timestamp: 2025-06-09T16:57:14.681Z
Learning: Migration files in packages/database/supabase/migrations/ are historical snapshots that preserve database schema and functions as they existed at the time of creation. These files should not be updated to reflect current schema changes, even if they reference tables or columns that have since been modified or removed. Schema incompatibilities in migration files are expected and acceptable as they represent the valid state at the time of migration.

Learnt from: maparent
PR: #165
File: packages/database/supabase/migrations/20250512142307_sync_table.sql:20-21
Timestamp: 2025-05-20T03:04:21.602Z
Learning: Database migration files (like the SQL files in packages/database/supabase/migrations/) should not be modified after they're created, even to fix minor issues like unused variables. Issues should be addressed in newer schema files instead to maintain migration history integrity.

Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-13T16:47:14.352Z
Learning: In the discourse-graph codebase, types.gen.ts contains automatically generated database function type definitions that may have reordered signatures between versions. This reordering is expected behavior from the code generation process and should not be flagged as an issue requiring fixes.

Learnt from: maparent
PR: #182
File: apps/website/app/utils/supabase/dbUtils.ts:22-28
Timestamp: 2025-05-30T14:49:24.016Z
Learning: In apps/website/app/utils/supabase/dbUtils.ts, expanding the KNOWN_EMBEDDINGS and DEFAULT_DIMENSIONS mappings to support additional embedding models requires corresponding database model changes (creating new embedding tables), which should be scoped as separate work from API route implementations.

Learnt from: maparent
PR: #291
File: packages/database/supabase/functions/create-space/index.ts:0-0
Timestamp: 2025-07-21T14:22:20.752Z
Learning: In the discourse-graph codebase, types.gen.ts is not accessible from Supabase edge functions, requiring duplication of types and utilities when needed in the edge function environment at packages/database/supabase/functions/.

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/obsidian.mdc:0-0
Timestamp: 2025-07-19T22:34:16.794Z
Learning: Applies to apps/obsidian/package.json : Prefer existing dependencies from package.json when adding or using dependencies in the Obsidian plugin

Learnt from: maparent
PR: #189
File: packages/database/types.gen.ts:336-371
Timestamp: 2025-06-04T11:54:37.239Z
Learning: The team prefers not to manually edit generated files (like Supabase TypeScript types) even when they contain inaccuracies, as manual changes would be overwritten during regeneration. They treat generated files as read-only artifacts.

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Maintain consistent naming conventions: UPPERCASE for constants

Learnt from: CR
PR: DiscourseGraphs/discourse-graph#0
File: .cursor/rules/main.mdc:0-0
Timestamp: 2025-07-19T22:34:08.725Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Prettier with the project's configuration

🧬 Code Graph Analysis (6)
packages/ui/src/lib/supabase/client.ts (1)
packages/database/dbdotenv.ts (1)
  • envContents (30-39)
apps/website/app/utils/supabase/server.ts (3)
apps/website/app/utils/supabase/client.ts (1)
  • createClient (7-16)
packages/ui/src/lib/supabase/client.ts (1)
  • createClient (16-26)
packages/database/dbdotenv.ts (1)
  • envContents (30-39)
apps/website/app/utils/supabase/client.ts (1)
packages/database/dbdotenv.ts (1)
  • envContents (30-39)
apps/roam/scripts/compile.ts (1)
packages/database/dbdotenv.ts (1)
  • envContents (30-39)
apps/website/app/utils/supabase/middleware.ts (1)
packages/database/dbdotenv.ts (1)
  • envContents (30-39)
packages/database/features/step-definitions/stepdefs.ts (1)
packages/database/dbdotenv.ts (2)
  • getVariant (8-22)
  • config (43-48)
🪛 Biome (2.1.2)
packages/ui/package.json

[error] 6-6: The key type was already declared.

This where a duplicated key was declared again.

If a key is defined multiple times, only the last definition takes effect. Previous definitions are ignored.

(lint/suspicious/noDuplicateObjectKeys)

🪛 LanguageTool
packages/database/README.md

[grammar] ~31-~31: Ensure spelling is correct
Context: ...h will do the following: 1. Start supbase 2. Apply the new migration locally 3....

(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)


[style] ~41-~41: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...r in the studio, or psql. 3. If that fails, you can reset your local da...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🪛 markdownlint-cli2 (0.17.2)
packages/database/README.md

44-44: Inconsistent indentation for list items at the same level
Expected: 3; Actual: 4

(MD005, list-indent)

🔇 Additional comments (34)
apps/roam/package.json (1)

16-16: LGTM! Dependency addition supports centralized environment management.

This addition enables the roam app to import the new envContents() function from @repo/database/dbdotenv, supporting the centralized environment variable management system introduced in this PR.

packages/ui/src/lib/supabase/client.ts (2)

6-6: LGTM! Centralized environment variable access implemented.

The import of envContents from @repo/database/dbdotenv enables the centralized environment management system.


17-19: LGTM! Environment variable access correctly refactored.

The refactoring from direct process.env access to using envContents() is implemented correctly. The function provides fallback to process.env when no environment file is found, ensuring backwards compatibility while enabling the new environment variant system.

apps/website/app/utils/supabase/middleware.ts (2)

3-3: LGTM! Centralized environment variable access implemented.

The import enables the new centralized environment management system via envContents().


8-10: LGTM! Environment variable access correctly refactored.

The refactoring from direct process.env access to envContents() follows the same reliable pattern used across other files. The dbEnv variable naming provides good clarity about the source of these environment variables.

apps/website/app/utils/supabase/client.ts (2)

3-3: LGTM! Centralized environment variable access implemented.

The import of envContents aligns with the centralized environment management system being introduced across the codebase.


8-10: LGTM! Environment variable access correctly refactored.

The refactoring consistently implements the new environment variable access pattern. The envContents() function provides the same environment variables with additional support for environment variants while maintaining backwards compatibility.

apps/roam/scripts/compile.ts (2)

5-5: LGTM: Clean integration with centralized environment management.

The import of envContents from the new @repo/database/dbdotenv module aligns well with the broader effort to centralize environment variable access across the codebase.


126-137: Fallback logic verified

The envContents() function in packages/database/dbdotenv.ts correctly falls back to process.env.SUPABASE_URL and process.env.SUPABASE_ANON_KEY when no env file is found (lines 30–36). In apps/roam/scripts/compile.ts, NEXT_API_ROOT is safely defaulted to an empty string via dbEnv.NEXT_API_ROOT || "". No changes required.

apps/website/app/utils/supabase/server.ts (2)

3-4: LGTM: Correct import path and environment centralization.

Good fix removing the .ts extension from the import path, and the integration with the centralized environment management system is clean and consistent.


9-12: Environment variable access properly centralized.

The refactoring to use envContents() maintains the existing error handling logic while providing consistent environment variable sourcing across the codebase. The fallback behavior in envContents() ensures backward compatibility.

packages/database/features/step-definitions/stepdefs.ts (2)

4-5: LGTM: Correct imports and environment integration.

Good fix removing the .ts extension from the import path, and the addition of getVariant and config imports properly integrates with the new environment management system.


16-20: Excellent production safety guard.

This is a critical safety measure that prevents destructive tests from running against the production database. The early exit with a clear error message and the subsequent config() call for environment initialization are both well-implemented.

turbo.json (2)

15-23: LGTM: Environment variables properly configured for new functionality.

The addition of Supabase and Vercel environment variables to globalEnv correctly supports the new environment management system. The variables like SUPABASE_USE_DB and SUPABASE_GIT_BRANCH enable the variant-based environment selection introduced in the PR.


30-30: Proper handling of sensitive environment variables.

The addition of GITHUB_ACTIONS, SUPABASE_ACCESS_TOKEN, and VERCEL_TOKEN to globalPassThroughEnv is correct - these sensitive tokens should be passed through rather than cached in the global environment.

Also applies to: 35-35, 39-39

packages/database/create_env.ts (4)

10-10: LGTM: Appropriate early exit for Vercel environment.

Good check to prevent the script from running in Vercel's build environment where it's not needed.


14-19: Proper token validation with clear error message.

The VERCEL_TOKEN requirement check is appropriate and provides a clear error message for developers.


21-29: Good variant validation with comprehensive options.

The validation correctly handles both command-line arguments and environment variable sources, with proper error handling for invalid variants.


66-67: Missing NEXT_API_ROOT configuration for branch and production variants.

The local variant sets NEXT_API_ROOT="http://localhost:3000" but the branch and production variants don't set this variable, which could cause issues when the environment is loaded.

Consider adding appropriate API root URLs for each variant:

     execSync(
       `vercel -t ${vercelToken} env pull --environment preview --git-branch ${safeBranch} .env.branch`,
       { encoding: "utf8" },
     );
+    // Append branch-specific API root
+    const branchContent = readFileSync(join(projectRoot, ".env.branch"), "utf8");
+    writeFileSync(
+      join(projectRoot, ".env.branch"),
+      branchContent + `\nNEXT_API_ROOT="https://${branch}-discourse-graphs.vercel.app"\n`
+    );
   } catch (err) {
   execSync(
     `vercel -t ${vercelToken} env pull --environment production .env.production`,
   );
+  // Append production API root
+  const prodContent = readFileSync(join(projectRoot, ".env.production"), "utf8");
+  writeFileSync(
+    join(projectRoot, ".env.production"),
+    prodContent + '\nNEXT_API_ROOT="https://discourse-graphs.vercel.app"\n'
+  );
 }

Also applies to: 75-77

⛔ Skipped due to learnings
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.
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.
Learnt from: maparent
PR: DiscourseGraphs/discourse-graph#0
File: :0-0
Timestamp: 2025-07-08T14:51:55.299Z
Learning: DiscourseGraphs maintainers prefer not to add narrowly typed definitions for individual `process.env` keys to avoid unnecessary coupling.
packages/database/dbdotenv.ts (2)

8-22: Environment detection and variant validation logic looks solid.

The function correctly prioritizes production environment detection over user configuration, which prevents accidental local environment usage in CI/CD. The validation against allowed variants with meaningful error messages is well implemented.


41-48: Singleton pattern implementation is appropriate.

The one-time configuration pattern with CONFIG_DONE flag prevents multiple dotenv configurations, which is the correct approach for this use case.

packages/database/package.json (4)

9-10: New export enables clean cross-package imports.

The addition of the "./dbdotenv" export allows other packages to import environment utilities using @repo/database/dbdotenv, which is cleaner than relative imports.


14-14: Dev script integration looks good.

Running tsx scripts/create_env.ts during development startup ensures environment files are generated before functions serve, which is the correct workflow.


21-25: Environment generation scripts are well-organized.

The script naming convention is clear and covers all necessary variants. The genenv:all script provides a convenient way to generate all environment files at once.


34-39: Dependency additions support the new functionality.

The @vercel/sdk and vercel packages are necessary for the environment generation scripts, and the tsx update ensures compatibility.

packages/database/scripts/create_env.ts (6)

11-11: Early exit for production environments is correct.

The check for Vercel's environment (HOME === "/vercel") prevents the script from running in production deployments, which is the intended behavior.


15-23: Variant validation and argument parsing looks solid.

The logic correctly prioritizes command line arguments over environment variables, with proper validation against allowed variants.


34-48: Vercel client setup with proper token validation.

The token validation ensures the script fails fast when credentials are missing for non-local variants. The team configuration with fallback values is well-structured.


50-67: Local environment generation is straightforward and correct.

The use of supabase status -o env to get local environment variables, combined with the prefix transformation logic, is the right approach for generating local environment files.


69-100: Branch environment generation with robust git integration.

The git branch detection with override capability and Vercel deployment querying is well-implemented. The warning for missing deployments is helpful for debugging.


121-134: Error handling approach is appropriate.

The try-catch block with logging and re-throwing ensures errors are visible while still failing the script execution, which is the correct behavior for build/dev scripts.

packages/database/README.md (3)

3-47: Comprehensive workflow documentation with clear scenario separation.

The restructured documentation effectively separates different usage scenarios and provides detailed step-by-step instructions. The local development workflow is particularly well-documented with proper handling of schema changes and migration management.


57-66: Branch database usage documentation is clear and helpful.

The instructions for using local code against the Supabase branch database are well-structured, with appropriate security considerations and clear environment variable setup instructions.


67-72: Production database usage includes appropriate security warnings.

The documentation correctly emphasizes the security risks of using local code against production databases and provides clear guidance on when this might be appropriate.

@@ -0,0 +1,78 @@
import { execSync } from "node:child_process";
Copy link
Contributor

Choose a reason for hiding this comment

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

filename (create_env) should be camelCase

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is still create_env

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, who/what is using this file?

@mdroidian
Copy link
Contributor

Good general direction. Great work! 👍

@maparent maparent requested a review from mdroidian July 27, 2025 20:37
@maparent maparent force-pushed the ENG-625-grab-supabase-env-from-vercel branch from 148375a to dc7964b Compare July 27, 2025 23:36
@maparent
Copy link
Collaborator Author

rebased on main, no other change.

@maparent
Copy link
Collaborator Author

Curious: I resolved all conversations (afaik) and GitHub still says I'm in "changes requested" state. Is there something else I'm expected to do?

@mdroidian
Copy link
Contributor

Curious: I resolved all conversations (afaik) and GitHub still says I'm in "changes requested" state. Is there something else I'm expected to do?

It needs another review. I should be able to get it today or tomorrow.

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.

Couple changes we probably should do, but can merge after.

parserOptions: {
project: true,
tsconfigRootDir: ".",
project: "./tsconfig.json",
Copy link
Contributor

@mdroidian mdroidian Aug 1, 2025

Choose a reason for hiding this comment

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

rm project: ./tsconfig.json, to allow project: true to work

makeLocalEnv();
}
if (variant === "branch" || variant === "all") {
await makeBranchEnv(vercel);
Copy link
Contributor

Choose a reason for hiding this comment

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

image

You could probably put const vercel = new Vercel({ bearerToken: vercelToken }); right above this if
I don't think we need vercel until this line, so we can remove the preview let and assignment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unless in the case of "all", where we need it before. This is actually a typescript error; it should know that vercel is non-null if variant is not local. And indeed tsx does not protest. I could add a "!" to tell typescript about this, I did in an earlier version, but for some reason the warning does not show in some cases.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

actually made a change.

@@ -0,0 +1,78 @@
import { execSync } from "node:child_process";
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is still create_env

@@ -0,0 +1,78 @@
import { execSync } from "node:child_process";
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, who/what is using this file?

The base one is for running against the local supabase.
It is possible to talk directly against either a supabase branch or the production database.
Use cases for either should be extremely rare, and are documented separately.
For this, set SUPABASE_USE_DB to 'branch' or 'production' respectively.
The branch used will be the current branch, unless overridden by SUPABASE_GIT_BRANCH.
@maparent
Copy link
Collaborator Author

maparent commented Aug 2, 2025

create_env.ts: That earlier version was checked in by mistake. Removed.

@maparent maparent force-pushed the ENG-625-grab-supabase-env-from-vercel branch from dc7964b to 56a4f5e Compare August 2, 2025 16:07
@maparent maparent merged commit 3a24c90 into main Aug 2, 2025
4 of 5 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Aug 2, 2025
@maparent maparent deleted the ENG-625-grab-supabase-env-from-vercel branch August 2, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants