mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: migration
This commit is contained in:
parent
c04bf3c7e0
commit
fafc238e70
@ -90,7 +90,8 @@ UPDATE "user" SET token = '' WHERE token IS NULL;
|
|||||||
UPDATE "user" SET "expirationDate" = CURRENT_TIMESTAMP + INTERVAL '1 year' WHERE "expirationDate" IS NULL;
|
UPDATE "user" SET "expirationDate" = CURRENT_TIMESTAMP + INTERVAL '1 year' WHERE "expirationDate" IS NULL;
|
||||||
UPDATE "user" SET "createdAt" = to_char(CURRENT_TIMESTAMP, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') WHERE "createdAt" IS NULL;
|
UPDATE "user" SET "createdAt" = to_char(CURRENT_TIMESTAMP, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') WHERE "createdAt" IS NULL;
|
||||||
UPDATE "user" SET "name" = '' WHERE "name" IS NULL;
|
UPDATE "user" SET "name" = '' WHERE "name" IS NULL;
|
||||||
UPDATE "user" SET "email" = COALESCE("email", '') WHERE true;
|
-- Generar emails únicos para registros vacíos
|
||||||
|
UPDATE "user" SET "email" = CONCAT('user_', id, '@dokploy.local') WHERE "email" = '' OR "email" IS NULL;
|
||||||
UPDATE "user" SET "email_verified" = COALESCE("email_verified", false) WHERE true;
|
UPDATE "user" SET "email_verified" = COALESCE("email_verified", false) WHERE true;
|
||||||
UPDATE "user" SET "role" = COALESCE("role", 'user') WHERE true;
|
UPDATE "user" SET "role" = COALESCE("role", 'user') WHERE true;
|
||||||
UPDATE "user" SET "banned" = COALESCE("banned", false) WHERE true;
|
UPDATE "user" SET "banned" = COALESCE("banned", false) WHERE true;
|
||||||
@ -128,6 +129,28 @@ SELECT
|
|||||||
CAST("createdAt" AS timestamp) as updated_at
|
CAST("createdAt" AS timestamp) as updated_at
|
||||||
FROM "auth";
|
FROM "auth";
|
||||||
|
|
||||||
|
-- Migrar datos de auth a account
|
||||||
|
INSERT INTO "account" (
|
||||||
|
id,
|
||||||
|
account_id,
|
||||||
|
provider_id,
|
||||||
|
user_id,
|
||||||
|
password,
|
||||||
|
"is2FAEnabled",
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
id as id,
|
||||||
|
id as account_id,
|
||||||
|
'credentials' as provider_id,
|
||||||
|
id as user_id,
|
||||||
|
password,
|
||||||
|
"is2FAEnabled",
|
||||||
|
CAST("createdAt" AS timestamp) as created_at,
|
||||||
|
CAST("createdAt" AS timestamp) as updated_at
|
||||||
|
FROM "auth";
|
||||||
|
|
||||||
-- Migrar datos de admin a user
|
-- Migrar datos de admin a user
|
||||||
UPDATE "user" u
|
UPDATE "user" u
|
||||||
SET
|
SET
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
"test": "vitest --config __test__/vitest.config.ts"
|
"test": "vitest --config __test__/vitest.config.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"better-auth":"1.1.16",
|
"better-auth": "1.1.16",
|
||||||
"bl": "6.0.11",
|
"bl": "6.0.11",
|
||||||
"rotating-file-stream": "3.2.3",
|
"rotating-file-stream": "3.2.3",
|
||||||
"qrcode": "^1.5.3",
|
"qrcode": "^1.5.3",
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { authClient } from "@/lib/auth";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { IS_CLOUD, isAdminPresent, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD, isAdminPresent, validateRequest } from "@dokploy/server";
|
||||||
@ -65,8 +66,8 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const form = useForm<Login>({
|
const form = useForm<Login>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: "",
|
email: "siumauricio@hotmail.com",
|
||||||
password: "",
|
password: "Password1234",
|
||||||
},
|
},
|
||||||
resolver: zodResolver(loginSchema),
|
resolver: zodResolver(loginSchema),
|
||||||
});
|
});
|
||||||
@ -76,25 +77,31 @@ export default function Home({ IS_CLOUD }: Props) {
|
|||||||
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
||||||
|
|
||||||
const onSubmit = async (values: Login) => {
|
const onSubmit = async (values: Login) => {
|
||||||
await mutateAsync({
|
const { data, error } = await authClient.signIn.email({
|
||||||
email: values.email.toLowerCase(),
|
email: values.email,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
})
|
});
|
||||||
.then((data) => {
|
|
||||||
if (data.is2FAEnabled) {
|
console.log(data, error);
|
||||||
setTemp(data);
|
// await mutateAsync({
|
||||||
} else {
|
// email: values.email.toLowerCase(),
|
||||||
toast.success("Successfully signed in", {
|
// password: values.password,
|
||||||
duration: 2000,
|
// })
|
||||||
});
|
// .then((data) => {
|
||||||
router.push("/dashboard/projects");
|
// if (data.is2FAEnabled) {
|
||||||
}
|
// setTemp(data);
|
||||||
})
|
// } else {
|
||||||
.catch(() => {
|
// toast.success("Successfully signed in", {
|
||||||
toast.error("Signin failed", {
|
// duration: 2000,
|
||||||
duration: 2000,
|
// });
|
||||||
});
|
// router.push("/dashboard/projects");
|
||||||
});
|
// }
|
||||||
|
// })
|
||||||
|
// .catch(() => {
|
||||||
|
// toast.error("Signin failed", {
|
||||||
|
// duration: 2000,
|
||||||
|
// });
|
||||||
|
// });
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { authClient } from "@/lib/auth";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { IS_CLOUD, isAdminPresent, validateRequest } from "@dokploy/server";
|
import { IS_CLOUD, isAdminPresent, validateRequest } from "@dokploy/server";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
@ -79,9 +80,9 @@ const Register = ({ isCloud }: Props) => {
|
|||||||
|
|
||||||
const form = useForm<Register>({
|
const form = useForm<Register>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
email: "",
|
email: "user5@yopmail.com",
|
||||||
password: "",
|
password: "Password1234",
|
||||||
confirmPassword: "",
|
confirmPassword: "Password1234",
|
||||||
},
|
},
|
||||||
resolver: zodResolver(registerSchema),
|
resolver: zodResolver(registerSchema),
|
||||||
});
|
});
|
||||||
@ -91,19 +92,24 @@ const Register = ({ isCloud }: Props) => {
|
|||||||
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
}, [form, form.reset, form.formState.isSubmitSuccessful]);
|
||||||
|
|
||||||
const onSubmit = async (values: Register) => {
|
const onSubmit = async (values: Register) => {
|
||||||
await mutateAsync({
|
const { data, error } = await authClient.signUp.email({
|
||||||
email: values.email.toLowerCase(),
|
email: values.email,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
})
|
name: "Mauricio Siu",
|
||||||
.then(() => {
|
});
|
||||||
toast.success("User registered successfuly", {
|
// await mutateAsync({
|
||||||
duration: 2000,
|
// email: values.email.toLowerCase(),
|
||||||
});
|
// password: values.password,
|
||||||
if (!isCloud) {
|
// })
|
||||||
router.push("/");
|
// .then(() => {
|
||||||
}
|
// toast.success("User registered successfuly", {
|
||||||
})
|
// duration: 2000,
|
||||||
.catch((e) => e);
|
// });
|
||||||
|
// if (!isCloud) {
|
||||||
|
// router.push("/");
|
||||||
|
// }
|
||||||
|
// })
|
||||||
|
// .catch((e) => e);
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div className="">
|
<div className="">
|
||||||
|
@ -6,7 +6,7 @@ import {
|
|||||||
apiRemoveUser,
|
apiRemoveUser,
|
||||||
apiUpdateAdmin,
|
apiUpdateAdmin,
|
||||||
apiUpdateWebServerMonitoring,
|
apiUpdateWebServerMonitoring,
|
||||||
users,
|
user,
|
||||||
} from "@/server/db/schema";
|
} from "@/server/db/schema";
|
||||||
import {
|
import {
|
||||||
IS_CLOUD,
|
IS_CLOUD,
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
|
boolean,
|
||||||
|
integer,
|
||||||
pgTable,
|
pgTable,
|
||||||
text,
|
text,
|
||||||
integer,
|
|
||||||
timestamp,
|
timestamp,
|
||||||
boolean,
|
|
||||||
} from "drizzle-orm/pg-core";
|
} from "drizzle-orm/pg-core";
|
||||||
|
|
||||||
export const user = pgTable("user", {
|
export const user = pgTable("user", {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { boolean, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
import { boolean, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
export const account = pgTable("account", {
|
export const account = pgTable("account", {
|
||||||
id: text("id").primaryKey(),
|
id: text("id").primaryKey(),
|
||||||
@ -7,7 +7,7 @@ export const account = pgTable("account", {
|
|||||||
providerId: text("provider_id").notNull(),
|
providerId: text("provider_id").notNull(),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id),
|
.references(() => user.id),
|
||||||
accessToken: text("access_token"),
|
accessToken: text("access_token"),
|
||||||
refreshToken: text("refresh_token"),
|
refreshToken: text("refresh_token"),
|
||||||
idToken: text("id_token"),
|
idToken: text("id_token"),
|
||||||
|
@ -5,7 +5,7 @@ import { createInsertSchema } from "drizzle-zod";
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
// import { admins } from "./admin";
|
// import { admins } from "./admin";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
const randomImages = [
|
const randomImages = [
|
||||||
"/avatars/avatar-1.png",
|
"/avatars/avatar-1.png",
|
||||||
@ -56,7 +56,7 @@ export const auth = pgTable("auth", {
|
|||||||
|
|
||||||
export const authRelations = relations(auth, ({ many }) => ({
|
export const authRelations = relations(auth, ({ many }) => ({
|
||||||
// admins: many(admins),
|
// admins: many(admins),
|
||||||
users: many(users),
|
users: many(user),
|
||||||
}));
|
}));
|
||||||
const createSchema = createInsertSchema(auth, {
|
const createSchema = createInsertSchema(auth, {
|
||||||
email: z.string().email(),
|
email: z.string().email(),
|
||||||
|
@ -4,8 +4,8 @@ import { createInsertSchema } from "drizzle-zod";
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { server } from "./server";
|
import { server } from "./server";
|
||||||
|
import { user } from "./user";
|
||||||
import { generateAppName } from "./utils";
|
import { generateAppName } from "./utils";
|
||||||
import { users } from "./user";
|
|
||||||
|
|
||||||
export const certificates = pgTable("certificate", {
|
export const certificates = pgTable("certificate", {
|
||||||
certificateId: text("certificateId")
|
certificateId: text("certificateId")
|
||||||
@ -20,7 +20,7 @@ export const certificates = pgTable("certificate", {
|
|||||||
.$defaultFn(() => generateAppName("certificate"))
|
.$defaultFn(() => generateAppName("certificate"))
|
||||||
.unique(),
|
.unique(),
|
||||||
autoRenew: boolean("autoRenew"),
|
autoRenew: boolean("autoRenew"),
|
||||||
userId: text("userId").references(() => users.id, {
|
userId: text("userId").references(() => user.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
}),
|
}),
|
||||||
serverId: text("serverId").references(() => server.serverId, {
|
serverId: text("serverId").references(() => server.serverId, {
|
||||||
@ -35,9 +35,9 @@ export const certificatesRelations = relations(
|
|||||||
fields: [certificates.serverId],
|
fields: [certificates.serverId],
|
||||||
references: [server.serverId],
|
references: [server.serverId],
|
||||||
}),
|
}),
|
||||||
user: one(users, {
|
user: one(user, {
|
||||||
fields: [certificates.userId],
|
fields: [certificates.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -5,7 +5,7 @@ import { nanoid } from "nanoid";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { admins } from "./admin";
|
import { admins } from "./admin";
|
||||||
import { backups } from "./backups";
|
import { backups } from "./backups";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
export const destinations = pgTable("destination", {
|
export const destinations = pgTable("destination", {
|
||||||
destinationId: text("destinationId")
|
destinationId: text("destinationId")
|
||||||
@ -22,16 +22,16 @@ export const destinations = pgTable("destination", {
|
|||||||
endpoint: text("endpoint").notNull(),
|
endpoint: text("endpoint").notNull(),
|
||||||
userId: text("userId")
|
userId: text("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const destinationsRelations = relations(
|
export const destinationsRelations = relations(
|
||||||
destinations,
|
destinations,
|
||||||
({ many, one }) => ({
|
({ many, one }) => ({
|
||||||
backups: many(backups),
|
backups: many(backups),
|
||||||
user: one(users, {
|
user: one(user, {
|
||||||
fields: [destinations.userId],
|
fields: [destinations.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -7,7 +7,7 @@ import { admins } from "./admin";
|
|||||||
import { bitbucket } from "./bitbucket";
|
import { bitbucket } from "./bitbucket";
|
||||||
import { github } from "./github";
|
import { github } from "./github";
|
||||||
import { gitlab } from "./gitlab";
|
import { gitlab } from "./gitlab";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
export const gitProviderType = pgEnum("gitProviderType", [
|
export const gitProviderType = pgEnum("gitProviderType", [
|
||||||
"github",
|
"github",
|
||||||
@ -25,7 +25,7 @@ export const gitProvider = pgTable("git_provider", {
|
|||||||
createdAt: text("createdAt")
|
createdAt: text("createdAt")
|
||||||
.notNull()
|
.notNull()
|
||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
userId: text("userId").references(() => users.id, {
|
userId: text("userId").references(() => user.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@ -43,9 +43,9 @@ export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
|
|||||||
fields: [gitProvider.gitProviderId],
|
fields: [gitProvider.gitProviderId],
|
||||||
references: [bitbucket.gitProviderId],
|
references: [bitbucket.gitProviderId],
|
||||||
}),
|
}),
|
||||||
user: one(users, {
|
user: one(user, {
|
||||||
fields: [gitProvider.userId],
|
fields: [gitProvider.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import { createInsertSchema } from "drizzle-zod";
|
|||||||
import { nanoid } from "nanoid";
|
import { nanoid } from "nanoid";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { admins } from "./admin";
|
import { admins } from "./admin";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
export const notificationType = pgEnum("notificationType", [
|
export const notificationType = pgEnum("notificationType", [
|
||||||
"slack",
|
"slack",
|
||||||
@ -45,7 +45,7 @@ export const notifications = pgTable("notification", {
|
|||||||
gotifyId: text("gotifyId").references(() => gotify.gotifyId, {
|
gotifyId: text("gotifyId").references(() => gotify.gotifyId, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
}),
|
}),
|
||||||
userId: text("userId").references(() => users.id, {
|
userId: text("userId").references(() => user.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@ -122,9 +122,9 @@ export const notificationsRelations = relations(notifications, ({ one }) => ({
|
|||||||
fields: [notifications.gotifyId],
|
fields: [notifications.gotifyId],
|
||||||
references: [gotify.gotifyId],
|
references: [gotify.gotifyId],
|
||||||
}),
|
}),
|
||||||
user: one(users, {
|
user: one(user, {
|
||||||
fields: [notifications.userId],
|
fields: [notifications.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ import { mongo } from "./mongo";
|
|||||||
import { mysql } from "./mysql";
|
import { mysql } from "./mysql";
|
||||||
import { postgres } from "./postgres";
|
import { postgres } from "./postgres";
|
||||||
import { redis } from "./redis";
|
import { redis } from "./redis";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
export const projects = pgTable("project", {
|
export const projects = pgTable("project", {
|
||||||
projectId: text("projectId")
|
projectId: text("projectId")
|
||||||
@ -26,7 +26,7 @@ export const projects = pgTable("project", {
|
|||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
userId: text("userId")
|
userId: text("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
env: text("env").notNull().default(""),
|
env: text("env").notNull().default(""),
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -38,9 +38,9 @@ export const projectRelations = relations(projects, ({ many, one }) => ({
|
|||||||
mongo: many(mongo),
|
mongo: many(mongo),
|
||||||
redis: many(redis),
|
redis: many(redis),
|
||||||
compose: many(compose),
|
compose: many(compose),
|
||||||
user: one(users, {
|
user: one(user, {
|
||||||
fields: [projects.userId],
|
fields: [projects.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import { nanoid } from "nanoid";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { admins } from "./admin";
|
import { admins } from "./admin";
|
||||||
import { applications } from "./application";
|
import { applications } from "./application";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
/**
|
/**
|
||||||
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
|
||||||
* database instance for multiple projects.
|
* database instance for multiple projects.
|
||||||
@ -30,13 +30,13 @@ export const registry = pgTable("registry", {
|
|||||||
registryType: registryType("selfHosted").notNull().default("cloud"),
|
registryType: registryType("selfHosted").notNull().default("cloud"),
|
||||||
userId: text("userId")
|
userId: text("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
.references(() => user.id, { onDelete: "cascade" }),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const registryRelations = relations(registry, ({ one, many }) => ({
|
export const registryRelations = relations(registry, ({ one, many }) => ({
|
||||||
user: one(users, {
|
user: one(user, {
|
||||||
fields: [registry.userId],
|
fields: [registry.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
applications: many(applications),
|
applications: many(applications),
|
||||||
}));
|
}));
|
||||||
|
@ -22,8 +22,8 @@ import { mysql } from "./mysql";
|
|||||||
import { postgres } from "./postgres";
|
import { postgres } from "./postgres";
|
||||||
import { redis } from "./redis";
|
import { redis } from "./redis";
|
||||||
import { sshKeys } from "./ssh-key";
|
import { sshKeys } from "./ssh-key";
|
||||||
|
import { user } from "./user";
|
||||||
import { generateAppName } from "./utils";
|
import { generateAppName } from "./utils";
|
||||||
import { users } from "./user";
|
|
||||||
|
|
||||||
export const serverStatus = pgEnum("serverStatus", ["active", "inactive"]);
|
export const serverStatus = pgEnum("serverStatus", ["active", "inactive"]);
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ export const server = pgTable("server", {
|
|||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
userId: text("userId")
|
userId: text("userId")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id, { onDelete: "cascade" }),
|
.references(() => user.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, {
|
||||||
@ -101,9 +101,9 @@ export const server = pgTable("server", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const serverRelations = relations(server, ({ one, many }) => ({
|
export const serverRelations = relations(server, ({ one, many }) => ({
|
||||||
user: one(users, {
|
user: one(user, {
|
||||||
fields: [server.userId],
|
fields: [server.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
deployments: many(deployments),
|
deployments: many(deployments),
|
||||||
sshKey: one(sshKeys, {
|
sshKey: one(sshKeys, {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
||||||
import { users } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
// OLD TABLE
|
// OLD TABLE
|
||||||
export const sessionTable = pgTable("session", {
|
export const sessionTable = pgTable("session", {
|
||||||
@ -12,6 +12,6 @@ export const sessionTable = pgTable("session", {
|
|||||||
userAgent: text("user_agent"),
|
userAgent: text("user_agent"),
|
||||||
userId: text("user_id")
|
userId: text("user_id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.references(() => users.id),
|
.references(() => user.id),
|
||||||
impersonatedBy: text("impersonated_by"),
|
impersonatedBy: text("impersonated_by"),
|
||||||
});
|
});
|
||||||
|
@ -7,7 +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 } from "./user";
|
import { user } from "./user";
|
||||||
|
|
||||||
export const sshKeys = pgTable("ssh-key", {
|
export const sshKeys = pgTable("ssh-key", {
|
||||||
sshKeyId: text("sshKeyId")
|
sshKeyId: text("sshKeyId")
|
||||||
@ -22,7 +22,7 @@ export const sshKeys = pgTable("ssh-key", {
|
|||||||
.notNull()
|
.notNull()
|
||||||
.$defaultFn(() => new Date().toISOString()),
|
.$defaultFn(() => new Date().toISOString()),
|
||||||
lastUsedAt: text("lastUsedAt"),
|
lastUsedAt: text("lastUsedAt"),
|
||||||
userId: text("userId").references(() => users.id, {
|
userId: text("userId").references(() => user.id, {
|
||||||
onDelete: "cascade",
|
onDelete: "cascade",
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
@ -31,9 +31,9 @@ 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(users, {
|
user: one(user, {
|
||||||
fields: [sshKeys.userId],
|
fields: [sshKeys.userId],
|
||||||
references: [users.id],
|
references: [user.id],
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import { certificateType } from "./shared";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// OLD TABLE
|
// OLD TABLE
|
||||||
export const users = pgTable("user", {
|
export const user = pgTable("user", {
|
||||||
id: text("id")
|
id: text("id")
|
||||||
.notNull()
|
.notNull()
|
||||||
.primaryKey()
|
.primaryKey()
|
||||||
@ -129,7 +129,7 @@ export const users = pgTable("user", {
|
|||||||
.default(false),
|
.default(false),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const usersRelations = relations(users, ({ one }) => ({
|
export const usersRelations = relations(user, ({ one }) => ({
|
||||||
// auth: one(auth, {
|
// auth: one(auth, {
|
||||||
// fields: [users.authId],
|
// fields: [users.authId],
|
||||||
// references: [auth.id],
|
// references: [auth.id],
|
||||||
@ -140,7 +140,7 @@ export const usersRelations = relations(users, ({ one }) => ({
|
|||||||
// }),
|
// }),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const createSchema = createInsertSchema(users, {
|
const createSchema = createInsertSchema(user, {
|
||||||
id: z.string().min(1),
|
id: z.string().min(1),
|
||||||
// authId: z.string().min(1),
|
// authId: z.string().min(1),
|
||||||
token: z.string().min(1),
|
token: z.string().min(1),
|
||||||
|
@ -2,10 +2,11 @@ import { betterAuth } from "better-auth";
|
|||||||
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
||||||
import { admin } from "better-auth/plugins";
|
import { admin } from "better-auth/plugins";
|
||||||
import { db } from "../db";
|
import { db } from "../db";
|
||||||
|
import * as schema from "../db/schema";
|
||||||
export const auth = betterAuth({
|
export const auth = betterAuth({
|
||||||
database: drizzleAdapter(db, {
|
database: drizzleAdapter(db, {
|
||||||
provider: "pg",
|
provider: "pg",
|
||||||
|
schema: schema,
|
||||||
}),
|
}),
|
||||||
emailAndPassword: {
|
emailAndPassword: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
@ -4,7 +4,7 @@ import {
|
|||||||
admins,
|
admins,
|
||||||
type apiCreateUserInvitation,
|
type apiCreateUserInvitation,
|
||||||
auth,
|
auth,
|
||||||
users,
|
user,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import * as bcrypt from "bcrypt";
|
import * as bcrypt from "bcrypt";
|
||||||
|
@ -5,7 +5,7 @@ import {
|
|||||||
type apiCreateAdmin,
|
type apiCreateAdmin,
|
||||||
type apiCreateUser,
|
type apiCreateUser,
|
||||||
auth,
|
auth,
|
||||||
users,
|
user,
|
||||||
} from "@dokploy/server/db/schema";
|
} from "@dokploy/server/db/schema";
|
||||||
import { getPublicIpWithFallback } from "@dokploy/server/wss/utils";
|
import { getPublicIpWithFallback } from "@dokploy/server/wss/utils";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
import { db } from "@dokploy/server/db";
|
import { db } from "@dokploy/server/db";
|
||||||
import { users } from "@dokploy/server/db/schema";
|
import { user } from "@dokploy/server/db/schema";
|
||||||
import { TRPCError } from "@trpc/server";
|
import { TRPCError } from "@trpc/server";
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
|
|
||||||
export type User = typeof users.$inferSelect;
|
export type User = typeof user.$inferSelect;
|
||||||
|
|
||||||
export const findUserById = async (userId: string) => {
|
export const findUserById = async (userId: string) => {
|
||||||
const user = await db.query.users.findFirst({
|
const userR = await db.query.user.findFirst({
|
||||||
where: eq(users.userId, userId),
|
where: eq(user.userId, userId),
|
||||||
});
|
});
|
||||||
if (!user) {
|
if (!userR) {
|
||||||
throw new TRPCError({
|
throw new TRPCError({
|
||||||
code: "NOT_FOUND",
|
code: "NOT_FOUND",
|
||||||
message: "User not found",
|
message: "User not found",
|
||||||
@ -19,8 +19,8 @@ export const findUserById = async (userId: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const findUserByAuthId = async (authId: string) => {
|
export const findUserByAuthId = async (authId: string) => {
|
||||||
const user = await db.query.users.findFirst({
|
const userR = await db.query.user.findFirst({
|
||||||
where: eq(users.authId, authId),
|
where: eq(user.authId, authId),
|
||||||
with: {
|
with: {
|
||||||
auth: true,
|
auth: true,
|
||||||
},
|
},
|
||||||
@ -35,8 +35,8 @@ export const findUserByAuthId = async (authId: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const findUsers = async (adminId: string) => {
|
export const findUsers = async (adminId: string) => {
|
||||||
const currentUsers = await db.query.users.findMany({
|
const currentUsers = await db.query.user.findMany({
|
||||||
where: eq(users.adminId, adminId),
|
where: eq(user.adminId, adminId),
|
||||||
with: {
|
with: {
|
||||||
auth: {
|
auth: {
|
||||||
columns: {
|
columns: {
|
||||||
@ -49,24 +49,24 @@ export const findUsers = async (adminId: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const addNewProject = async (authId: string, projectId: string) => {
|
export const addNewProject = async (authId: string, projectId: string) => {
|
||||||
const user = await findUserByAuthId(authId);
|
const userR = await findUserByAuthId(authId);
|
||||||
|
|
||||||
await db
|
await db
|
||||||
.update(users)
|
.update(user)
|
||||||
.set({
|
.set({
|
||||||
accessedProjects: [...user.accessedProjects, projectId],
|
accessedProjects: [...userR.accessedProjects, projectId],
|
||||||
})
|
})
|
||||||
.where(eq(users.authId, authId));
|
.where(eq(user.authId, authId));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const addNewService = async (authId: string, serviceId: string) => {
|
export const addNewService = async (authId: string, serviceId: string) => {
|
||||||
const user = await findUserByAuthId(authId);
|
const userR = await findUserByAuthId(authId);
|
||||||
await db
|
await db
|
||||||
.update(users)
|
.update(user)
|
||||||
.set({
|
.set({
|
||||||
accessedServices: [...user.accessedServices, serviceId],
|
accessedServices: [...userR.accessedServices, serviceId],
|
||||||
})
|
})
|
||||||
.where(eq(users.authId, authId));
|
.where(eq(user.authId, authId));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const canPerformCreationService = async (
|
export const canPerformCreationService = async (
|
||||||
|
Loading…
Reference in New Issue
Block a user