feat(create-turbo): create https://github.com/juliusmarminge/acme-corp
This commit is contained in:
22
packages/db/index.ts
Normal file
22
packages/db/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// Generated by prisma/post-generate.ts
|
||||
|
||||
import { Kysely } from "kysely";
|
||||
import { PlanetScaleDialect } from "kysely-planetscale";
|
||||
import { customAlphabet } from "nanoid";
|
||||
|
||||
import type { DB } from "./prisma/types";
|
||||
|
||||
export { jsonArrayFrom, jsonObjectFrom } from "kysely/helpers/postgres";
|
||||
|
||||
export * from "./prisma/types";
|
||||
export * from "./prisma/enums";
|
||||
|
||||
export const db = new Kysely<DB>({
|
||||
dialect: new PlanetScaleDialect({
|
||||
url: process.env.DATABASE_URL,
|
||||
}),
|
||||
});
|
||||
|
||||
// Use custom alphabet without special chars for less chaotic, copy-able URLs
|
||||
// Will not collide for a long long time: https://zelark.github.io/nano-id-cc/
|
||||
export const genId = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 16);
|
||||
45
packages/db/package.json
Normal file
45
packages/db/package.json
Normal file
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "@acme/db",
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"exports": {
|
||||
".": "./index.ts"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "rm -rf .turbo node_modules",
|
||||
"db:generate": "pnpm with-env prisma generate",
|
||||
"db:push": "pnpm with-env prisma db push --skip-generate",
|
||||
"studio": "pnpm with-env prisma studio --port 5556",
|
||||
"format": "prisma format && prettier --check \"**/*.{mjs,ts,json}\"",
|
||||
"lint": "eslint .",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"with-env": "dotenv -e ../../.env.local --"
|
||||
},
|
||||
"dependencies": {
|
||||
"@planetscale/database": "^1.14.0",
|
||||
"kysely": "^0.27.2",
|
||||
"kysely-planetscale": "^1.4.0",
|
||||
"nanoid": "^5.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@acme/eslint-config": "^0.2.0",
|
||||
"@acme/prettier-config": "^0.1.0",
|
||||
"@acme/tsconfig": "^0.1.0",
|
||||
"dotenv-cli": "^7.3.0",
|
||||
"eslint": "^8.56.0",
|
||||
"prettier": "^3.2.4",
|
||||
"prisma": "^5.8.1",
|
||||
"prisma-kysely": "^1.7.1",
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"@acme/eslint-config/base"
|
||||
],
|
||||
"rules": {
|
||||
"@typescript-eslint/consistent-type-definitions": "off"
|
||||
}
|
||||
},
|
||||
"prettier": "@acme/prettier-config"
|
||||
}
|
||||
12
packages/db/prisma/enums.ts
Normal file
12
packages/db/prisma/enums.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export const ProjectTier = {
|
||||
FREE: "FREE",
|
||||
PRO: "PRO",
|
||||
} as const;
|
||||
export type ProjectTier = (typeof ProjectTier)[keyof typeof ProjectTier];
|
||||
export const SubscriptionPlan = {
|
||||
FREE: "FREE",
|
||||
STANDARD: "STANDARD",
|
||||
PRO: "PRO",
|
||||
} as const;
|
||||
export type SubscriptionPlan =
|
||||
(typeof SubscriptionPlan)[keyof typeof SubscriptionPlan];
|
||||
83
packages/db/prisma/schema.prisma
Normal file
83
packages/db/prisma/schema.prisma
Normal file
@@ -0,0 +1,83 @@
|
||||
generator kysely {
|
||||
provider = "prisma-kysely"
|
||||
output = "."
|
||||
enumFileName = "enums.ts"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "mysql"
|
||||
url = env("DATABASE_URL")
|
||||
relationMode = "prisma"
|
||||
}
|
||||
|
||||
enum ProjectTier {
|
||||
FREE
|
||||
PRO
|
||||
}
|
||||
|
||||
model Project {
|
||||
id String @id @db.VarChar(30) // prefix_ + nanoid (16)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
// A project is tied to a Clerk User or Organization
|
||||
organizationId String? @db.VarChar(36) // uuid v4
|
||||
userId String? @db.VarChar(36) // uuid v4
|
||||
|
||||
name String
|
||||
tier ProjectTier @default(FREE)
|
||||
url String?
|
||||
|
||||
@@index([organizationId])
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
enum SubscriptionPlan {
|
||||
FREE
|
||||
STANDARD
|
||||
PRO
|
||||
}
|
||||
|
||||
model Customer {
|
||||
id String @id @db.VarChar(30) // prefix_ + nanoid (16)
|
||||
stripeId String @unique
|
||||
subscriptionId String?
|
||||
clerkUserId String
|
||||
clerkOrganizationId String?
|
||||
name String?
|
||||
plan SubscriptionPlan?
|
||||
paidUntil DateTime?
|
||||
endsAt DateTime?
|
||||
|
||||
@@index([clerkUserId])
|
||||
}
|
||||
|
||||
model ApiKey {
|
||||
id String @id @db.VarChar(30) // prefix_ + nanoid (16)
|
||||
createdAt DateTime @default(now())
|
||||
expiresAt DateTime?
|
||||
lastUsed DateTime?
|
||||
revokedAt DateTime?
|
||||
|
||||
projectId String @db.VarChar(30) // prefix_ + nanoid (16)
|
||||
clerkUserId String @db.VarChar(36) // uuid v4
|
||||
|
||||
name String @default("Secret Key")
|
||||
key String @unique
|
||||
|
||||
@@index([projectId])
|
||||
}
|
||||
|
||||
model Ingestion {
|
||||
id String @id @db.VarChar(30) // prefix_ + nanoid (16)
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
projectId String @db.VarChar(30) // prefix_ + nanoid (16)
|
||||
apiKeyId String @db.VarChar(30) // prefix_ + nanoid (16)
|
||||
|
||||
schema Json
|
||||
hash String @db.VarChar(40) // sha1
|
||||
parent String? @db.VarChar(40) // sha1
|
||||
origin String @db.VarChar(100)
|
||||
|
||||
@@index([projectId])
|
||||
}
|
||||
57
packages/db/prisma/types.ts
Normal file
57
packages/db/prisma/types.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { ColumnType } from "kysely";
|
||||
|
||||
import type { ProjectTier, SubscriptionPlan } from "./enums";
|
||||
|
||||
export type Generated<T> =
|
||||
T extends ColumnType<infer S, infer I, infer U>
|
||||
? ColumnType<S, I | undefined, U>
|
||||
: ColumnType<T, T | undefined, T>;
|
||||
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
|
||||
|
||||
export type ApiKey = {
|
||||
id: string;
|
||||
createdAt: Generated<Timestamp>;
|
||||
expiresAt: Timestamp | null;
|
||||
lastUsed: Timestamp | null;
|
||||
revokedAt: Timestamp | null;
|
||||
projectId: string;
|
||||
clerkUserId: string;
|
||||
name: Generated<string>;
|
||||
key: string;
|
||||
};
|
||||
export type Customer = {
|
||||
id: string;
|
||||
stripeId: string;
|
||||
subscriptionId: string | null;
|
||||
clerkUserId: string;
|
||||
clerkOrganizationId: string | null;
|
||||
name: string | null;
|
||||
plan: SubscriptionPlan | null;
|
||||
paidUntil: Timestamp | null;
|
||||
endsAt: Timestamp | null;
|
||||
};
|
||||
export type Ingestion = {
|
||||
id: string;
|
||||
createdAt: Generated<Timestamp>;
|
||||
projectId: string;
|
||||
apiKeyId: string;
|
||||
schema: unknown;
|
||||
hash: string;
|
||||
parent: string | null;
|
||||
origin: string;
|
||||
};
|
||||
export type Project = {
|
||||
id: string;
|
||||
createdAt: Generated<Timestamp>;
|
||||
organizationId: string | null;
|
||||
userId: string | null;
|
||||
name: string;
|
||||
tier: Generated<ProjectTier>;
|
||||
url: string | null;
|
||||
};
|
||||
export type DB = {
|
||||
ApiKey: ApiKey;
|
||||
Customer: Customer;
|
||||
Ingestion: Ingestion;
|
||||
Project: Project;
|
||||
};
|
||||
8
packages/db/tsconfig.json
Normal file
8
packages/db/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@acme/tsconfig/base.json",
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json",
|
||||
},
|
||||
"include": ["*.ts", "prisma", "src"],
|
||||
"exclude": ["node_modules"],
|
||||
}
|
||||
Reference in New Issue
Block a user