feat: migrate rest schemas

This commit is contained in:
Mauricio Siu 2025-02-13 00:45:29 -06:00
parent 7c62408070
commit 0d525398a8
12 changed files with 5348 additions and 30 deletions

View File

@ -0,0 +1,32 @@
ALTER TABLE "project" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "destination" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "certificate" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "registry" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "notification" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "ssh-key" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "git_provider" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "server" RENAME COLUMN "adminId" TO "userId";--> statement-breakpoint
ALTER TABLE "project" DROP CONSTRAINT "project_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "destination" DROP CONSTRAINT "destination_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "certificate" DROP CONSTRAINT "certificate_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "registry" DROP CONSTRAINT "registry_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "notification" DROP CONSTRAINT "notification_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "ssh-key" DROP CONSTRAINT "ssh-key_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "git_provider" DROP CONSTRAINT "git_provider_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "server" DROP CONSTRAINT "server_adminId_admin_adminId_fk";
--> statement-breakpoint
ALTER TABLE "project" ADD CONSTRAINT "project_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "destination" ADD CONSTRAINT "destination_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "certificate" ADD CONSTRAINT "certificate_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "registry" ADD CONSTRAINT "registry_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "notification" ADD CONSTRAINT "notification_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "ssh-key" ADD CONSTRAINT "ssh-key_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "git_provider" ADD CONSTRAINT "git_provider_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "server" ADD CONSTRAINT "server_userId_user_temp_id_fk" FOREIGN KEY ("userId") REFERENCES "public"."user_temp"("id") ON DELETE cascade ON UPDATE no action;

File diff suppressed because it is too large Load Diff

View File

@ -477,6 +477,13 @@
"when": 1739427057545, "when": 1739427057545,
"tag": "0067_migrate-data", "tag": "0067_migrate-data",
"breakpoints": true "breakpoints": true
},
{
"idx": 68,
"version": "7",
"when": 1739428942964,
"tag": "0068_sour_professor_monster",
"breakpoints": true
} }
] ]
} }

View File

@ -25,9 +25,9 @@ export const certificates = pgTable("certificate", {
// userId: text("userId").references(() => user.userId, { // userId: text("userId").references(() => user.userId, {
// onDelete: "cascade", // onDelete: "cascade",
// }), // }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
serverId: text("serverId").references(() => server.serverId, { serverId: text("serverId").references(() => server.serverId, {
onDelete: "cascade", onDelete: "cascade",
}), }),
@ -40,9 +40,9 @@ export const certificatesRelations = relations(
fields: [certificates.serverId], fields: [certificates.serverId],
references: [server.serverId], references: [server.serverId],
}), }),
admin: one(admins, { user: one(users_temp, {
fields: [certificates.adminId], fields: [certificates.userId],
references: [admins.adminId], references: [users_temp.id],
}), }),
}), }),
); );

View File

@ -24,9 +24,9 @@ export const destinations = pgTable("destination", {
// userId: text("userId") // userId: text("userId")
// .notNull() // .notNull()
// .references(() => user.userId, { onDelete: "cascade" }), // .references(() => user.userId, { onDelete: "cascade" }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
}); });
export const destinationsRelations = relations( export const destinationsRelations = relations(

View File

@ -29,9 +29,9 @@ export const gitProvider = pgTable("git_provider", {
// userId: text("userId").references(() => user.userId, { // userId: text("userId").references(() => user.userId, {
// onDelete: "cascade", // onDelete: "cascade",
// }), // }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
}); });
export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({ export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({

View File

@ -49,9 +49,9 @@ export const notifications = pgTable("notification", {
// userId: text("userId").references(() => user.userId, { // userId: text("userId").references(() => user.userId, {
// onDelete: "cascade", // onDelete: "cascade",
// }), // }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
}); });
export const slack = pgTable("slack", { export const slack = pgTable("slack", {
@ -126,9 +126,9 @@ export const notificationsRelations = relations(notifications, ({ one }) => ({
fields: [notifications.gotifyId], fields: [notifications.gotifyId],
references: [gotify.gotifyId], references: [gotify.gotifyId],
}), }),
admin: one(admins, { user: one(users_temp, {
fields: [notifications.adminId], fields: [notifications.userId],
references: [admins.adminId], references: [users_temp.id],
}), }),
})); }));

View File

@ -28,9 +28,9 @@ export const projects = pgTable("project", {
// userId: text("userId") // userId: text("userId")
// .notNull() // .notNull()
// .references(() => user.userId, { onDelete: "cascade" }), // .references(() => user.userId, { onDelete: "cascade" }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
env: text("env").notNull().default(""), env: text("env").notNull().default(""),
}); });

View File

@ -32,9 +32,9 @@ export const registry = pgTable("registry", {
// userId: text("userId") // userId: text("userId")
// .notNull() // .notNull()
// .references(() => user.userId, { onDelete: "cascade" }), // .references(() => user.userId, { onDelete: "cascade" }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
}); });
export const registryRelations = relations(registry, ({ one, many }) => ({ export const registryRelations = relations(registry, ({ one, many }) => ({

View File

@ -47,9 +47,9 @@ export const server = pgTable("server", {
// userId: text("userId") // userId: text("userId")
// .notNull() // .notNull()
// .references(() => user.userId, { onDelete: "cascade" }), // .references(() => user.userId, { onDelete: "cascade" }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
serverStatus: serverStatus("serverStatus").notNull().default("active"), serverStatus: serverStatus("serverStatus").notNull().default("active"),
command: text("command").notNull().default(""), command: text("command").notNull().default(""),
sshKeyId: text("sshKeyId").references(() => sshKeys.sshKeyId, { sshKeyId: text("sshKeyId").references(() => sshKeys.sshKeyId, {

View File

@ -7,6 +7,7 @@ import { admins } from "./admin";
import { applications } from "./application"; import { applications } from "./application";
import { compose } from "./compose"; import { compose } from "./compose";
import { server } from "./server"; import { server } from "./server";
import { users_temp } from "./user";
// import { user } from "./user"; // import { user } from "./user";
export const sshKeys = pgTable("ssh-key", { export const sshKeys = pgTable("ssh-key", {
@ -25,19 +26,19 @@ export const sshKeys = pgTable("ssh-key", {
// userId: text("userId").references(() => user.userId, { // userId: text("userId").references(() => user.userId, {
// onDelete: "cascade", // onDelete: "cascade",
// }), // }),
adminId: text("adminId") userId: text("userId")
.notNull() .notNull()
.references(() => admins.adminId, { onDelete: "cascade" }), .references(() => users_temp.id, { onDelete: "cascade" }),
}); });
export const sshKeysRelations = relations(sshKeys, ({ many, one }) => ({ export const sshKeysRelations = relations(sshKeys, ({ many, one }) => ({
applications: many(applications), applications: many(applications),
compose: many(compose), compose: many(compose),
servers: many(server), servers: many(server),
// user: one(user, { user: one(users_temp, {
// fields: [sshKeys.userId], fields: [sshKeys.userId],
// references: [user.id], references: [users_temp.id],
// }), }),
})); }));
const createSchema = createInsertSchema( const createSchema = createInsertSchema(

View File

@ -189,10 +189,10 @@ export const usersRelations = relations(users, ({ one }) => ({
fields: [users.authId], fields: [users.authId],
references: [auth.id], references: [auth.id],
}), }),
admin: one(admins, { // admin: one(admins, {
fields: [users.adminId], // fields: [users.adminId],
references: [admins.adminId], // references: [admins.adminId],
}), // }),
})); }));
const createSchema = createInsertSchema(users, { const createSchema = createInsertSchema(users, {