Skip to content

Commit

Permalink
feat: deploy new neon db to edge #561
Browse files Browse the repository at this point in the history
- added dreon and preon environment variables
- migrated schema to db package
- replaced planetscale with neon serverless and pg
- migrated drizzle schema to neon

Closes #561, closes #628, closes #629, closes #564
  • Loading branch information
srizvi committed Jan 21, 2024
1 parent 2588eac commit c33f05e
Show file tree
Hide file tree
Showing 27 changed files with 2,407 additions and 158 deletions.
28 changes: 16 additions & 12 deletions apps/labs/src/env.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';

export const env = createEnv({
shared: {
NODE_ENV: z
.enum(["development", "production", "test"])
.default("development"),
VERCEL_ENV: z.enum(["development", "preview", "production"]).optional(),
.enum(['development', 'production', 'test'])
.default('development'),
VERCEL_ENV: z.enum(['development', 'preview', 'production']).optional(),
VERCEL_URL: z
.string()
.optional()
Expand All @@ -19,6 +19,7 @@ export const env = createEnv({
DATABASE_URL: z.string().min(1),
DISCORD_CLIENT_ID: z.string().min(1),
DISCORD_CLIENT_SECRET: z.string().min(1),
DREON_DIRECT_URL: z.string().min(1),
GITHUB_OAUTH_TOKEN: z.string().min(1),
GOOGLE_CLIENT_ID: z.string().min(1),
GOOGLE_CLIENT_SECRET: z.string().min(1),
Expand All @@ -27,6 +28,7 @@ export const env = createEnv({
NEXTAUTH_SECRET: z.string().min(1),
NEXTAUTH_URL: z.string().url().optional(),
POSTGRES_URL_NON_POOLING: z.string().min(1),
PREON_DIRECT_URL: z.string().min(1),
PROJECT_ID_VERCEL: z.string().min(1),
RATELIMIT_UPSTASH_REDIS_REST_TOKEN: z.string().min(1),
RATELIMIT_UPSTASH_REDIS_REST_URL: z.string().min(1),
Expand Down Expand Up @@ -62,6 +64,7 @@ export const env = createEnv({
DATABASE_URL: process.env.DATABASE_URL,
DISCORD_CLIENT_ID: process.env.DISCORD_CLIENT_ID,
DISCORD_CLIENT_SECRET: process.env.DISCORD_CLIENT_SECRET,
DREON_DIRECT_URL: process.env.DREON_DIRECT_URL,
GITHUB_OAUTH_TOKEN: process.env.GITHUB_OAUTH_TOKEN,
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
Expand All @@ -70,17 +73,17 @@ export const env = createEnv({
NEXTAUTH_SECRET: process.env.NEXTAUTH_SECRET,
NEXTAUTH_URL: process.env.NEXTAUTH_URL,
NEXT_PUBLIC_APP_URL:
process.env.VERCEL_ENV === "production"
process.env.VERCEL_ENV === 'production'
? `${process.env.NEXT_PUBLIC_APP_URL}`
: process.env.VERCEL_ENV === "preview"
: process.env.VERCEL_ENV === 'preview'
? `${process.env.VERCEL_URL}`
: "http://localhost:3001",
: 'http://localhost:3001',
NEXT_PUBLIC_POSTHOG_HOST:
process.env.VERCEL_ENV === "production"
process.env.VERCEL_ENV === 'production'
? `${process.env.NEXT_PUBLIC_APP_URL}/ingest`
: process.env.VERCEL_ENV === "preview"
: process.env.VERCEL_ENV === 'preview'
? `${process.env.VERCEL_URL}/ingest`
: "http://localhost:3001/ingest",
: 'http://localhost:3001/ingest',
NEXT_PUBLIC_POSTHOG_KEY: process.env.NEXT_PUBLIC_POSTHOG_KEY,
NEXT_PUBLIC_ROOT_DOMAIN: process.env.NEXT_PUBLIC_ROOT_DOMAIN,
NEXT_PUBLIC_STRIPE_BEST_MONTHLY_PRICE_ID:
Expand All @@ -97,6 +100,7 @@ export const env = createEnv({
process.env.NEXT_PUBLIC_TIPTAP_COLLAB_APP_ID,
NEXT_PUBLIC_COLLAB_DOC_PREFIX: process.env.NEXT_PUBLIC_COLLAB_DOC_PREFIX,
POSTGRES_URL_NON_POOLING: process.env.POSTGRES_URL_NON_POOLING,
PREON_DIRECT_URL: process.env.PREON_DIRECT_URL,
PROJECT_ID_VERCEL: process.env.PROJECT_ID_VERCEL,
RATELIMIT_UPSTASH_REDIS_REST_TOKEN:
process.env.RATELIMIT_UPSTASH_REDIS_REST_TOKEN,
Expand All @@ -117,5 +121,5 @@ export const env = createEnv({
skipValidation:
!!process.env.CI ||
!!process.env.SKIP_ENV_VALIDATION ||
process.env.npm_lifecycle_event === "lint",
process.env.npm_lifecycle_event === 'lint',
});
32 changes: 14 additions & 18 deletions packages/db/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import type { Config } from "drizzle-kit";
import * as dotenv from "dotenv";
import type { Config } from 'drizzle-kit';

dotenv.config({ path: "../../.env" });
import * as dotenv from 'dotenv';

const uri = [
"mysql://",
process.env.DB_USERNAME,
":",
process.env.DB_PASSWORD,
"@",
process.env.DB_HOST,
":3306/",
process.env.DB_NAME,
'?ssl={"rejectUnauthorized":true}',
].join("");
dotenv.config({ path: '../../.env' });

if (!process.env.DREON_DIRECT_URL) {
throw new Error('Drizzle Config Error: DREON_DIRECT_URL is not defined.`');
}

export default {
schema: "./src/schema",
driver: "mysql2",
dbCredentials: { uri },
tablesFilter: ["t3turbo_*"],
schema: './src/schema',
out: './drizzle',
driver: 'pg',
dbCredentials: {
connectionString: process.env.DREON_DIRECT_URL,
},
tablesFilter: ['av_*'],
} satisfies Config;
Loading

0 comments on commit c33f05e

Please sign in to comment.