refactor: update organization

This commit is contained in:
Mauricio Siu
2025-02-15 20:25:58 -06:00
parent 87b12ff6e9
commit 53ce5e57fa
16 changed files with 5776 additions and 82 deletions

View File

@@ -1,2 +0,0 @@
ALTER TABLE "project" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "project" ADD CONSTRAINT "project_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;

View File

@@ -0,0 +1,16 @@
ALTER TABLE "project" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "destination" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "certificate" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "registry" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "notification" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "ssh-key" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "git_provider" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "server" ADD COLUMN "organizationId" text;--> statement-breakpoint
ALTER TABLE "project" ADD CONSTRAINT "project_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "destination" ADD CONSTRAINT "destination_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "certificate" ADD CONSTRAINT "certificate_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "registry" ADD CONSTRAINT "registry_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "notification" ADD CONSTRAINT "notification_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ssh-key" ADD CONSTRAINT "ssh-key_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "git_provider" ADD CONSTRAINT "git_provider_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "server" ADD CONSTRAINT "server_organizationId_organization_id_fk" FOREIGN KEY ("organizationId") REFERENCES "public"."organization"("id") ON DELETE cascade ON UPDATE no action;

View File

@@ -1,5 +1,6 @@
-- Custom SQL migration file, put your code below! --
-- Primero, actualizamos los proyectos con la organización del usuario
-- Custom SQL migration file
-- Actualizar projects
UPDATE "project" p
SET "organizationId" = (
SELECT m."organization_id"
@@ -10,18 +11,132 @@ SET "organizationId" = (
)
WHERE p."organizationId" IS NULL;
-- Verificamos que todos los proyectos tengan una organización
-- Actualizar servers
UPDATE "server" s
SET "organizationId" = (
SELECT m."organization_id"
FROM "member" m
WHERE m."user_id" = s."userId"
AND m."role" = 'owner'
LIMIT 1
)
WHERE s."organizationId" IS NULL;
-- Actualizar ssh-keys
UPDATE "ssh-key" k
SET "organizationId" = (
SELECT m."organization_id"
FROM "member" m
WHERE m."user_id" = k."userId"
AND m."role" = 'owner'
LIMIT 1
)
WHERE k."organizationId" IS NULL;
-- Actualizar destinations
UPDATE "destination" d
SET "organizationId" = (
SELECT m."organization_id"
FROM "member" m
WHERE m."user_id" = d."userId"
AND m."role" = 'owner'
LIMIT 1
)
WHERE d."organizationId" IS NULL;
-- Actualizar registry
UPDATE "registry" r
SET "organizationId" = (
SELECT m."organization_id"
FROM "member" m
WHERE m."user_id" = r."userId"
AND m."role" = 'owner'
LIMIT 1
)
WHERE r."organizationId" IS NULL;
-- Actualizar notifications
UPDATE "notification" n
SET "organizationId" = (
SELECT m."organization_id"
FROM "member" m
WHERE m."user_id" = n."userId"
AND m."role" = 'owner'
LIMIT 1
)
WHERE n."organizationId" IS NULL;
-- Actualizar certificates
UPDATE "certificate" c
SET "organizationId" = (
SELECT m."organization_id"
FROM "member" m
WHERE m."user_id" = c."userId"
AND m."role" = 'owner'
LIMIT 1
)
WHERE c."organizationId" IS NULL;
-- Actualizar git_provider
UPDATE "git_provider" g
SET "organizationId" = (
SELECT m."organization_id"
FROM "member" m
WHERE m."user_id" = g."userId"
AND m."role" = 'owner'
LIMIT 1
)
WHERE g."organizationId" IS NULL;
-- Verificar que todos los recursos tengan una organización
DO $$
BEGIN
IF EXISTS (
SELECT 1
FROM "project"
WHERE "organizationId" IS NULL
SELECT 1 FROM "project" WHERE "organizationId" IS NULL
UNION ALL
SELECT 1 FROM "server" WHERE "organizationId" IS NULL
UNION ALL
SELECT 1 FROM "ssh-key" WHERE "organizationId" IS NULL
UNION ALL
SELECT 1 FROM "destination" WHERE "organizationId" IS NULL
UNION ALL
SELECT 1 FROM "registry" WHERE "organizationId" IS NULL
UNION ALL
SELECT 1 FROM "notification" WHERE "organizationId" IS NULL
UNION ALL
SELECT 1 FROM "certificate" WHERE "organizationId" IS NULL
UNION ALL
SELECT 1 FROM "git_provider" WHERE "organizationId" IS NULL
) THEN
RAISE EXCEPTION 'Hay proyectos sin organización asignada';
RAISE EXCEPTION 'Hay recursos sin organización asignada';
END IF;
END $$;
-- Hacemos organization_id NOT NULL después de la migración
ALTER TABLE "project"
ALTER COLUMN "organizationId" SET NOT NULL;
-- Hacer organization_id NOT NULL en todas las tablas
ALTER TABLE "project" ALTER COLUMN "organizationId" SET NOT NULL;
ALTER TABLE "server" ALTER COLUMN "organizationId" SET NOT NULL;
ALTER TABLE "ssh-key" ALTER COLUMN "organizationId" SET NOT NULL;
ALTER TABLE "destination" ALTER COLUMN "organizationId" SET NOT NULL;
ALTER TABLE "registry" ALTER COLUMN "organizationId" SET NOT NULL;
ALTER TABLE "notification" ALTER COLUMN "organizationId" SET NOT NULL;
ALTER TABLE "certificate" ALTER COLUMN "organizationId" SET NOT NULL;
ALTER TABLE "git_provider" ALTER COLUMN "organizationId" SET NOT NULL;
-- Crear índices para mejorar el rendimiento de búsquedas por organización
CREATE INDEX IF NOT EXISTS "idx_project_organization" ON "project" ("organizationId");
CREATE INDEX IF NOT EXISTS "idx_server_organization" ON "server" ("organizationId");
CREATE INDEX IF NOT EXISTS "idx_sshkey_organization" ON "ssh-key" ("organizationId");
CREATE INDEX IF NOT EXISTS "idx_destination_organization" ON "destination" ("organizationId");
CREATE INDEX IF NOT EXISTS "idx_registry_organization" ON "registry" ("organizationId");
CREATE INDEX IF NOT EXISTS "idx_notification_organization" ON "notification" ("organizationId");
CREATE INDEX IF NOT EXISTS "idx_certificate_organization" ON "certificate" ("organizationId");
CREATE INDEX IF NOT EXISTS "idx_git_provider_organization" ON "git_provider" ("organizationId");

View File

@@ -0,0 +1,32 @@
ALTER TABLE "project" DROP CONSTRAINT "project_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "destination" DROP CONSTRAINT "destination_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "certificate" DROP CONSTRAINT "certificate_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "registry" DROP CONSTRAINT "registry_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "notification" DROP CONSTRAINT "notification_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "ssh-key" DROP CONSTRAINT "ssh-key_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "git_provider" DROP CONSTRAINT "git_provider_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "server" DROP CONSTRAINT "server_userId_user_temp_id_fk";
--> statement-breakpoint
ALTER TABLE "project" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "destination" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "certificate" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "registry" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "notification" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "ssh-key" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "git_provider" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "server" ALTER COLUMN "organizationId" SET NOT NULL;--> statement-breakpoint
ALTER TABLE "project" DROP COLUMN "userId";--> statement-breakpoint
ALTER TABLE "destination" DROP COLUMN "userId";--> statement-breakpoint
ALTER TABLE "certificate" DROP COLUMN "userId";--> statement-breakpoint
ALTER TABLE "registry" DROP COLUMN "userId";--> statement-breakpoint
ALTER TABLE "notification" DROP COLUMN "userId";--> statement-breakpoint
ALTER TABLE "ssh-key" DROP COLUMN "userId";--> statement-breakpoint
ALTER TABLE "git_provider" DROP COLUMN "userId";--> statement-breakpoint
ALTER TABLE "server" DROP COLUMN "userId";

View File

@@ -1,5 +1,5 @@
{
"id": "cd06dbbf-61cb-4aba-b096-49a1850ff32b",
"id": "8e8626de-fb34-4c11-b9d0-b7a958993fb7",
"prevId": "e0842a94-530d-4a3c-a6b1-16cf37618b8b",
"version": "7",
"dialect": "postgresql",
@@ -2352,6 +2352,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -2368,6 +2374,19 @@
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"destination_organizationId_organization_id_fk": {
"name": "destination_organizationId_organization_id_fk",
"tableFrom": "destination",
"tableTo": "organization",
"columnsFrom": [
"organizationId"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@@ -2761,6 +2780,12 @@
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"serverId": {
"name": "serverId",
"type": "text",
@@ -2783,6 +2808,19 @@
"onDelete": "cascade",
"onUpdate": "no action"
},
"certificate_organizationId_organization_id_fk": {
"name": "certificate_organizationId_organization_id_fk",
"tableFrom": "certificate",
"tableTo": "organization",
"columnsFrom": [
"organizationId"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"certificate_serverId_server_serverId_fk": {
"name": "certificate_serverId_server_serverId_fk",
"tableFrom": "certificate",
@@ -3677,6 +3715,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -3693,6 +3737,19 @@
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"registry_organizationId_organization_id_fk": {
"name": "registry_organizationId_organization_id_fk",
"tableFrom": "registry",
"tableTo": "organization",
"columnsFrom": [
"organizationId"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@@ -3937,6 +3994,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -4018,6 +4081,19 @@
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"notification_organizationId_organization_id_fk": {
"name": "notification_organizationId_organization_id_fk",
"tableFrom": "notification",
"tableTo": "organization",
"columnsFrom": [
"organizationId"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@@ -4140,6 +4216,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -4156,6 +4238,19 @@
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"ssh-key_organizationId_organization_id_fk": {
"name": "ssh-key_organizationId_organization_id_fk",
"tableFrom": "ssh-key",
"tableTo": "organization",
"columnsFrom": [
"organizationId"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@@ -4199,6 +4294,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -4215,6 +4316,19 @@
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"git_provider_organizationId_organization_id_fk": {
"name": "git_provider_organizationId_organization_id_fk",
"tableFrom": "git_provider",
"tableTo": "organization",
"columnsFrom": [
"organizationId"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
@@ -4515,6 +4629,12 @@
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"serverStatus": {
"name": "serverStatus",
"type": "serverStatus",
@@ -4559,6 +4679,19 @@
"onDelete": "cascade",
"onUpdate": "no action"
},
"server_organizationId_organization_id_fk": {
"name": "server_organizationId_organization_id_fk",
"tableFrom": "server",
"tableTo": "organization",
"columnsFrom": [
"organizationId"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"server_sshKeyId_ssh-key_sshKeyId_fk": {
"name": "server_sshKeyId_ssh-key_sshKeyId_fk",
"tableFrom": "server",

View File

@@ -1,6 +1,6 @@
{
"id": "30a4b462-2f38-42ae-8291-f6a2ce6d0bb4",
"prevId": "cd06dbbf-61cb-4aba-b096-49a1850ff32b",
"id": "11cb27c0-0f5a-4ec9-98be-5b6f7c5e7799",
"prevId": "8e8626de-fb34-4c11-b9d0-b7a958993fb7",
"version": "7",
"dialect": "postgresql",
"tables": {
@@ -2352,6 +2352,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -2368,6 +2374,19 @@
],
"onUpdate": "no action",
"onDelete": "cascade"
},
"destination_organizationId_organization_id_fk": {
"name": "destination_organizationId_organization_id_fk",
"tableFrom": "destination",
"columnsFrom": [
"organizationId"
],
"tableTo": "organization",
"columnsTo": [
"id"
],
"onUpdate": "no action",
"onDelete": "cascade"
}
},
"compositePrimaryKeys": {},
@@ -2761,6 +2780,12 @@
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"serverId": {
"name": "serverId",
"type": "text",
@@ -2783,6 +2808,19 @@
"onUpdate": "no action",
"onDelete": "cascade"
},
"certificate_organizationId_organization_id_fk": {
"name": "certificate_organizationId_organization_id_fk",
"tableFrom": "certificate",
"columnsFrom": [
"organizationId"
],
"tableTo": "organization",
"columnsTo": [
"id"
],
"onUpdate": "no action",
"onDelete": "cascade"
},
"certificate_serverId_server_serverId_fk": {
"name": "certificate_serverId_server_serverId_fk",
"tableFrom": "certificate",
@@ -3677,6 +3715,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -3693,6 +3737,19 @@
],
"onUpdate": "no action",
"onDelete": "cascade"
},
"registry_organizationId_organization_id_fk": {
"name": "registry_organizationId_organization_id_fk",
"tableFrom": "registry",
"columnsFrom": [
"organizationId"
],
"tableTo": "organization",
"columnsTo": [
"id"
],
"onUpdate": "no action",
"onDelete": "cascade"
}
},
"compositePrimaryKeys": {},
@@ -3937,6 +3994,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -4018,6 +4081,19 @@
],
"onUpdate": "no action",
"onDelete": "cascade"
},
"notification_organizationId_organization_id_fk": {
"name": "notification_organizationId_organization_id_fk",
"tableFrom": "notification",
"columnsFrom": [
"organizationId"
],
"tableTo": "organization",
"columnsTo": [
"id"
],
"onUpdate": "no action",
"onDelete": "cascade"
}
},
"compositePrimaryKeys": {},
@@ -4140,6 +4216,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -4156,6 +4238,19 @@
],
"onUpdate": "no action",
"onDelete": "cascade"
},
"ssh-key_organizationId_organization_id_fk": {
"name": "ssh-key_organizationId_organization_id_fk",
"tableFrom": "ssh-key",
"columnsFrom": [
"organizationId"
],
"tableTo": "organization",
"columnsTo": [
"id"
],
"onUpdate": "no action",
"onDelete": "cascade"
}
},
"compositePrimaryKeys": {},
@@ -4199,6 +4294,12 @@
"type": "text",
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
}
},
"indexes": {},
@@ -4215,6 +4316,19 @@
],
"onUpdate": "no action",
"onDelete": "cascade"
},
"git_provider_organizationId_organization_id_fk": {
"name": "git_provider_organizationId_organization_id_fk",
"tableFrom": "git_provider",
"columnsFrom": [
"organizationId"
],
"tableTo": "organization",
"columnsTo": [
"id"
],
"onUpdate": "no action",
"onDelete": "cascade"
}
},
"compositePrimaryKeys": {},
@@ -4515,6 +4629,12 @@
"primaryKey": false,
"notNull": true
},
"organizationId": {
"name": "organizationId",
"type": "text",
"primaryKey": false,
"notNull": false
},
"serverStatus": {
"name": "serverStatus",
"type": "serverStatus",
@@ -4559,6 +4679,19 @@
"onUpdate": "no action",
"onDelete": "cascade"
},
"server_organizationId_organization_id_fk": {
"name": "server_organizationId_organization_id_fk",
"tableFrom": "server",
"columnsFrom": [
"organizationId"
],
"tableTo": "organization",
"columnsTo": [
"id"
],
"onUpdate": "no action",
"onDelete": "cascade"
},
"server_sshKeyId_ssh-key_sshKeyId_fk": {
"name": "server_sshKeyId_ssh-key_sshKeyId_fk",
"tableFrom": "server",

File diff suppressed because it is too large Load Diff

View File

@@ -495,16 +495,23 @@
{
"idx": 70,
"version": "7",
"when": 1739671371444,
"tag": "0070_dusty_wind_dancer",
"when": 1739671869809,
"tag": "0070_nervous_vivisector",
"breakpoints": true
},
{
"idx": 71,
"version": "7",
"when": 1739671387634,
"when": 1739671878698,
"tag": "0071_migrate-data-projects",
"breakpoints": true
},
{
"idx": 72,
"version": "7",
"when": 1739672367223,
"tag": "0072_lazy_pixie",
"breakpoints": true
}
]
}

View File

@@ -8,6 +8,7 @@ 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")
@@ -22,12 +23,9 @@ export const certificates = pgTable("certificate", {
.$defaultFn(() => generateAppName("certificate"))
.unique(),
autoRenew: boolean("autoRenew"),
// userId: text("userId").references(() => user.userId, {
// onDelete: "cascade",
// }),
userId: text("userId")
organizationId: text("organizationId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
.references(() => organization.id, { onDelete: "cascade" }),
serverId: text("serverId").references(() => server.serverId, {
onDelete: "cascade",
}),
@@ -40,9 +38,9 @@ export const certificatesRelations = relations(
fields: [certificates.serverId],
references: [server.serverId],
}),
user: one(users_temp, {
fields: [certificates.userId],
references: [users_temp.id],
organization: one(organization, {
fields: [certificates.organizationId],
references: [organization.id],
}),
}),
);

View File

@@ -6,6 +6,7 @@ import { z } from "zod";
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", {
@@ -21,18 +22,19 @@ export const destinations = pgTable("destination", {
region: text("region").notNull(),
// maybe it can be null
endpoint: text("endpoint").notNull(),
// userId: text("userId")
// .notNull()
// .references(() => user.userId, { onDelete: "cascade" }),
userId: text("userId")
organizationId: text("organizationId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
.references(() => organization.id, { onDelete: "cascade" }),
});
export const destinationsRelations = relations(
destinations,
({ many, one }) => ({
backups: many(backups),
organization: one(organization, {
fields: [destinations.organizationId],
references: [organization.id],
}),
// user: one(user, {
// fields: [destinations.userId],
// references: [user.id],

View File

@@ -8,6 +8,7 @@ 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", [
@@ -26,12 +27,9 @@ export const gitProvider = pgTable("git_provider", {
createdAt: text("createdAt")
.notNull()
.$defaultFn(() => new Date().toISOString()),
// userId: text("userId").references(() => user.userId, {
// onDelete: "cascade",
// }),
userId: text("userId")
organizationId: text("organizationId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
.references(() => organization.id, { onDelete: "cascade" }),
});
export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
@@ -47,9 +45,9 @@ export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
fields: [gitProvider.gitProviderId],
references: [bitbucket.gitProviderId],
}),
user: one(users_temp, {
fields: [gitProvider.userId],
references: [users_temp.id],
organization: one(organization, {
fields: [gitProvider.organizationId],
references: [organization.id],
}),
}));

View File

@@ -4,6 +4,7 @@ import { createInsertSchema } from "drizzle-zod";
import { nanoid } from "nanoid";
import { z } from "zod";
import { users_temp } from "./user";
import { organization } from "./account";
// import { user } from "./user";
export const notificationType = pgEnum("notificationType", [
@@ -45,12 +46,9 @@ export const notifications = pgTable("notification", {
gotifyId: text("gotifyId").references(() => gotify.gotifyId, {
onDelete: "cascade",
}),
// userId: text("userId").references(() => user.userId, {
// onDelete: "cascade",
// }),
userId: text("userId")
organizationId: text("organizationId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
.references(() => organization.id, { onDelete: "cascade" }),
});
export const slack = pgTable("slack", {
@@ -125,9 +123,9 @@ export const notificationsRelations = relations(notifications, ({ one }) => ({
fields: [notifications.gotifyId],
references: [gotify.gotifyId],
}),
user: one(users_temp, {
fields: [notifications.userId],
references: [users_temp.id],
organization: one(organization, {
fields: [notifications.organizationId],
references: [organization.id],
}),
}));

View File

@@ -26,14 +26,9 @@ export const projects = pgTable("project", {
createdAt: text("createdAt")
.notNull()
.$defaultFn(() => new Date().toISOString()),
// userId: text("userId")
// .notNull()
// .references(() => user.userId, { onDelete: "cascade" }),
userId: text("userId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
organizationId: text("organizationId")
// .notNull()
.notNull()
.references(() => organization.id, { onDelete: "cascade" }),
env: text("env").notNull().default(""),
});
@@ -46,14 +41,10 @@ export const projectRelations = relations(projects, ({ many, one }) => ({
mongo: many(mongo),
redis: many(redis),
compose: many(compose),
user: one(users_temp, {
fields: [projects.userId],
references: [users_temp.id],
organization: one(organization, {
fields: [projects.organizationId],
references: [organization.id],
}),
// user: one(user, {
// fields: [projects.userId],
// references: [user.id],
// }),
}));
const createSchema = createInsertSchema(projects, {

View File

@@ -6,6 +6,7 @@ import { z } from "zod";
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
@@ -29,12 +30,9 @@ export const registry = pgTable("registry", {
.notNull()
.$defaultFn(() => new Date().toISOString()),
registryType: registryType("selfHosted").notNull().default("cloud"),
// userId: text("userId")
// .notNull()
// .references(() => user.userId, { onDelete: "cascade" }),
userId: text("userId")
organizationId: text("organizationId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
.references(() => organization.id, { onDelete: "cascade" }),
});
export const registryRelations = relations(registry, ({ one, many }) => ({
@@ -50,7 +48,7 @@ const createSchema = createInsertSchema(registry, {
username: z.string().min(1),
password: z.string().min(1),
registryUrl: z.string(),
userId: z.string().min(1),
organizationId: z.string().min(1),
registryId: z.string().min(1),
registryType: z.enum(["cloud"]),
imagePrefix: z.string().nullable().optional(),

View File

@@ -25,6 +25,7 @@ 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"]);
@@ -43,13 +44,9 @@ export const server = pgTable("server", {
.$defaultFn(() => generateAppName("server")),
enableDockerCleanup: boolean("enableDockerCleanup").notNull().default(false),
createdAt: text("createdAt").notNull(),
// .$defaultFn(() => new Date().toISOString()),
// userId: text("userId")
// .notNull()
// .references(() => user.userId, { onDelete: "cascade" }),
userId: text("userId")
organizationId: text("organizationId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
.references(() => organization.id, { onDelete: "cascade" }),
serverStatus: serverStatus("serverStatus").notNull().default("active"),
command: text("command").notNull().default(""),
sshKeyId: text("sshKeyId").references(() => sshKeys.sshKeyId, {

View File

@@ -8,6 +8,7 @@ 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", {
@@ -23,21 +24,18 @@ export const sshKeys = pgTable("ssh-key", {
.notNull()
.$defaultFn(() => new Date().toISOString()),
lastUsedAt: text("lastUsedAt"),
// userId: text("userId").references(() => user.userId, {
// onDelete: "cascade",
// }),
userId: text("userId")
organizationId: text("organizationId")
.notNull()
.references(() => users_temp.id, { onDelete: "cascade" }),
.references(() => organization.id, { onDelete: "cascade" }),
});
export const sshKeysRelations = relations(sshKeys, ({ many, one }) => ({
applications: many(applications),
compose: many(compose),
servers: many(server),
user: one(users_temp, {
fields: [sshKeys.userId],
references: [users_temp.id],
organization: one(organization, {
fields: [sshKeys.organizationId],
references: [organization.id],
}),
}));
@@ -53,7 +51,7 @@ export const apiCreateSshKey = createSchema
description: true,
privateKey: true,
publicKey: true,
userId: true,
organizationId: true,
})
.merge(sshKeyCreate.pick({ privateKey: true }));