From 3d9ac75283c13d33b0200b1c1b814417ae748736 Mon Sep 17 00:00:00 2001 From: Jared Pereira Date: Wed, 22 Jan 2025 17:01:00 -0500 Subject: [PATCH] migration to add created_at fields to domain tables --- drizzle/relations.ts | 16 ++++++++-------- drizzle/schema.ts | 14 ++++++++------ supabase/database.types.ts | 6 ++++++ ...122215946_add_created_at_to_domain_tables.sql | 3 +++ 4 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 supabase/migrations/20250122215946_add_created_at_to_domain_tables.sql diff --git a/drizzle/relations.ts b/drizzle/relations.ts index 96d515e0..c0d11e54 100644 --- a/drizzle/relations.ts +++ b/drizzle/relations.ts @@ -69,6 +69,14 @@ export const email_auth_tokensRelations = relations(email_auth_tokens, ({one}) = }), })); +export const custom_domainsRelations = relations(custom_domains, ({one, many}) => ({ + identity: one(identities, { + fields: [custom_domains.identity], + references: [identities.email] + }), + custom_domain_routes: many(custom_domain_routes), +})); + export const custom_domain_routesRelations = relations(custom_domain_routes, ({one}) => ({ custom_domain: one(custom_domains, { fields: [custom_domain_routes.domain], @@ -86,14 +94,6 @@ export const custom_domain_routesRelations = relations(custom_domain_routes, ({o }), })); -export const custom_domainsRelations = relations(custom_domains, ({one, many}) => ({ - custom_domain_routes: many(custom_domain_routes), - identity: one(identities, { - fields: [custom_domains.identity], - references: [identities.email] - }), -})); - export const phone_rsvps_to_entityRelations = relations(phone_rsvps_to_entity, ({one}) => ({ entity: one(entities, { fields: [phone_rsvps_to_entity.entity], diff --git a/drizzle/schema.ts b/drizzle/schema.ts index ca17c27f..2f0a7028 100644 --- a/drizzle/schema.ts +++ b/drizzle/schema.ts @@ -88,12 +88,20 @@ export const phone_number_auth_tokens = pgTable("phone_number_auth_tokens", { country_code: text("country_code").notNull(), }); +export const custom_domains = pgTable("custom_domains", { + domain: text("domain").primaryKey().notNull(), + identity: text("identity").default('').notNull().references(() => identities.email, { onDelete: "cascade", onUpdate: "cascade" } ), + confirmed: boolean("confirmed").notNull(), + created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), +}); + export const custom_domain_routes = pgTable("custom_domain_routes", { id: uuid("id").defaultRandom().primaryKey().notNull(), domain: text("domain").notNull().references(() => custom_domains.domain), route: text("route").notNull(), view_permission_token: uuid("view_permission_token").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), edit_permission_token: uuid("edit_permission_token").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), + created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), }, (table) => { return { @@ -101,12 +109,6 @@ export const custom_domain_routes = pgTable("custom_domain_routes", { } }); -export const custom_domains = pgTable("custom_domains", { - domain: text("domain").primaryKey().notNull(), - identity: text("identity").default('').notNull().references(() => identities.email, { onDelete: "cascade", onUpdate: "cascade" } ), - confirmed: boolean("confirmed").notNull(), -}); - export const phone_rsvps_to_entity = pgTable("phone_rsvps_to_entity", { created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), phone_number: text("phone_number").notNull(), diff --git a/supabase/database.types.ts b/supabase/database.types.ts index f50bdcaa..80ed99f2 100644 --- a/supabase/database.types.ts +++ b/supabase/database.types.ts @@ -36,6 +36,7 @@ export type Database = { Tables: { custom_domain_routes: { Row: { + created_at: string domain: string edit_permission_token: string id: string @@ -43,6 +44,7 @@ export type Database = { view_permission_token: string } Insert: { + created_at?: string domain: string edit_permission_token: string id?: string @@ -50,6 +52,7 @@ export type Database = { view_permission_token: string } Update: { + created_at?: string domain?: string edit_permission_token?: string id?: string @@ -83,16 +86,19 @@ export type Database = { custom_domains: { Row: { confirmed: boolean + created_at: string domain: string identity: string } Insert: { confirmed: boolean + created_at?: string domain: string identity?: string } Update: { confirmed?: boolean + created_at?: string domain?: string identity?: string } diff --git a/supabase/migrations/20250122215946_add_created_at_to_domain_tables.sql b/supabase/migrations/20250122215946_add_created_at_to_domain_tables.sql new file mode 100644 index 00000000..f3a68cf9 --- /dev/null +++ b/supabase/migrations/20250122215946_add_created_at_to_domain_tables.sql @@ -0,0 +1,3 @@ +alter table "public"."custom_domain_routes" add column "created_at" timestamp with time zone not null default now(); + +alter table "public"."custom_domains" add column "created_at" timestamp with time zone not null default now(); -- 2.51.2