From 397684e2e1f11eca2abdcc6c86115aeff560d64a Mon Sep 17 00:00:00 2001 From: Ihsen Bouallegue Date: Tue, 14 Nov 2023 22:08:37 +0100 Subject: [PATCH] Fix database URI in drizzle.config.ts and add createdAt field to organizations table --- drizzle.config.ts | 28 ++++++++++++++-------------- src/lib/schema/app.ts | 16 ++++++++-------- src/lib/schema/auth.ts | 2 +- src/lib/schema/orgaizations.ts | 4 +++- src/lib/validations/organization.ts | 1 + 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/drizzle.config.ts b/drizzle.config.ts index adf1aa8d..2f82079f 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -1,14 +1,14 @@ -import * as dotenv from "dotenv"; -import type { Config } from "drizzle-kit"; - -dotenv.config(); - -export default { - schema: "./src/lib/schema/*", - out: "./drizzle", - driver: "mysql2", - verbose: true, - dbCredentials: { - connectionString: `${process.env.DATABASE_URL}`, - }, -} satisfies Config; +import * as dotenv from "dotenv"; +import type { Config } from "drizzle-kit"; + +dotenv.config(); + +export default { + schema: "./src/lib/schema/*", + out: "./drizzle", + driver: "mysql2", + verbose: true, + dbCredentials: { + uri: `${process.env.DATABASE_URL}`, + }, +} satisfies Config; diff --git a/src/lib/schema/app.ts b/src/lib/schema/app.ts index 6de4887c..cb816c3f 100644 --- a/src/lib/schema/app.ts +++ b/src/lib/schema/app.ts @@ -19,8 +19,8 @@ export const hubSpaces = mysqlTable( "hubspaces", { id: varchar("id", { length: 256 }) - .$defaultFn(() => HUBSPACE_KEY) - .primaryKey(), + .primaryKey() + .$defaultFn(() => HUBSPACE_KEY), name: varchar("name", { length: 256 }).notNull(), domain: varchar("domain", { length: 256 }).notNull(), ownerId: varchar("owner_id", { length: 256 }).notNull(), @@ -36,10 +36,10 @@ export const hubs = mysqlTable( "hubs", { id: varchar("id", { length: 256 }) - .$defaultFn(() => HUB_KEY) - .primaryKey(), + .primaryKey() + .$defaultFn(() => HUB_KEY), name: varchar("name", { length: 256 }).notNull(), - logo: varchar("logo", { length: 256 }).default("").notNull(), + logo: varchar("logo", { length: 1024 }).default("").notNull(), slug: varchar("slug", { length: 256 }).default("/").notNull(), primaryColor: varchar("primary_color", { length: 256 }) .default("#ff008c") @@ -62,12 +62,12 @@ export const hubs = mysqlTable( export const links = mysqlTable("links", { id: varchar("id", { length: 256 }) - .$defaultFn(() => LINK_KEY) .primaryKey() + .$defaultFn(() => LINK_KEY) .notNull(), title: varchar("title", { length: 256 }).notNull(), description: text("description").notNull(), - image: varchar("image", { length: 256 }).default("").notNull(), + image: varchar("image", { length: 1024 }).default("").notNull(), url: varchar("url", { length: 256 }).notNull(), createdAt: timestamp("created_at").defaultNow(), linkGroupId: varchar("link_group_id", { length: 256 }).notNull(), @@ -76,8 +76,8 @@ export const links = mysqlTable("links", { export const footerLinks = mysqlTable("footer_links", { id: varchar("id", { length: 256 }) - .$defaultFn(() => FOOTERLINK_KEY) .primaryKey() + .$defaultFn(() => FOOTERLINK_KEY) .notNull(), title: varchar("title", { length: 256 }).notNull(), url: varchar("url", { length: 256 }).notNull(), diff --git a/src/lib/schema/auth.ts b/src/lib/schema/auth.ts index 764dba48..b71318d1 100644 --- a/src/lib/schema/auth.ts +++ b/src/lib/schema/auth.ts @@ -77,7 +77,7 @@ export const verificationTokens = mysqlTable( expires: timestamp("expires", { mode: "date" }).notNull(), }, (vt) => ({ - compoundKey: primaryKey(vt.identifier, vt.token), + compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }), }) ); diff --git a/src/lib/schema/orgaizations.ts b/src/lib/schema/orgaizations.ts index 9dddad2a..afff4b99 100644 --- a/src/lib/schema/orgaizations.ts +++ b/src/lib/schema/orgaizations.ts @@ -3,6 +3,7 @@ import { boolean, mysqlTable, primaryKey, + timestamp, uniqueIndex, varchar, } from "drizzle-orm/mysql-core"; @@ -22,6 +23,7 @@ export const organizations = mysqlTable( name: varchar("name", { length: 255 }).notNull(), slug: varchar("slug", { length: 255 }).notNull(), admin: varchar("admin", { length: 128 }).notNull(), + createdAt: timestamp("created_at").defaultNow(), isPersonalOrganization: boolean("is_personal_organization") .default(false) .notNull(), @@ -49,7 +51,7 @@ export const usersToOrganizations = mysqlTable( organizationId: varchar("organization_id", { length: 128 }).notNull(), }, (t) => ({ - pk: primaryKey(t.userId, t.organizationId), + pk: primaryKey({ columns: [t.userId, t.organizationId] }), }) ); diff --git a/src/lib/validations/organization.ts b/src/lib/validations/organization.ts index 7da0ea47..d111a27e 100644 --- a/src/lib/validations/organization.ts +++ b/src/lib/validations/organization.ts @@ -18,4 +18,5 @@ export const organizationSchema = insertOrganizationSchema.omit({ id: true }); export const organizationSchemaWithoutAdmin = insertOrganizationSchema.omit({ id: true, admin: true, + createdAt: true, });