Skip to content

Commit

Permalink
fix: cleanup prisma singletons and eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed May 16, 2024
1 parent 9048119 commit 7e370d2
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 166 deletions.
43 changes: 23 additions & 20 deletions apps/backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import antfu from "@antfu/eslint-config"
// Rules: https://eslint-config.antfu.me/rules

export default antfu({
lessOpinionated: true,
stylistic: {
semi: false,
indent: 2,
quotes: "double",
export default antfu(
{
lessOpinionated: true,
stylistic: {
semi: false,
indent: 2,
quotes: "double",
},
typescript: {
tsconfigPath: "tsconfig.json",
},
ignores: ["**/fixtures"],
formatters: {
css: true,
html: true,
},
},
typescript: {
tsconfigPath: "tsconfig.json",
{
rules: {
"no-console": ["off", "never"],
"node/prefer-global/process": ["off", "never"],
"style/brace-style": ["warn", "1tbs"],
},
},
ignores: ["**/fixtures"],
formatters: {
css: true,
html: true,
},
}, {
rules: {
"no-console": ["off", "never"],
"node/prefer-global/process": ["off", "never"],
"style/brace-style": ["1tbs", "warn"],
},
})
)
106 changes: 47 additions & 59 deletions apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Note: Prisma FTS workaround: https://github.com/Linen-dev/linen.dev/blob/main/packages/database/prisma/schema.prisma

datasource db {
provider = "postgres"
url = env("DATABASE_URL")
Expand All @@ -16,6 +15,53 @@ generator zod {
useTypeAssertions = true
}

model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onUpdate: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([provider, providerAccountId])
@@index([userId])
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
settings Json? @default("{}")
createdAt DateTime @default(now())
accounts Account[]
sessions Session[]
bookmarks Bookmark[]
tags Tag[]
feeds Feed[]
feedEntries FeedEntry[]
feedMedia FeedEntryMedia[]
categories Category[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

model Bookmark {
id String @id @default(cuid())
title String?
Expand Down Expand Up @@ -73,64 +119,6 @@ model Category {
@@index([userId])
}

// @auth/sveltekit
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onUpdate: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([provider, providerAccountId])
@@index([userId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
@@index([userId])
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
settings Json? @default("{}")
createdAt DateTime @default(now())
accounts Account[]
sessions Session[]
bookmarks Bookmark[]
tags Tag[]
feeds Feed[]
feedEntries FeedEntry[]
feedMedia FeedEntryMedia[]
categories Category[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

model Feed {
id String @id @default(cuid())
name String
Expand Down
4 changes: 3 additions & 1 deletion apps/backend/src/plugins/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { getLogger } from "./logger.js";
const logger = getLogger({ prefix: "db" });

process.on("exit", async () => {
logger.debug("Cleaning up database connection");
// Note: might not be necessary, hook might be built into Prisma now-a-days.
// needs more research.
logger.info("Cleaning up database connection");
await prisma.$disconnect();
});

Expand Down
47 changes: 25 additions & 22 deletions apps/web/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
import antfu from "@antfu/eslint-config"
// Rules: https://eslint-config.antfu.me/rules

export default antfu({
lessOpinionated: true,
svelte: true,
stylistic: {
semi: false,
indent: 2,
quotes: "double",
export default antfu(
{
lessOpinionated: true,
svelte: true,
stylistic: {
semi: false,
indent: 2,
quotes: "double",
},
typescript: {
tsconfigPath: "tsconfig.json",
},
ignores: ["**/fixtures"],
formatters: {
css: true,
html: true,
markdown: "prettier",
},
},
typescript: {
tsconfigPath: "tsconfig.json",
{
rules: {
"no-console": ["off", "never"],
"node/prefer-global/process": ["off", "never"],
"style/brace-style": ["warn", "1tbs"],
},
},
ignores: ["**/fixtures"],
formatters: {
css: true,
html: true,
markdown: "prettier",
},
}, {
rules: {
"no-console": ["off", "never"],
"node/prefer-global/process": ["off", "never"],
"style/brace-style": ["1tbs", "warn"],
},
})
)
106 changes: 47 additions & 59 deletions apps/web/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Note: Prisma FTS workaround: https://github.com/Linen-dev/linen.dev/blob/main/packages/database/prisma/schema.prisma

datasource db {
provider = "postgres"
url = env("DATABASE_URL")
Expand All @@ -16,6 +15,53 @@ generator zod {
useTypeAssertions = true
}

model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onUpdate: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([provider, providerAccountId])
@@index([userId])
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
settings Json? @default("{}")
createdAt DateTime @default(now())
accounts Account[]
sessions Session[]
bookmarks Bookmark[]
tags Tag[]
feeds Feed[]
feedEntries FeedEntry[]
feedMedia FeedEntryMedia[]
categories Category[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

model Bookmark {
id String @id @default(cuid())
title String?
Expand Down Expand Up @@ -73,64 +119,6 @@ model Category {
@@index([userId])
}

// @auth/sveltekit
model Account {
id String @id @default(cuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onUpdate: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([provider, providerAccountId])
@@index([userId])
}

model Session {
id String @id @default(cuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
@@index([userId])
}

model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
settings Json? @default("{}")
createdAt DateTime @default(now())
accounts Account[]
sessions Session[]
bookmarks Bookmark[]
tags Tag[]
feeds Feed[]
feedEntries FeedEntry[]
feedMedia FeedEntryMedia[]
categories Category[]
}

model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}

model Feed {
id String @id @default(cuid())
name String
Expand Down
8 changes: 3 additions & 5 deletions apps/web/src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PrismaClient, Prisma } from "@prisma/client"

const globalForPrisma = globalThis as unknown as { prisma: PrismaClient }

const prisma =
export const db =
globalForPrisma.prisma ||
new PrismaClient().$extends({
name: "findManyAndCount",
Expand All @@ -12,7 +12,7 @@ const prisma =
this: Model,
args: Prisma.Exact<Args, Prisma.Args<Model, "findMany">>,
): Promise<[Prisma.Result<Model, Args, "findMany">, number]> {
return prisma.$transaction([
return db.$transaction([
(this as any).findMany(args),
(this as any).count({ where: (args as any).where }),
]) as any
Expand All @@ -21,6 +21,4 @@ const prisma =
},
})

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma

export { prisma as db }
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = db

0 comments on commit 7e370d2

Please sign in to comment.