From adea07a890a2d00261edfdf58d6a3ea502345c76 Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Tue, 22 Apr 2025 04:29:05 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/api/src/db/schema/deployment.ts | 1 - apps/api/src/db/schema/project.ts | 22 +++++++++++----------- apps/api/src/db/schema/user.ts | 8 ++++++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/apps/api/src/db/schema/deployment.ts b/apps/api/src/db/schema/deployment.ts index 4de7f72e..08d5294f 100644 --- a/apps/api/src/db/schema/deployment.ts +++ b/apps/api/src/db/schema/deployment.ts @@ -103,7 +103,6 @@ export const deploymentSelectSchema = createSelectSchema(deployments).omit({ _url: true }) -// TODO: narrow export const deploymentUpdateSchema = createUpdateSchema(deployments).pick({ enabled: true, published: true, diff --git a/apps/api/src/db/schema/project.ts b/apps/api/src/db/schema/project.ts index 12ee697a..941e3bc3 100644 --- a/apps/api/src/db/schema/project.ts +++ b/apps/api/src/db/schema/project.ts @@ -61,23 +61,23 @@ export const projects = pgTable( _webhooks: jsonb().$type().default([]), // Stripe products corresponding to the stripe plans across deployments - stripeBaseProduct: stripeId(), - stripeRequestProduct: stripeId(), + stripeBaseProductId: stripeId(), + stripeRequestProductId: stripeId(), // [metricSlug: string]: string - stripeMetricProducts: jsonb().$type>().default({}), + stripeMetricProductIds: jsonb().$type>().default({}), // Stripe coupons associated with this project, mapping from unique coupon // hash to stripe coupon id. // `[hash: string]: string` - _stripeCoupons: jsonb().$type>().default({}), + _stripeCouponIds: jsonb().$type>().default({}), // Stripe billing plans associated with this project (created lazily), // mapping from unique plan hash to stripe plan ids for base and request // respectively. - // `[hash: string]: { basePlan: string, requestPlan: string }` - _stripePlans: jsonb() - .$type>() + // `[hash: string]: { basePlanId: string, requestPlanId: string }` + _stripePlanIds: jsonb() + .$type>() .default({}), // Connected Stripe account (standard or express). @@ -87,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: stripeId() + _stripeAccountId: stripeId() }, (table) => [ index('project_userId_idx').on(table.userId), @@ -150,9 +150,9 @@ export const projectSelectSchema = createSelectSchema(projects).omit({ _providerToken: true, _text: true, _webhooks: true, - _stripeCoupons: true, - _stripePlans: true, - _stripeAccount: true + _stripeCouponIds: true, + _stripePlanIds: true, + _stripeAccountId: true }) // TODO: narrow update schema diff --git a/apps/api/src/db/schema/user.ts b/apps/api/src/db/schema/user.ts index 2efe747a..8ee0dda7 100644 --- a/apps/api/src/db/schema/user.ts +++ b/apps/api/src/db/schema/user.ts @@ -18,6 +18,7 @@ import { createSelectSchema, createUpdateSchema, id, + stripeId, timestamps, userRoleEnum } from './utils' @@ -49,7 +50,7 @@ export const users = pgTable( // third-party auth providers providers: jsonb().$type().default({}), - stripeCustomerId: text() + stripeCustomerId: stripeId().unique() }, (table) => [ uniqueIndex('user_email_idx').on(table.email), @@ -69,7 +70,10 @@ export const usersRelations = relations(users, ({ many }) => ({ export type User = typeof users.$inferSelect -export const userInsertSchema = createInsertSchema(users).pick({ +export const userInsertSchema = createInsertSchema(users, { + // TODO: username validation + // username: (schema) => schema.min(3).max(20) +}).pick({ username: true, email: true, password: true,