Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DB_PREFIX environment variable #1171

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# The database URL is used to connect to your Supabase database.
POSTGRES_URL="postgres://postgres.[USERNAME]:[PASSWORD]@aws-0-eu-central-1.pooler.supabase.com:6543/postgres?workaround=supabase-pooler.vercel"

# DB_PREFIX is used to prefix the database tables, e.g. "t3" will create tables like "t3_user"
DB_PREFIX="t3"


# You can generate the secret via 'openssl rand -base64 32' on Unix
# @see https://next-auth.js.org/configuration/options#secret
Expand Down
10 changes: 9 additions & 1 deletion packages/db/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { relations, sql } from "drizzle-orm";
import { pgTable, primaryKey } from "drizzle-orm/pg-core";
import {
integer,

Check failure on line 3 in packages/db/src/schema.ts

View workflow job for this annotation

GitHub Actions / lint

'integer' is defined but never used. Allowed unused vars must match /^_/u
primaryKey,
text,

Check failure on line 5 in packages/db/src/schema.ts

View workflow job for this annotation

GitHub Actions / lint

'text' is defined but never used. Allowed unused vars must match /^_/u
timestamp,

Check failure on line 6 in packages/db/src/schema.ts

View workflow job for this annotation

GitHub Actions / lint

'timestamp' is defined but never used. Allowed unused vars must match /^_/u
uuid,

Check failure on line 7 in packages/db/src/schema.ts

View workflow job for this annotation

GitHub Actions / lint

'uuid' is defined but never used. Allowed unused vars must match /^_/u
varchar,

Check failure on line 8 in packages/db/src/schema.ts

View workflow job for this annotation

GitHub Actions / lint

'varchar' is defined but never used. Allowed unused vars must match /^_/u
} from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";
import { pgTable } from "./table";

export const Post = pgTable("post", (t) => ({
id: t.uuid().notNull().primaryKey().defaultRandom(),
Expand Down
8 changes: 8 additions & 0 deletions packages/db/src/table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { pgTableCreator } from "drizzle-orm/pg-core";

export const pgTable = pgTableCreator((name: string) => {
if (process.env.DB_PREFIX) {

Check failure on line 4 in packages/db/src/table.ts

View workflow job for this annotation

GitHub Actions / lint

DB_PREFIX is not listed as a dependency in root turbo.json
return `${process.env.DB_PREFIX}_${name}`;

Check failure on line 5 in packages/db/src/table.ts

View workflow job for this annotation

GitHub Actions / lint

DB_PREFIX is not listed as a dependency in root turbo.json
}
return name;
});
Loading