pull/715/head
Travis Fischer 2025-04-22 04:21:43 +07:00
rodzic 9efa186ea0
commit 9201f9230e
5 zmienionych plików z 46 dodań i 29 usunięć

Wyświetl plik

@ -9,6 +9,7 @@ import {
createInsertSchema,
createSelectSchema,
createUpdateSchema,
cuid,
timestamps
} from './utils'
@ -16,7 +17,7 @@ export const deployments = pgTable(
'deployments',
{
// namespace/projectName@hash
id: text('id').primaryKey(),
id: text().primaryKey(),
...timestamps,
hash: text().notNull(),
@ -28,11 +29,11 @@ export const deployments = pgTable(
description: text().notNull().default(''),
readme: text().notNull().default(''),
userId: text()
userId: cuid()
.notNull()
.references(() => users.id),
teamId: text().references(() => teams.id),
projectId: text()
teamId: cuid().references(() => teams.id),
projectId: cuid()
.notNull()
.references(() => projects.id, {
onDelete: 'cascade'
@ -52,8 +53,8 @@ export const deployments = pgTable(
// Backend API URL
_url: text().notNull(),
pricingPlans: jsonb().$type<PricingPlan[]>(),
coupons: jsonb().$type<Coupon[]>()
pricingPlans: jsonb().$type<PricingPlan[]>().notNull(),
coupons: jsonb().$type<Coupon[]>().notNull().default([])
},
(table) => [
index('deployment_userId_idx').on(table.userId),

Wyświetl plik

@ -18,6 +18,8 @@ import {
createInsertSchema,
createSelectSchema,
createUpdateSchema,
cuid,
stripeId,
timestamps
} from './utils'
@ -25,22 +27,22 @@ export const projects = pgTable(
'projects',
{
// namespace/projectName
id: text('id').primaryKey(),
id: text().primaryKey(),
...timestamps,
name: text().notNull(),
alias: text(),
userId: text()
userId: cuid()
.notNull()
.references(() => users.id),
teamId: text().notNull(),
teamId: cuid().notNull(),
// Most recently published Deployment if one exists
lastPublishedDeploymentId: text(),
lastPublishedDeploymentId: cuid(),
// Most recent Deployment if one exists
lastDeploymentId: text(),
lastDeploymentId: cuid(),
applicationFeePercent: integer().notNull().default(20),
@ -59,8 +61,8 @@ export const projects = pgTable(
_webhooks: jsonb().$type<Webhook[]>().default([]),
// Stripe products corresponding to the stripe plans across deployments
stripeBaseProduct: text(),
stripeRequestProduct: text(),
stripeBaseProduct: stripeId(),
stripeRequestProduct: stripeId(),
// [metricSlug: string]: string
stripeMetricProducts: jsonb().$type<Record<string, string>>().default({}),
@ -85,7 +87,7 @@ export const projects = pgTable(
// the stripeID utility.
// TODO: is it wise to share this between dev and prod?
// TODO: is it okay for this to be public?
_stripeAccount: text()
_stripeAccount: stripeId()
},
(table) => [
index('project_userId_idx').on(table.userId),

Wyświetl plik

@ -1,33 +1,27 @@
import { relations } from 'drizzle-orm'
import {
index,
pgTable,
primaryKey,
text,
uniqueIndex
} from 'drizzle-orm/pg-core'
import { index, pgTable, primaryKey } from 'drizzle-orm/pg-core'
import { teams } from './team'
import { users } from './user'
import { teamMemberRoleEnum, timestamps } from './utils'
import { cuid, teamMemberRoleEnum, timestamps } from './utils'
export const teamMembers = pgTable(
'team_members',
{
...timestamps,
userId: text()
userId: cuid()
.notNull()
.references(() => users.id, { onDelete: 'cascade' }),
teamId: text()
teamId: cuid()
.notNull()
.references(() => teams.id, { onDelete: 'cascade' }),
role: teamMemberRoleEnum().default('user').notNull()
},
(table) => [
primaryKey({ columns: [table.userId, table.teamId] }),
uniqueIndex('team_member_user_idx').on(table.userId),
uniqueIndex('team_member_team_idx').on(table.teamId),
index('team_member_user_idx').on(table.userId),
index('team_member_team_idx').on(table.teamId),
index('team_member_createdAt_idx').on(table.createdAt),
index('team_member_updatedAt_idx').on(table.updatedAt)
]

Wyświetl plik

@ -7,6 +7,7 @@ import {
createInsertSchema,
createSelectSchema,
createUpdateSchema,
cuid,
id,
timestamps
} from './utils'
@ -20,7 +21,7 @@ export const teams = pgTable(
slug: text().notNull().unique(),
name: text().notNull(),
ownerId: text('owner').notNull()
ownerId: cuid().notNull()
},
(table) => [
uniqueIndex('team_slug_idx').on(table.slug),

Wyświetl plik

@ -1,10 +1,29 @@
import { createId } from '@paralleldrive/cuid2'
import { sql } from 'drizzle-orm'
import { pgEnum, text, timestamp } from 'drizzle-orm/pg-core'
import { sql, type Writable } from 'drizzle-orm'
import {
pgEnum,
type PgVarcharBuilderInitial,
type PgVarcharConfig,
text,
timestamp,
varchar
} from 'drizzle-orm/pg-core'
import { createSchemaFactory } from 'drizzle-zod'
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 = {
createdAt: timestamp('createdAt').notNull().defaultNow(),
updatedAt: timestamp('updatedAt')