{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "drizzle-postgres",
  "type": "registry:block",
  "title": "Drizzle Postgres",
  "description": "Postgres + Drizzle package, schema barrel, migrations, and server-only DB access.",
  "dependencies": [
    "drizzle-orm",
    "postgres"
  ],
  "devDependencies": [
    "drizzle-kit",
    "dotenv"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "packages/db/package.json",
      "type": "registry:file",
      "target": "packages/db/package.json",
      "content": "{\n  \"name\": \"@workspace/db\",\n  \"private\": true,\n  \"type\": \"module\",\n  \"exports\": {\n    \".\": \"./src/index.ts\",\n    \"./schema\": \"./src/schema/index.ts\"\n  }\n}\n"
    },
    {
      "path": "packages/db/src/client.ts",
      "type": "registry:file",
      "target": "packages/db/src/client.ts",
      "content": "import { drizzle } from \"drizzle-orm/postgres-js\";\nimport postgres from \"postgres\";\nimport * as schema from \"./schema\";\n\nexport function createDb(connectionString: string) {\n  const client = postgres(connectionString, { max: 1 });\n  return drizzle(client, { schema });\n}\n"
    },
    {
      "path": "packages/db/src/index.ts",
      "type": "registry:file",
      "target": "packages/db/src/index.ts",
      "content": "export { createDb } from \"./client\";\nexport * from \"./schema\";\n"
    },
    {
      "path": "packages/db/src/schema/index.ts",
      "type": "registry:file",
      "target": "packages/db/src/schema/index.ts",
      "content": "/**\n * Export every table from this barrel so Drizzle Kit and createDb share one schema graph.\n */\n"
    },
    {
      "path": "apps/web/src/lib/db.ts",
      "type": "registry:file",
      "target": "apps/web/src/lib/db.ts",
      "content": "import \"server-only\";\n\nimport { createDb } from \"@workspace/db\";\n\nconst globalForDb = globalThis as typeof globalThis & {\n  __stackfoundryDb?: ReturnType<typeof createDb>;\n};\n\nfunction getConnectionString() {\n  const url = process.env.DATABASE_URL;\n  if (!url) {\n    throw new Error(\"DATABASE_URL is not set.\");\n  }\n  return url;\n}\n\nexport function getDb() {\n  if (!globalForDb.__stackfoundryDb) {\n    globalForDb.__stackfoundryDb = createDb(getConnectionString());\n  }\n  return globalForDb.__stackfoundryDb;\n}\n"
    },
    {
      "path": "drizzle.config.ts",
      "type": "registry:file",
      "target": "drizzle.config.ts",
      "content": "import { config } from \"dotenv\";\nimport { defineConfig } from \"drizzle-kit\";\n\nconfig({ path: \".env\" });\nconfig({ path: \".env.local\", override: true });\n\nexport default defineConfig({\n  schema: \"./packages/db/src/schema/index.ts\",\n  out: \"./packages/db/drizzle\",\n  dialect: \"postgresql\",\n  dbCredentials: {\n    url: process.env.DATABASE_URL ?? \"\",\n  },\n});\n"
    }
  ],
  "maintenanceSkills": [
    {
      "name": "drizzle-postgres",
      "target": ".stackfoundry/skills/drizzle-postgres/SKILL.md",
      "content": "---\nname: drizzle-postgres\ndescription: Maintain the Drizzle Postgres module installed by StackFoundry.\n---\n\n# Drizzle Postgres Operating Instructions\n\n- Keep DB access server-only.\n- Add tables under the schema directory and export them from the schema barrel.\n- Generate and commit migration SQL when schema changes are intended.\n- Do not import DB helpers from Client Components.\n- Include tenant/user/org scope in cached query tags when data is user-specific.\n\n## Shared Skills\n\nWhen provider, framework, or database behavior changes, load the installed shared skill before editing implementation details:\n\n- `.stackfoundry/skills/drizzle/SKILL.md` (source: `registry/skills/drizzle/SKILL.md`)\n- `.stackfoundry/skills/nextjs/SKILL.md` (source: `registry/skills/nextjs/SKILL.md`)\n\nKeep this module skill focused on ownership, installed files, env vars, deployment checks, and module-specific invariants.\n\n"
    },
    {
      "name": "drizzle",
      "target": ".stackfoundry/skills/drizzle/SKILL.md",
      "content": "---\nname: drizzle\ndescription: Maintain Drizzle ORM and Postgres code installed by StackFoundry modules.\n---\n\n# Drizzle Operating Instructions\n\n## Installed Location\n\n- Installed target: `.stackfoundry/skills/drizzle/SKILL.md`\n- Registry source: `registry/skills/drizzle/SKILL.md`\n\nAgents maintaining an installed module should load this shared skill from the installed target when provider, framework, database, SDK, or platform behavior is involved. Keep provider-specific API details here instead of duplicating them inside module maintenance skills.\n\n- Keep database access in server-only code.\n- Add schema changes under `packages/db/src/schema` and export shared tables from the schema barrel.\n- Generate and commit migrations when schema changes are intended.\n- Use typed query helpers instead of raw SQL unless the query needs a documented escape hatch.\n- Include tenant, organization, or user scope in queries and cache tags whenever data is not global.\n"
    },
    {
      "name": "nextjs",
      "target": ".stackfoundry/skills/nextjs/SKILL.md",
      "content": "---\nname: nextjs\ndescription: Maintain Next.js App Router code installed by StackFoundry modules.\n---\n\n# Next.js Operating Instructions\n\n## Installed Location\n\n- Installed target: `.stackfoundry/skills/nextjs/SKILL.md`\n- Registry source: `registry/skills/nextjs/SKILL.md`\n\nAgents maintaining an installed module should load this shared skill from the installed target when provider, framework, database, SDK, or platform behavior is involved. Keep provider-specific API details here instead of duplicating them inside module maintenance skills.\n\n- Keep server-only data access out of Client Components.\n- Put route handlers under `app/api` and UI routes under the relevant App Router segment.\n- Prefer Server Components for data loading and add `\"use client\"` only for interactivity.\n- Keep public environment variables prefixed with `NEXT_PUBLIC_`; keep secrets server-only.\n- Re-run typecheck and build after changing route handlers, layouts, or shared app configuration.\n"
    }
  ],
  "envVars": {
    "DATABASE_URL": ""
  },
  "docs": "# Drizzle Postgres Module\n\nInstalls a Postgres + Drizzle data layer with migrations and server-only app access.\n\n## Owns\n\n- `packages/db`\n- root `drizzle.config.ts`\n- app-level `lib/db.ts`\n- `DATABASE_URL` env documentation\n\n## Verification\n\n- Generate migrations.\n- Run migrations or push in a local database.\n- Confirm app server code can import `getDb()`.\n- Confirm no client component imports DB code.\n",
  "meta": {
    "category": "database",
    "env": [
      "DATABASE_URL"
    ],
    "status": "ready",
    "maturity": "ready",
    "drizzle": {
      "schemaExports": [],
      "migrationRecommended": true
    },
    "recommendedFor": []
  }
}
