mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-19 12:55:26 +02:00
refactor: update project structure to use environmentId instead of projectId across components and API routes; implement environment management features
This commit is contained in:
@@ -180,9 +180,6 @@ export const applications = pgTable("application", {
|
||||
registryId: text("registryId").references(() => registry.registryId, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
environmentId: text("environmentId")
|
||||
.notNull()
|
||||
.references(() => environments.environmentId, { onDelete: "cascade" }),
|
||||
@@ -206,10 +203,7 @@ export const applications = pgTable("application", {
|
||||
export const applicationsRelations = relations(
|
||||
applications,
|
||||
({ one, many }) => ({
|
||||
project: one(projects, {
|
||||
fields: [applications.projectId],
|
||||
references: [projects.projectId],
|
||||
}),
|
||||
|
||||
environment: one(environments, {
|
||||
fields: [applications.environmentId],
|
||||
references: [environments.environmentId],
|
||||
@@ -281,7 +275,6 @@ const createSchema = createInsertSchema(applications, {
|
||||
customGitBuildPath: z.string().optional(),
|
||||
customGitUrl: z.string().optional(),
|
||||
buildPath: z.string().optional(),
|
||||
projectId: z.string(),
|
||||
environmentId: z.string(),
|
||||
sourceType: z
|
||||
.enum(["github", "docker", "git", "gitlab", "bitbucket", "gitea", "drop"])
|
||||
@@ -326,7 +319,6 @@ export const apiCreateApplication = createSchema.pick({
|
||||
name: true,
|
||||
appName: true,
|
||||
description: true,
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
serverId: true,
|
||||
});
|
||||
|
||||
@@ -85,9 +85,6 @@ export const compose = pgTable("compose", {
|
||||
.default(false),
|
||||
triggerType: triggerType("triggerType").default("push"),
|
||||
composeStatus: applicationStatus("composeStatus").notNull().default("idle"),
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
environmentId: text("environmentId")
|
||||
.notNull()
|
||||
.references(() => environments.environmentId, { onDelete: "cascade" }),
|
||||
@@ -113,10 +110,7 @@ export const compose = pgTable("compose", {
|
||||
});
|
||||
|
||||
export const composeRelations = relations(compose, ({ one, many }) => ({
|
||||
project: one(projects, {
|
||||
fields: [compose.projectId],
|
||||
references: [projects.projectId],
|
||||
}),
|
||||
|
||||
environment: one(environments, {
|
||||
fields: [compose.environmentId],
|
||||
references: [environments.environmentId],
|
||||
@@ -157,7 +151,6 @@ const createSchema = createInsertSchema(compose, {
|
||||
description: z.string(),
|
||||
env: z.string().optional(),
|
||||
composeFile: z.string().optional(),
|
||||
projectId: z.string(),
|
||||
environmentId: z.string(),
|
||||
customGitSSHKeyId: z.string().optional(),
|
||||
command: z.string().optional(),
|
||||
@@ -169,7 +162,6 @@ const createSchema = createInsertSchema(compose, {
|
||||
export const apiCreateCompose = createSchema.pick({
|
||||
name: true,
|
||||
description: true,
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
composeType: true,
|
||||
appName: true,
|
||||
@@ -179,7 +171,6 @@ export const apiCreateCompose = createSchema.pick({
|
||||
|
||||
export const apiCreateComposeByTemplate = createSchema
|
||||
.pick({
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
})
|
||||
.extend({
|
||||
|
||||
@@ -67,9 +67,7 @@ export const mariadb = pgTable("mariadb", {
|
||||
createdAt: text("createdAt")
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date().toISOString()),
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
|
||||
environmentId: text("environmentId")
|
||||
.notNull()
|
||||
.references(() => environments.environmentId, { onDelete: "cascade" }),
|
||||
@@ -79,10 +77,7 @@ export const mariadb = pgTable("mariadb", {
|
||||
});
|
||||
|
||||
export const mariadbRelations = relations(mariadb, ({ one, many }) => ({
|
||||
project: one(projects, {
|
||||
fields: [mariadb.projectId],
|
||||
references: [projects.projectId],
|
||||
}),
|
||||
|
||||
environment: one(environments, {
|
||||
fields: [mariadb.environmentId],
|
||||
references: [environments.environmentId],
|
||||
@@ -123,7 +118,6 @@ const createSchema = createInsertSchema(mariadb, {
|
||||
memoryLimit: z.string().optional(),
|
||||
cpuReservation: z.string().optional(),
|
||||
cpuLimit: z.string().optional(),
|
||||
projectId: z.string(),
|
||||
environmentId: z.string(),
|
||||
applicationStatus: z.enum(["idle", "running", "done", "error"]),
|
||||
externalPort: z.number(),
|
||||
@@ -145,7 +139,6 @@ export const apiCreateMariaDB = createSchema
|
||||
appName: true,
|
||||
dockerImage: true,
|
||||
databaseRootPassword: true,
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
description: true,
|
||||
databaseName: true,
|
||||
|
||||
@@ -63,9 +63,7 @@ export const mongo = pgTable("mongo", {
|
||||
createdAt: text("createdAt")
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date().toISOString()),
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
|
||||
environmentId: text("environmentId")
|
||||
.notNull()
|
||||
.references(() => environments.environmentId, { onDelete: "cascade" }),
|
||||
@@ -76,10 +74,7 @@ export const mongo = pgTable("mongo", {
|
||||
});
|
||||
|
||||
export const mongoRelations = relations(mongo, ({ one, many }) => ({
|
||||
project: one(projects, {
|
||||
fields: [mongo.projectId],
|
||||
references: [projects.projectId],
|
||||
}),
|
||||
|
||||
environment: one(environments, {
|
||||
fields: [mongo.environmentId],
|
||||
references: [environments.environmentId],
|
||||
@@ -112,7 +107,6 @@ const createSchema = createInsertSchema(mongo, {
|
||||
memoryLimit: z.string().optional(),
|
||||
cpuReservation: z.string().optional(),
|
||||
cpuLimit: z.string().optional(),
|
||||
projectId: z.string(),
|
||||
environmentId: z.string(),
|
||||
applicationStatus: z.enum(["idle", "running", "done", "error"]),
|
||||
externalPort: z.number(),
|
||||
@@ -134,7 +128,6 @@ export const apiCreateMongo = createSchema
|
||||
name: true,
|
||||
appName: true,
|
||||
dockerImage: true,
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
description: true,
|
||||
databaseUser: true,
|
||||
|
||||
@@ -65,9 +65,7 @@ export const mysql = pgTable("mysql", {
|
||||
createdAt: text("createdAt")
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date().toISOString()),
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
|
||||
environmentId: text("environmentId")
|
||||
.notNull()
|
||||
.references(() => environments.environmentId, { onDelete: "cascade" }),
|
||||
@@ -77,10 +75,7 @@ export const mysql = pgTable("mysql", {
|
||||
});
|
||||
|
||||
export const mysqlRelations = relations(mysql, ({ one, many }) => ({
|
||||
project: one(projects, {
|
||||
fields: [mysql.projectId],
|
||||
references: [projects.projectId],
|
||||
}),
|
||||
|
||||
environment: one(environments, {
|
||||
fields: [mysql.environmentId],
|
||||
references: [environments.environmentId],
|
||||
@@ -121,7 +116,6 @@ const createSchema = createInsertSchema(mysql, {
|
||||
memoryLimit: z.string().optional(),
|
||||
cpuReservation: z.string().optional(),
|
||||
cpuLimit: z.string().optional(),
|
||||
projectId: z.string(),
|
||||
applicationStatus: z.enum(["idle", "running", "done", "error"]),
|
||||
externalPort: z.number(),
|
||||
description: z.string().optional(),
|
||||
@@ -141,7 +135,6 @@ export const apiCreateMySql = createSchema
|
||||
name: true,
|
||||
appName: true,
|
||||
dockerImage: true,
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
description: true,
|
||||
databaseName: true,
|
||||
|
||||
@@ -65,9 +65,7 @@ export const postgres = pgTable("postgres", {
|
||||
createdAt: text("createdAt")
|
||||
.notNull()
|
||||
.$defaultFn(() => new Date().toISOString()),
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
|
||||
environmentId: text("environmentId")
|
||||
.notNull()
|
||||
.references(() => environments.environmentId, { onDelete: "cascade" }),
|
||||
@@ -77,10 +75,7 @@ export const postgres = pgTable("postgres", {
|
||||
});
|
||||
|
||||
export const postgresRelations = relations(postgres, ({ one, many }) => ({
|
||||
project: one(projects, {
|
||||
fields: [postgres.projectId],
|
||||
references: [projects.projectId],
|
||||
}),
|
||||
|
||||
environment: one(environments, {
|
||||
fields: [postgres.environmentId],
|
||||
references: [environments.environmentId],
|
||||
@@ -112,7 +107,6 @@ const createSchema = createInsertSchema(postgres, {
|
||||
memoryLimit: z.string().optional(),
|
||||
cpuReservation: z.string().optional(),
|
||||
cpuLimit: z.string().optional(),
|
||||
projectId: z.string(),
|
||||
environmentId: z.string(),
|
||||
applicationStatus: z.enum(["idle", "running", "done", "error"]),
|
||||
externalPort: z.number(),
|
||||
@@ -137,7 +131,6 @@ export const apiCreatePostgres = createSchema
|
||||
databaseUser: true,
|
||||
databasePassword: true,
|
||||
dockerImage: true,
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
description: true,
|
||||
serverId: true,
|
||||
|
||||
@@ -61,9 +61,7 @@ export const redis = pgTable("redis", {
|
||||
labelsSwarm: json("labelsSwarm").$type<LabelsSwarm>(),
|
||||
networkSwarm: json("networkSwarm").$type<NetworkSwarm[]>(),
|
||||
replicas: integer("replicas").default(1).notNull(),
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
|
||||
environmentId: text("environmentId")
|
||||
.notNull()
|
||||
.references(() => environments.environmentId, { onDelete: "cascade" }),
|
||||
@@ -73,10 +71,7 @@ export const redis = pgTable("redis", {
|
||||
});
|
||||
|
||||
export const redisRelations = relations(redis, ({ one, many }) => ({
|
||||
project: one(projects, {
|
||||
fields: [redis.projectId],
|
||||
references: [projects.projectId],
|
||||
}),
|
||||
|
||||
environment: one(environments, {
|
||||
fields: [redis.environmentId],
|
||||
references: [environments.environmentId],
|
||||
@@ -101,7 +96,6 @@ const createSchema = createInsertSchema(redis, {
|
||||
memoryLimit: z.string().optional(),
|
||||
cpuReservation: z.string().optional(),
|
||||
cpuLimit: z.string().optional(),
|
||||
projectId: z.string(),
|
||||
environmentId: z.string(),
|
||||
applicationStatus: z.enum(["idle", "running", "done", "error"]),
|
||||
externalPort: z.number(),
|
||||
@@ -123,7 +117,6 @@ export const apiCreateRedis = createSchema
|
||||
appName: true,
|
||||
databasePassword: true,
|
||||
dockerImage: true,
|
||||
projectId: true,
|
||||
environmentId: true,
|
||||
description: true,
|
||||
serverId: true,
|
||||
|
||||
@@ -76,6 +76,7 @@ export const createApplication = async (
|
||||
});
|
||||
}
|
||||
|
||||
console.log("input", input);
|
||||
return await db.transaction(async (tx) => {
|
||||
const newApplication = await tx
|
||||
.insert(applications)
|
||||
@@ -86,6 +87,8 @@ export const createApplication = async (
|
||||
.returning()
|
||||
.then((value) => value[0]);
|
||||
|
||||
console.log("newApplication", newApplication);
|
||||
|
||||
if (!newApplication) {
|
||||
throw new TRPCError({
|
||||
code: "BAD_REQUEST",
|
||||
@@ -105,7 +108,7 @@ export const findApplicationById = async (applicationId: string) => {
|
||||
const application = await db.query.applications.findFirst({
|
||||
where: eq(applications.applicationId, applicationId),
|
||||
with: {
|
||||
project: true,
|
||||
environment: true,
|
||||
domains: true,
|
||||
deployments: true,
|
||||
mounts: true,
|
||||
|
||||
@@ -33,6 +33,16 @@ export const createEnvironment = async (
|
||||
export const findEnvironmentById = async (environmentId: string) => {
|
||||
const environment = await db.query.environments.findFirst({
|
||||
where: eq(environments.environmentId, environmentId),
|
||||
with: {
|
||||
applications: true,
|
||||
mariadb: true,
|
||||
mongo: true,
|
||||
mysql: true,
|
||||
postgres: true,
|
||||
redis: true,
|
||||
compose: true,
|
||||
project: true,
|
||||
},
|
||||
});
|
||||
if (!environment) {
|
||||
throw new TRPCError({
|
||||
|
||||
@@ -99,7 +99,7 @@ export const updateProjectById = async (
|
||||
};
|
||||
|
||||
export const validUniqueServerAppName = async (appName: string) => {
|
||||
const query = await db.query.projects.findMany({
|
||||
const query = await db.query.environments.findMany({
|
||||
with: {
|
||||
applications: {
|
||||
where: eq(applications.appName, appName),
|
||||
|
||||
Reference in New Issue
Block a user