feat(09-01): add property_address column to clients — schema, migration, server actions

- Add propertyAddress: text("property_address") nullable column to clients pgTable
- Generate migration drizzle/0007_equal_nekra.sql: ALTER TABLE "clients" ADD COLUMN "property_address" text
- Apply migration successfully to local postgres database
- Extend clientSchema Zod schema with propertyAddress: z.string().optional()
- createClient: persist propertyAddress || null to coerce empty string to NULL
- updateClient: persist propertyAddress || null alongside name, email, updatedAt
This commit is contained in:
Chandler Copeland
2026-03-21 12:13:55 -06:00
parent 569dc0fc97
commit baa1c785a5
5 changed files with 474 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ import { eq } from "drizzle-orm";
const clientSchema = z.object({
name: z.string().min(1, "Name is required"),
email: z.string().email("Valid email address required"),
propertyAddress: z.string().optional(),
});
export async function createClient(
@@ -24,6 +25,7 @@ export async function createClient(
const parsed = clientSchema.safeParse({
name: formData.get("name"),
email: formData.get("email"),
propertyAddress: formData.get("propertyAddress"),
});
if (!parsed.success) {
@@ -33,6 +35,7 @@ export async function createClient(
await db.insert(clients).values({
name: parsed.data.name,
email: parsed.data.email,
propertyAddress: parsed.data.propertyAddress || null,
});
revalidatePath("/portal/clients");
@@ -52,6 +55,7 @@ export async function updateClient(
const parsed = clientSchema.safeParse({
name: formData.get("name"),
email: formData.get("email"),
propertyAddress: formData.get("propertyAddress"),
});
if (!parsed.success) {
@@ -60,7 +64,7 @@ export async function updateClient(
await db
.update(clients)
.set({ name: parsed.data.name, email: parsed.data.email, updatedAt: new Date() })
.set({ name: parsed.data.name, email: parsed.data.email, propertyAddress: parsed.data.propertyAddress || null, updatedAt: new Date() })
.where(eq(clients.id, id));
revalidatePath("/portal/clients");

View File

@@ -55,6 +55,7 @@ export const clients = pgTable("clients", {
id: text("id").primaryKey().$defaultFn(() => crypto.randomUUID()),
name: text("name").notNull(),
email: text("email").notNull(),
propertyAddress: text("property_address"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at").defaultNow().notNull(),
});