From 6d0e195a4d3af51d9a0b280ae4a20a0493cdb35e Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 15 Feb 2025 20:26:05 -0600 Subject: [PATCH] refactor: update --- packages/server/auth-schema.ts | 146 ++++++++++-------- packages/server/src/db/schema/certificate.ts | 2 +- packages/server/src/db/schema/destination.ts | 2 +- packages/server/src/db/schema/git-provider.ts | 2 +- packages/server/src/db/schema/notification.ts | 2 +- packages/server/src/db/schema/project.ts | 2 +- packages/server/src/db/schema/registry.ts | 2 +- packages/server/src/db/schema/server.ts | 2 +- packages/server/src/db/schema/ssh-key.ts | 2 +- packages/server/src/db/schema/user.ts | 2 +- 10 files changed, 91 insertions(+), 73 deletions(-) diff --git a/packages/server/auth-schema.ts b/packages/server/auth-schema.ts index 20b0a2b6..38839afb 100644 --- a/packages/server/auth-schema.ts +++ b/packages/server/auth-schema.ts @@ -1,77 +1,95 @@ -import { pgTable, text, integer, timestamp, boolean } from "drizzle-orm/pg-core"; - +import { + boolean, + integer, + pgTable, + text, + timestamp, +} from "drizzle-orm/pg-core"; + export const users_temp = pgTable("users_temp", { - id: text("id").primaryKey(), - name: text('name').notNull(), - email: text('email').notNull().unique(), - emailVerified: boolean('email_verified').notNull(), - image: text('image'), - createdAt: timestamp('created_at').notNull(), - updatedAt: timestamp('updated_at').notNull(), - role: text('role').notNull(), - ownerId: text('owner_id').notNull() - }); + id: text("id").primaryKey(), + name: text("name").notNull(), + email: text("email").notNull().unique(), + emailVerified: boolean("email_verified").notNull(), + image: text("image"), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), + role: text("role").notNull(), + ownerId: text("owner_id").notNull(), +}); export const session = pgTable("session", { - id: text("id").primaryKey(), - expiresAt: timestamp('expires_at').notNull(), - token: text('token').notNull().unique(), - createdAt: timestamp('created_at').notNull(), - updatedAt: timestamp('updated_at').notNull(), - ipAddress: text('ip_address'), - userAgent: text('user_agent'), - userId: text('user_id').notNull().references(()=> users_temp.id, { onDelete: 'cascade' }), - activeOrganizationId: text('active_organization_id') - }); + id: text("id").primaryKey(), + expiresAt: timestamp("expires_at").notNull(), + token: text("token").notNull().unique(), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), + ipAddress: text("ip_address"), + userAgent: text("user_agent"), + userId: text("user_id") + .notNull() + .references(() => users_temp.id, { onDelete: "cascade" }), + activeOrganizationId: text("active_organization_id"), +}); export const account = pgTable("account", { - id: text("id").primaryKey(), - accountId: text('account_id').notNull(), - providerId: text('provider_id').notNull(), - userId: text('user_id').notNull().references(()=> users_temp.id, { onDelete: 'cascade' }), - accessToken: text('access_token'), - refreshToken: text('refresh_token'), - idToken: text('id_token'), - accessTokenExpiresAt: timestamp('access_token_expires_at'), - refreshTokenExpiresAt: timestamp('refresh_token_expires_at'), - scope: text('scope'), - password: text('password'), - createdAt: timestamp('created_at').notNull(), - updatedAt: timestamp('updated_at').notNull() - }); + id: text("id").primaryKey(), + accountId: text("account_id").notNull(), + providerId: text("provider_id").notNull(), + userId: text("user_id") + .notNull() + .references(() => users_temp.id, { onDelete: "cascade" }), + accessToken: text("access_token"), + refreshToken: text("refresh_token"), + idToken: text("id_token"), + accessTokenExpiresAt: timestamp("access_token_expires_at"), + refreshTokenExpiresAt: timestamp("refresh_token_expires_at"), + scope: text("scope"), + password: text("password"), + createdAt: timestamp("created_at").notNull(), + updatedAt: timestamp("updated_at").notNull(), +}); export const verification = pgTable("verification", { - id: text("id").primaryKey(), - identifier: text('identifier').notNull(), - value: text('value').notNull(), - expiresAt: timestamp('expires_at').notNull(), - createdAt: timestamp('created_at'), - updatedAt: timestamp('updated_at') - }); + id: text("id").primaryKey(), + identifier: text("identifier").notNull(), + value: text("value").notNull(), + expiresAt: timestamp("expires_at").notNull(), + createdAt: timestamp("created_at"), + updatedAt: timestamp("updated_at"), +}); export const organization = pgTable("organization", { - id: text("id").primaryKey(), - name: text('name').notNull(), - slug: text('slug').unique(), - logo: text('logo'), - createdAt: timestamp('created_at').notNull(), - metadata: text('metadata') - }); + id: text("id").primaryKey(), + name: text("name").notNull(), + slug: text("slug").unique(), + logo: text("logo"), + createdAt: timestamp("created_at").notNull(), + metadata: text("metadata"), +}); export const member = pgTable("member", { - id: text("id").primaryKey(), - organizationId: text('organization_id').notNull().references(()=> organization.id, { onDelete: 'cascade' }), - userId: text('user_id').notNull().references(()=> user.id, { onDelete: 'cascade' }), - role: text('role').notNull(), - createdAt: timestamp('created_at').notNull() - }); + id: text("id").primaryKey(), + organizationId: text("organization_id") + .notNull() + .references(() => organization.id, { onDelete: "cascade" }), + userId: text("user_id") + .notNull() + .references(() => user.id, { onDelete: "cascade" }), + role: text("role").notNull(), + createdAt: timestamp("created_at").notNull(), +}); export const invitation = pgTable("invitation", { - id: text("id").primaryKey(), - organizationId: text('organization_id').notNull().references(()=> organization.id, { onDelete: 'cascade' }), - email: text('email').notNull(), - role: text('role'), - status: text('status').notNull(), - expiresAt: timestamp('expires_at').notNull(), - inviterId: text('inviter_id').notNull().references(()=> user.id, { onDelete: 'cascade' }) - }); + id: text("id").primaryKey(), + organizationId: text("organization_id") + .notNull() + .references(() => organization.id, { onDelete: "cascade" }), + email: text("email").notNull(), + role: text("role"), + status: text("status").notNull(), + expiresAt: timestamp("expires_at").notNull(), + inviterId: text("inviter_id") + .notNull() + .references(() => user.id, { onDelete: "cascade" }), +}); diff --git a/packages/server/src/db/schema/certificate.ts b/packages/server/src/db/schema/certificate.ts index c78ee998..dd121b50 100644 --- a/packages/server/src/db/schema/certificate.ts +++ b/packages/server/src/db/schema/certificate.ts @@ -3,12 +3,12 @@ import { boolean, pgTable, text } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { z } from "zod"; +import { organization } from "./account"; import { admins } from "./admin"; import { server } from "./server"; import { users_temp } from "./user"; // import { user } from "./user"; import { generateAppName } from "./utils"; -import { organization } from "./account"; export const certificates = pgTable("certificate", { certificateId: text("certificateId") diff --git a/packages/server/src/db/schema/destination.ts b/packages/server/src/db/schema/destination.ts index b438d20b..4d8dbc13 100644 --- a/packages/server/src/db/schema/destination.ts +++ b/packages/server/src/db/schema/destination.ts @@ -3,10 +3,10 @@ import { pgTable, text } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { z } from "zod"; +import { organization } from "./account"; import { admins } from "./admin"; import { backups } from "./backups"; import { users_temp } from "./user"; -import { organization } from "./account"; // import { user } from "./user"; export const destinations = pgTable("destination", { diff --git a/packages/server/src/db/schema/git-provider.ts b/packages/server/src/db/schema/git-provider.ts index 40c4558a..e4255714 100644 --- a/packages/server/src/db/schema/git-provider.ts +++ b/packages/server/src/db/schema/git-provider.ts @@ -3,12 +3,12 @@ import { pgEnum, pgTable, text } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { z } from "zod"; +import { organization } from "./account"; import { admins } from "./admin"; import { bitbucket } from "./bitbucket"; import { github } from "./github"; import { gitlab } from "./gitlab"; import { users_temp } from "./user"; -import { organization } from "./account"; // import { user } from "./user"; export const gitProviderType = pgEnum("gitProviderType", [ diff --git a/packages/server/src/db/schema/notification.ts b/packages/server/src/db/schema/notification.ts index 5d2bb243..6e29ddf6 100644 --- a/packages/server/src/db/schema/notification.ts +++ b/packages/server/src/db/schema/notification.ts @@ -3,8 +3,8 @@ import { boolean, integer, pgEnum, pgTable, text } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { z } from "zod"; -import { users_temp } from "./user"; import { organization } from "./account"; +import { users_temp } from "./user"; // import { user } from "./user"; export const notificationType = pgEnum("notificationType", [ diff --git a/packages/server/src/db/schema/project.ts b/packages/server/src/db/schema/project.ts index 193fce47..cf4ea8a8 100644 --- a/packages/server/src/db/schema/project.ts +++ b/packages/server/src/db/schema/project.ts @@ -4,6 +4,7 @@ import { pgTable, text } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { z } from "zod"; +import { organization } from "./account"; import { admins } from "./admin"; // import { admins } from "./admin"; import { applications } from "./application"; @@ -14,7 +15,6 @@ import { mysql } from "./mysql"; import { postgres } from "./postgres"; import { redis } from "./redis"; import { users, users_temp } from "./user"; -import { organization } from "./account"; export const projects = pgTable("project", { projectId: text("projectId") diff --git a/packages/server/src/db/schema/registry.ts b/packages/server/src/db/schema/registry.ts index 932b198f..aa362a05 100644 --- a/packages/server/src/db/schema/registry.ts +++ b/packages/server/src/db/schema/registry.ts @@ -3,10 +3,10 @@ import { pgEnum, pgTable, text } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { z } from "zod"; +import { organization } from "./account"; import { admins } from "./admin"; import { applications } from "./application"; import { users_temp } from "./user"; -import { organization } from "./account"; // import { user } from "./user"; /** * This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same diff --git a/packages/server/src/db/schema/server.ts b/packages/server/src/db/schema/server.ts index 971c6916..f1dcd100 100644 --- a/packages/server/src/db/schema/server.ts +++ b/packages/server/src/db/schema/server.ts @@ -11,6 +11,7 @@ import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { z } from "zod"; +import { organization } from "./account"; import { admins } from "./admin"; import { applications } from "./application"; import { certificates } from "./certificate"; @@ -25,7 +26,6 @@ import { sshKeys } from "./ssh-key"; import { users_temp } from "./user"; // import { user } from "./user"; import { generateAppName } from "./utils"; -import { organization } from "./account"; export const serverStatus = pgEnum("serverStatus", ["active", "inactive"]); diff --git a/packages/server/src/db/schema/ssh-key.ts b/packages/server/src/db/schema/ssh-key.ts index 0b012495..b705be36 100644 --- a/packages/server/src/db/schema/ssh-key.ts +++ b/packages/server/src/db/schema/ssh-key.ts @@ -3,12 +3,12 @@ import { pgTable, text } from "drizzle-orm/pg-core"; import { createInsertSchema } from "drizzle-zod"; import { nanoid } from "nanoid"; import { sshKeyCreate, sshKeyType } from "../validations"; +import { organization } from "./account"; import { admins } from "./admin"; import { applications } from "./application"; import { compose } from "./compose"; import { server } from "./server"; import { users_temp } from "./user"; -import { organization } from "./account"; // import { user } from "./user"; export const sshKeys = pgTable("ssh-key", { diff --git a/packages/server/src/db/schema/user.ts b/packages/server/src/db/schema/user.ts index 359cfbd4..e2755b8f 100644 --- a/packages/server/src/db/schema/user.ts +++ b/packages/server/src/db/schema/user.ts @@ -13,8 +13,8 @@ import { z } from "zod"; import { account, organization } from "./account"; import { admins } from "./admin"; import { auth } from "./auth"; -import { certificateType } from "./shared"; import { projects } from "./project"; +import { certificateType } from "./shared"; /** * This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same * database instance for multiple projects.