kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
9efa186ea0
commit
9201f9230e
|
@ -9,6 +9,7 @@ import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
createUpdateSchema,
|
createUpdateSchema,
|
||||||
|
cuid,
|
||||||
timestamps
|
timestamps
|
||||||
} from './utils'
|
} from './utils'
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@ export const deployments = pgTable(
|
||||||
'deployments',
|
'deployments',
|
||||||
{
|
{
|
||||||
// namespace/projectName@hash
|
// namespace/projectName@hash
|
||||||
id: text('id').primaryKey(),
|
id: text().primaryKey(),
|
||||||
...timestamps,
|
...timestamps,
|
||||||
|
|
||||||
hash: text().notNull(),
|
hash: text().notNull(),
|
||||||
|
@ -28,11 +29,11 @@ export const deployments = pgTable(
|
||||||
description: text().notNull().default(''),
|
description: text().notNull().default(''),
|
||||||
readme: text().notNull().default(''),
|
readme: text().notNull().default(''),
|
||||||
|
|
||||||
userId: text()
|
userId: cuid()
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id),
|
.references(() => users.id),
|
||||||
teamId: text().references(() => teams.id),
|
teamId: cuid().references(() => teams.id),
|
||||||
projectId: text()
|
projectId: cuid()
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => projects.id, {
|
.references(() => projects.id, {
|
||||||
onDelete: 'cascade'
|
onDelete: 'cascade'
|
||||||
|
@ -52,8 +53,8 @@ export const deployments = pgTable(
|
||||||
// Backend API URL
|
// Backend API URL
|
||||||
_url: text().notNull(),
|
_url: text().notNull(),
|
||||||
|
|
||||||
pricingPlans: jsonb().$type<PricingPlan[]>(),
|
pricingPlans: jsonb().$type<PricingPlan[]>().notNull(),
|
||||||
coupons: jsonb().$type<Coupon[]>()
|
coupons: jsonb().$type<Coupon[]>().notNull().default([])
|
||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
index('deployment_userId_idx').on(table.userId),
|
index('deployment_userId_idx').on(table.userId),
|
||||||
|
|
|
@ -18,6 +18,8 @@ import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
createUpdateSchema,
|
createUpdateSchema,
|
||||||
|
cuid,
|
||||||
|
stripeId,
|
||||||
timestamps
|
timestamps
|
||||||
} from './utils'
|
} from './utils'
|
||||||
|
|
||||||
|
@ -25,22 +27,22 @@ export const projects = pgTable(
|
||||||
'projects',
|
'projects',
|
||||||
{
|
{
|
||||||
// namespace/projectName
|
// namespace/projectName
|
||||||
id: text('id').primaryKey(),
|
id: text().primaryKey(),
|
||||||
...timestamps,
|
...timestamps,
|
||||||
|
|
||||||
name: text().notNull(),
|
name: text().notNull(),
|
||||||
alias: text(),
|
alias: text(),
|
||||||
|
|
||||||
userId: text()
|
userId: cuid()
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id),
|
.references(() => users.id),
|
||||||
teamId: text().notNull(),
|
teamId: cuid().notNull(),
|
||||||
|
|
||||||
// Most recently published Deployment if one exists
|
// Most recently published Deployment if one exists
|
||||||
lastPublishedDeploymentId: text(),
|
lastPublishedDeploymentId: cuid(),
|
||||||
|
|
||||||
// Most recent Deployment if one exists
|
// Most recent Deployment if one exists
|
||||||
lastDeploymentId: text(),
|
lastDeploymentId: cuid(),
|
||||||
|
|
||||||
applicationFeePercent: integer().notNull().default(20),
|
applicationFeePercent: integer().notNull().default(20),
|
||||||
|
|
||||||
|
@ -59,8 +61,8 @@ export const projects = pgTable(
|
||||||
_webhooks: jsonb().$type<Webhook[]>().default([]),
|
_webhooks: jsonb().$type<Webhook[]>().default([]),
|
||||||
|
|
||||||
// Stripe products corresponding to the stripe plans across deployments
|
// Stripe products corresponding to the stripe plans across deployments
|
||||||
stripeBaseProduct: text(),
|
stripeBaseProduct: stripeId(),
|
||||||
stripeRequestProduct: text(),
|
stripeRequestProduct: stripeId(),
|
||||||
|
|
||||||
// [metricSlug: string]: string
|
// [metricSlug: string]: string
|
||||||
stripeMetricProducts: jsonb().$type<Record<string, string>>().default({}),
|
stripeMetricProducts: jsonb().$type<Record<string, string>>().default({}),
|
||||||
|
@ -85,7 +87,7 @@ export const projects = pgTable(
|
||||||
// the stripeID utility.
|
// the stripeID utility.
|
||||||
// TODO: is it wise to share this between dev and prod?
|
// TODO: is it wise to share this between dev and prod?
|
||||||
// TODO: is it okay for this to be public?
|
// TODO: is it okay for this to be public?
|
||||||
_stripeAccount: text()
|
_stripeAccount: stripeId()
|
||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
index('project_userId_idx').on(table.userId),
|
index('project_userId_idx').on(table.userId),
|
||||||
|
|
|
@ -1,33 +1,27 @@
|
||||||
import { relations } from 'drizzle-orm'
|
import { relations } from 'drizzle-orm'
|
||||||
import {
|
import { index, pgTable, primaryKey } from 'drizzle-orm/pg-core'
|
||||||
index,
|
|
||||||
pgTable,
|
|
||||||
primaryKey,
|
|
||||||
text,
|
|
||||||
uniqueIndex
|
|
||||||
} from 'drizzle-orm/pg-core'
|
|
||||||
|
|
||||||
import { teams } from './team'
|
import { teams } from './team'
|
||||||
import { users } from './user'
|
import { users } from './user'
|
||||||
import { teamMemberRoleEnum, timestamps } from './utils'
|
import { cuid, teamMemberRoleEnum, timestamps } from './utils'
|
||||||
|
|
||||||
export const teamMembers = pgTable(
|
export const teamMembers = pgTable(
|
||||||
'team_members',
|
'team_members',
|
||||||
{
|
{
|
||||||
...timestamps,
|
...timestamps,
|
||||||
|
|
||||||
userId: text()
|
userId: cuid()
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id, { onDelete: 'cascade' }),
|
.references(() => users.id, { onDelete: 'cascade' }),
|
||||||
teamId: text()
|
teamId: cuid()
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => teams.id, { onDelete: 'cascade' }),
|
.references(() => teams.id, { onDelete: 'cascade' }),
|
||||||
role: teamMemberRoleEnum().default('user').notNull()
|
role: teamMemberRoleEnum().default('user').notNull()
|
||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
primaryKey({ columns: [table.userId, table.teamId] }),
|
primaryKey({ columns: [table.userId, table.teamId] }),
|
||||||
uniqueIndex('team_member_user_idx').on(table.userId),
|
index('team_member_user_idx').on(table.userId),
|
||||||
uniqueIndex('team_member_team_idx').on(table.teamId),
|
index('team_member_team_idx').on(table.teamId),
|
||||||
index('team_member_createdAt_idx').on(table.createdAt),
|
index('team_member_createdAt_idx').on(table.createdAt),
|
||||||
index('team_member_updatedAt_idx').on(table.updatedAt)
|
index('team_member_updatedAt_idx').on(table.updatedAt)
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
createInsertSchema,
|
createInsertSchema,
|
||||||
createSelectSchema,
|
createSelectSchema,
|
||||||
createUpdateSchema,
|
createUpdateSchema,
|
||||||
|
cuid,
|
||||||
id,
|
id,
|
||||||
timestamps
|
timestamps
|
||||||
} from './utils'
|
} from './utils'
|
||||||
|
@ -20,7 +21,7 @@ export const teams = pgTable(
|
||||||
slug: text().notNull().unique(),
|
slug: text().notNull().unique(),
|
||||||
name: text().notNull(),
|
name: text().notNull(),
|
||||||
|
|
||||||
ownerId: text('owner').notNull()
|
ownerId: cuid().notNull()
|
||||||
},
|
},
|
||||||
(table) => [
|
(table) => [
|
||||||
uniqueIndex('team_slug_idx').on(table.slug),
|
uniqueIndex('team_slug_idx').on(table.slug),
|
||||||
|
|
|
@ -1,10 +1,29 @@
|
||||||
import { createId } from '@paralleldrive/cuid2'
|
import { createId } from '@paralleldrive/cuid2'
|
||||||
import { sql } from 'drizzle-orm'
|
import { sql, type Writable } from 'drizzle-orm'
|
||||||
import { pgEnum, text, timestamp } from 'drizzle-orm/pg-core'
|
import {
|
||||||
|
pgEnum,
|
||||||
|
type PgVarcharBuilderInitial,
|
||||||
|
type PgVarcharConfig,
|
||||||
|
text,
|
||||||
|
timestamp,
|
||||||
|
varchar
|
||||||
|
} from 'drizzle-orm/pg-core'
|
||||||
import { createSchemaFactory } from 'drizzle-zod'
|
import { createSchemaFactory } from 'drizzle-zod'
|
||||||
|
|
||||||
export const id = text('id').primaryKey().$defaultFn(createId)
|
export const id = text('id').primaryKey().$defaultFn(createId)
|
||||||
|
|
||||||
|
export function cuid<U extends string, T extends Readonly<[U, ...U[]]>>(
|
||||||
|
config?: PgVarcharConfig<T | Writable<T>, never>
|
||||||
|
): PgVarcharBuilderInitial<'', Writable<T>, 24> {
|
||||||
|
return varchar({ length: 24, ...config })
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stripeId<U extends string, T extends Readonly<[U, ...U[]]>>(
|
||||||
|
config?: PgVarcharConfig<T | Writable<T>, never>
|
||||||
|
): PgVarcharBuilderInitial<'', Writable<T>, 255> {
|
||||||
|
return varchar({ length: 255, ...config })
|
||||||
|
}
|
||||||
|
|
||||||
export const timestamps = {
|
export const timestamps = {
|
||||||
createdAt: timestamp('createdAt').notNull().defaultNow(),
|
createdAt: timestamp('createdAt').notNull().defaultNow(),
|
||||||
updatedAt: timestamp('updatedAt')
|
updatedAt: timestamp('updatedAt')
|
||||||
|
|
Ładowanie…
Reference in New Issue