Skip to content
Merged
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
1 change: 0 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions drizzle/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { InferSelectModel } from "drizzle-orm";
import type { NeonHttpDatabase } from "drizzle-orm/neon-http";
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
import type * as dbSchema from "./schema";
import type {
activity,
Expand All @@ -12,7 +12,7 @@ import type {
user,
} from "./schema";

export type Database = NeonHttpDatabase<typeof dbSchema>;
export type Database = NodePgDatabase<typeof dbSchema>;

export type User = InferSelectModel<typeof user>;
export type Project = InferSelectModel<typeof project>;
Expand Down
13 changes: 6 additions & 7 deletions lib/utils/useDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { neon } from "@neondatabase/serverless";
import { sql } from "drizzle-orm";
import { upstashCache } from "drizzle-orm/cache/upstash";
import { drizzle } from "drizzle-orm/neon-http";
import { drizzle } from "drizzle-orm/node-postgres";
import { err, ok, type Result } from "neverthrow";
import { cache } from "react";
import type { Database } from "@/drizzle/types";
Expand Down Expand Up @@ -33,10 +32,8 @@ export async function getDatabaseForOwner(ownerId: string): Promise<Database> {
);

const sslMode = process.env.DATABASE_SSL === "true" ? "?sslmode=require" : "";
const client = neon(`${process.env.DATABASE_URL}/${databaseName}${sslMode}`);

return drizzle({
client,
return drizzle(`${process.env.DATABASE_URL}/${databaseName}${sslMode}`, {
cache: upstashCache({
url: process.env.UPSTASH_REDIS_REST_URL!,
token: process.env.UPSTASH_REDIS_REST_TOKEN!,
Expand All @@ -55,8 +52,10 @@ export async function deleteDatabase(ownerId: string) {
);

const sslMode = process.env.DATABASE_SSL === "true" ? "?sslmode=require" : "";
const client = neon(`${process.env.DATABASE_URL}/manage${sslMode}`);
const ownerDb = drizzle({ client, schema });

const ownerDb = drizzle(`${process.env.DATABASE_URL}/manage${sslMode}`, {
schema,
});

// Terminate all connections to the database before dropping
await ownerDb.execute(sql`
Expand Down
4 changes: 2 additions & 2 deletions ops/drizzle/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NeonHttpDatabase } from "drizzle-orm/neon-http";
import type { NodePgDatabase } from "drizzle-orm/node-postgres";
import type * as dbSchema from "./schema";

export type OpsDatabase = NeonHttpDatabase<typeof dbSchema>;
export type OpsDatabase = NodePgDatabase<typeof dbSchema>;
6 changes: 2 additions & 4 deletions ops/useOps.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { UserJSON } from "@clerk/nextjs/server";
import { neon } from "@neondatabase/serverless";
import { drizzle } from "drizzle-orm/neon-http";
import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "./drizzle/schema";
import type { OpsDatabase } from "./drizzle/types";

export async function getOpsDatabase(): Promise<OpsDatabase> {
const sslMode = process.env.DATABASE_SSL === "true" ? "?sslmode=require" : "";
const client = neon(`${process.env.DATABASE_URL}/manage${sslMode}`);
return drizzle({ client, schema });
return drizzle(`${process.env.DATABASE_URL}/manage${sslMode}`, { schema });
}

export async function addUserToOpsDb(userData: UserJSON) {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"@dnd-kit/sortable": "^8.0.0",
"@dnd-kit/utilities": "^3.2.2",
"@headlessui/react": "^2.2.0",
"@neondatabase/serverless": "^1.0.2",
"@radix-ui/react-avatar": "^1.1.0",
"@radix-ui/react-checkbox": "^1.1.1",
"@radix-ui/react-collapsible": "^1.1.2",
Expand Down