mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: simplify names of colums
This commit is contained in:
parent
ed46fd3cef
commit
73efe0d0ed
37
apps/dokploy/drizzle/0047_optimal_peter_quill.sql
Normal file
37
apps/dokploy/drizzle/0047_optimal_peter_quill.sql
Normal file
@ -0,0 +1,37 @@
|
||||
ALTER TABLE "application" RENAME COLUMN "githubProviderId" TO "githubId";--> statement-breakpoint
|
||||
ALTER TABLE "application" RENAME COLUMN "gitlabProviderId" TO "gitlabId";--> statement-breakpoint
|
||||
ALTER TABLE "application" RENAME COLUMN "bitbucketProviderId" TO "bitbucketId";--> statement-breakpoint
|
||||
ALTER TABLE "bitbucket_provider" RENAME COLUMN "bitbucketProviderId" TO "bitbucketId";--> statement-breakpoint
|
||||
ALTER TABLE "github_provider" RENAME COLUMN "githubProviderId" TO "githubId";--> statement-breakpoint
|
||||
ALTER TABLE "gitlab_provider" RENAME COLUMN "gitlabProviderId" TO "gitlabId";--> statement-breakpoint
|
||||
ALTER TABLE "application" DROP CONSTRAINT "application_githubProviderId_github_provider_githubProviderId_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "application" DROP CONSTRAINT "application_gitlabProviderId_gitlab_provider_gitlabProviderId_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "application" DROP CONSTRAINT "application_bitbucketProviderId_bitbucket_provider_bitbucketProviderId_fk";
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "application" ADD CONSTRAINT "application_githubId_github_provider_githubId_fk" FOREIGN KEY ("githubId") REFERENCES "public"."github_provider"("githubId") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "application" ADD CONSTRAINT "application_gitlabId_gitlab_provider_gitlabId_fk" FOREIGN KEY ("gitlabId") REFERENCES "public"."gitlab_provider"("gitlabId") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "application" ADD CONSTRAINT "application_bitbucketId_bitbucket_provider_bitbucketId_fk" FOREIGN KEY ("bitbucketId") REFERENCES "public"."bitbucket_provider"("bitbucketId") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "admin" DROP COLUMN IF EXISTS "githubAppId";--> statement-breakpoint
|
||||
ALTER TABLE "admin" DROP COLUMN IF EXISTS "githubAppName";--> statement-breakpoint
|
||||
ALTER TABLE "admin" DROP COLUMN IF EXISTS "githubClientId";--> statement-breakpoint
|
||||
ALTER TABLE "admin" DROP COLUMN IF EXISTS "githubClientSecret";--> statement-breakpoint
|
||||
ALTER TABLE "admin" DROP COLUMN IF EXISTS "githubInstallationId";--> statement-breakpoint
|
||||
ALTER TABLE "admin" DROP COLUMN IF EXISTS "githubPrivateKey";--> statement-breakpoint
|
||||
ALTER TABLE "admin" DROP COLUMN IF EXISTS "githubWebhookSecret";
|
3413
apps/dokploy/drizzle/meta/0047_snapshot.json
Normal file
3413
apps/dokploy/drizzle/meta/0047_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -330,6 +330,13 @@
|
||||
"when": 1725168434474,
|
||||
"tag": "0046_wonderful_oracle",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 47,
|
||||
"version": "6",
|
||||
"when": 1725172770448,
|
||||
"tag": "0047_optimal_peter_quill",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
@ -50,7 +50,7 @@ export default async function handler(
|
||||
.set({
|
||||
githubInstallationId: installation_id,
|
||||
})
|
||||
.where(eq(githubProvider.githubProviderId, value as string))
|
||||
.where(eq(githubProvider.githubId, value as string))
|
||||
.returning();
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ export default async function handler(
|
||||
return res.status(400).json({ error: "Missing or invalid code" });
|
||||
}
|
||||
const expiresAt = Math.floor(Date.now() / 1000) + result.expires_in;
|
||||
const updatedGiltab = await updateGitlabProvider(gitlab.gitlabProviderId, {
|
||||
const updatedGiltab = await updateGitlabProvider(gitlab.gitlabId, {
|
||||
accessToken: result.access_token,
|
||||
refreshToken: result.refresh_token,
|
||||
expiresAt,
|
||||
|
@ -31,9 +31,9 @@ export const gitProvider = createTRPCRouter({
|
||||
getAll: protectedProcedure.query(async () => {
|
||||
return await db.query.gitProvider.findMany({
|
||||
with: {
|
||||
gitlabProvider: true,
|
||||
bitbucketProvider: true,
|
||||
githubProvider: true,
|
||||
gitlab: true,
|
||||
bitbucket: true,
|
||||
github: true,
|
||||
},
|
||||
});
|
||||
}),
|
||||
@ -86,7 +86,7 @@ export const gitProvider = createTRPCRouter({
|
||||
.filter((provider) => haveGithubRequirements(provider))
|
||||
.map((provider) => {
|
||||
return {
|
||||
githubProviderId: provider.githubProviderId,
|
||||
githubId: provider.githubId,
|
||||
gitProvider: {
|
||||
...provider.gitProvider,
|
||||
},
|
||||
@ -105,7 +105,7 @@ export const gitProvider = createTRPCRouter({
|
||||
.filter((provider) => haveGitlabRequirements(provider))
|
||||
.map((provider) => {
|
||||
return {
|
||||
gitlabProviderId: provider.gitlabProviderId,
|
||||
gitlabId: provider.gitlabId,
|
||||
gitProvider: {
|
||||
...provider.gitProvider,
|
||||
},
|
||||
@ -120,7 +120,7 @@ export const gitProvider = createTRPCRouter({
|
||||
gitProvider: true,
|
||||
},
|
||||
columns: {
|
||||
bitbucketProviderId: true,
|
||||
bitbucketId: true,
|
||||
},
|
||||
});
|
||||
return result;
|
||||
@ -182,3 +182,20 @@ export const gitProvider = createTRPCRouter({
|
||||
return await getGithubBranches(input);
|
||||
}),
|
||||
});
|
||||
// 1725175543
|
||||
// {
|
||||
// access_token: '11d422887d8fac712191ee9b09dfdb043a705938cd67a4a39f36b4bc65b3106d',
|
||||
// token_type: 'Bearer',
|
||||
// expires_in: 7200,
|
||||
// refresh_token: '3806d8022d32886c19d91eb9d1cea9328b864387f39c5d0469d08c48e18b674e',
|
||||
// scope: 'api read_user read_repository',
|
||||
// created_at: 1725167656
|
||||
// }
|
||||
// {
|
||||
// access_token: 'd256b52b10bf72ebf2784f8c0528e48a04a7d249c28695b6cc105b47b09c7336',
|
||||
// token_type: 'Bearer',
|
||||
// expires_in: 7200,
|
||||
// refresh_token: '265eb87d0bbef410e0c30a2c239c4fa3698943219a439fb43cf2f8227d1fcaf2',
|
||||
// scope: 'api read_user read_repository',
|
||||
// created_at: 1725167803
|
||||
// }
|
||||
|
@ -119,9 +119,9 @@ export const removeGithubProvider = async (gitProviderId: string) => {
|
||||
return result[0];
|
||||
};
|
||||
|
||||
export const getGithubProvider = async (githubProviderId: string) => {
|
||||
export const getGithubProvider = async (githubId: string) => {
|
||||
const githubProviderResult = await db.query.githubProvider.findFirst({
|
||||
where: eq(githubProvider.githubProviderId, githubProviderId),
|
||||
where: eq(githubProvider.githubId, githubId),
|
||||
});
|
||||
|
||||
if (!githubProviderResult) {
|
||||
@ -142,9 +142,9 @@ export const haveGithubRequirements = (githubProvider: GithubProvider) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const getGitlabProvider = async (gitlabProviderId: string) => {
|
||||
export const getGitlabProvider = async (gitlabId: string) => {
|
||||
const gitlabProviderResult = await db.query.gitlabProvider.findFirst({
|
||||
where: eq(gitlabProvider.gitlabProviderId, gitlabProviderId),
|
||||
where: eq(gitlabProvider.gitlabId, gitlabId),
|
||||
});
|
||||
|
||||
if (!gitlabProviderResult) {
|
||||
@ -158,7 +158,7 @@ export const getGitlabProvider = async (gitlabProviderId: string) => {
|
||||
};
|
||||
|
||||
export const updateGitlabProvider = async (
|
||||
gitlabProviderId: string,
|
||||
gitlabId: string,
|
||||
input: Partial<GitlabProvider>,
|
||||
) => {
|
||||
const result = await db
|
||||
@ -166,15 +166,15 @@ export const updateGitlabProvider = async (
|
||||
.set({
|
||||
...input,
|
||||
})
|
||||
.where(eq(gitlabProvider.gitlabProviderId, gitlabProviderId))
|
||||
.where(eq(gitlabProvider.gitlabId, gitlabId))
|
||||
.returning();
|
||||
|
||||
return result[0];
|
||||
};
|
||||
|
||||
export const getBitbucketProvider = async (bitbucketProviderId: string) => {
|
||||
export const getBitbucketProvider = async (bitbucketId: string) => {
|
||||
const bitbucketProviderResult = await db.query.bitbucketProvider.findFirst({
|
||||
where: eq(bitbucketProvider.bitbucketProviderId, bitbucketProviderId),
|
||||
where: eq(bitbucketProvider.bitbucketId, bitbucketId),
|
||||
});
|
||||
|
||||
if (!bitbucketProviderResult) {
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { generatePassword } from "@/templates/utils";
|
||||
import { relations } from "drizzle-orm";
|
||||
import {
|
||||
boolean,
|
||||
@ -186,20 +185,14 @@ export const applications = pgTable("application", {
|
||||
projectId: text("projectId")
|
||||
.notNull()
|
||||
.references(() => projects.projectId, { onDelete: "cascade" }),
|
||||
githubProviderId: text("githubProviderId").references(
|
||||
() => githubProvider.githubProviderId,
|
||||
{
|
||||
githubId: text("githubId").references(() => githubProvider.githubId, {
|
||||
onDelete: "set null",
|
||||
},
|
||||
),
|
||||
gitlabProviderId: text("gitlabProviderId").references(
|
||||
() => gitlabProvider.gitlabProviderId,
|
||||
{
|
||||
}),
|
||||
gitlabId: text("gitlabId").references(() => gitlabProvider.gitlabId, {
|
||||
onDelete: "set null",
|
||||
},
|
||||
),
|
||||
bitbucketProviderId: text("bitbucketProviderId").references(
|
||||
() => bitbucketProvider.bitbucketProviderId,
|
||||
}),
|
||||
bitbucketId: text("bitbucketId").references(
|
||||
() => bitbucketProvider.bitbucketId,
|
||||
{
|
||||
onDelete: "set null",
|
||||
},
|
||||
@ -228,16 +221,16 @@ export const applicationsRelations = relations(
|
||||
references: [registry.registryId],
|
||||
}),
|
||||
githubProvider: one(githubProvider, {
|
||||
fields: [applications.githubProviderId],
|
||||
references: [githubProvider.githubProviderId],
|
||||
fields: [applications.githubId],
|
||||
references: [githubProvider.githubId],
|
||||
}),
|
||||
gitlabProvider: one(gitlabProvider, {
|
||||
fields: [applications.gitlabProviderId],
|
||||
references: [gitlabProvider.gitlabProviderId],
|
||||
fields: [applications.gitlabId],
|
||||
references: [gitlabProvider.gitlabId],
|
||||
}),
|
||||
bitbucketProvider: one(bitbucketProvider, {
|
||||
fields: [applications.bitbucketProviderId],
|
||||
references: [bitbucketProvider.bitbucketProviderId],
|
||||
fields: [applications.bitbucketId],
|
||||
references: [bitbucketProvider.bitbucketId],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
@ -416,7 +409,7 @@ export const apiSaveGithubProvider = createSchema
|
||||
branch: true,
|
||||
owner: true,
|
||||
buildPath: true,
|
||||
githubProviderId: true,
|
||||
githubId: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
@ -427,7 +420,7 @@ export const apiSaveGitlabProvider = createSchema
|
||||
gitlabBuildPath: true,
|
||||
gitlabOwner: true,
|
||||
gitlabRepository: true,
|
||||
gitlabProviderId: true,
|
||||
gitlabId: true,
|
||||
})
|
||||
.required();
|
||||
|
||||
@ -437,7 +430,7 @@ export const apiSaveBitbucketProvider = createSchema
|
||||
bitbucketBuildPath: true,
|
||||
bitbucketOwner: true,
|
||||
bitbucketRepository: true,
|
||||
bitbucketProviderId: true,
|
||||
bitbucketId: true,
|
||||
applicationId: true,
|
||||
})
|
||||
.required();
|
||||
|
@ -27,15 +27,15 @@ export const gitProvider = pgTable("git_provider", {
|
||||
});
|
||||
|
||||
export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
|
||||
githubProvider: one(githubProvider, {
|
||||
github: one(githubProvider, {
|
||||
fields: [gitProvider.gitProviderId],
|
||||
references: [githubProvider.gitProviderId],
|
||||
}),
|
||||
gitlabProvider: one(gitlabProvider, {
|
||||
gitlab: one(gitlabProvider, {
|
||||
fields: [gitProvider.gitProviderId],
|
||||
references: [gitlabProvider.gitProviderId],
|
||||
}),
|
||||
bitbucketProvider: one(bitbucketProvider, {
|
||||
bitbucket: one(bitbucketProvider, {
|
||||
fields: [gitProvider.gitProviderId],
|
||||
references: [bitbucketProvider.gitProviderId],
|
||||
}),
|
||||
@ -46,7 +46,7 @@ export const gitProviderRelations = relations(gitProvider, ({ one, many }) => ({
|
||||
}));
|
||||
|
||||
export const githubProvider = pgTable("github_provider", {
|
||||
githubProviderId: text("githubProviderId")
|
||||
githubId: text("githubId")
|
||||
.notNull()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
@ -73,7 +73,7 @@ export const githubProviderRelations = relations(
|
||||
);
|
||||
|
||||
export const gitlabProvider = pgTable("gitlab_provider", {
|
||||
gitlabProviderId: text("gitlabProviderId")
|
||||
gitlabId: text("gitlabId")
|
||||
.notNull()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
@ -100,7 +100,7 @@ export const gitlabProviderRelations = relations(
|
||||
);
|
||||
|
||||
export const bitbucketProvider = pgTable("bitbucket_provider", {
|
||||
bitbucketProviderId: text("bitbucketProviderId")
|
||||
bitbucketId: text("bitbucketId")
|
||||
.notNull()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => nanoid()),
|
||||
|
@ -23,11 +23,11 @@ export const cloneBitbucketRepository = async (
|
||||
bitbucketRepository,
|
||||
bitbucketOwner,
|
||||
bitbucketBranch,
|
||||
bitbucketProviderId,
|
||||
bitbucketId,
|
||||
bitbucketProvider,
|
||||
} = entity;
|
||||
|
||||
if (!bitbucketProviderId) {
|
||||
if (!bitbucketId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Bitbucket Provider not found",
|
||||
@ -77,11 +77,11 @@ export const cloneRawBitbucketRepository = async (
|
||||
bitbucketRepository,
|
||||
bitbucketOwner,
|
||||
bitbucketBranch,
|
||||
bitbucketProviderId,
|
||||
bitbucketId,
|
||||
bitbucketProvider,
|
||||
} = entity;
|
||||
|
||||
if (!bitbucketProviderId) {
|
||||
if (!bitbucketId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Bitbucket Provider not found",
|
||||
|
@ -77,9 +77,9 @@ export const cloneGithubRepository = async (
|
||||
isCompose = false,
|
||||
) => {
|
||||
const writeStream = createWriteStream(logPath, { flags: "a" });
|
||||
const { appName, repository, owner, branch, githubProviderId } = entity;
|
||||
const { appName, repository, owner, branch, githubId } = entity;
|
||||
|
||||
if (!githubProviderId) {
|
||||
if (!githubId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "GitHub Provider not found",
|
||||
@ -102,7 +102,7 @@ export const cloneGithubRepository = async (
|
||||
});
|
||||
}
|
||||
|
||||
const githubProvider = await getGithubProvider(githubProviderId);
|
||||
const githubProvider = await getGithubProvider(githubId);
|
||||
const basePath = isCompose ? COMPOSE_PATH : APPLICATIONS_PATH;
|
||||
const outputPath = join(basePath, appName, "code");
|
||||
const octokit = authGithub(githubProvider);
|
||||
@ -143,15 +143,15 @@ export const cloneGithubRepository = async (
|
||||
export const cloneRawGithubRepository = async (
|
||||
entity: ApplicationWithGithub,
|
||||
) => {
|
||||
const { appName, repository, owner, branch, githubProviderId } = entity;
|
||||
const { appName, repository, owner, branch, githubId } = entity;
|
||||
|
||||
if (!githubProviderId) {
|
||||
if (!githubId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "GitHub Provider not found",
|
||||
});
|
||||
}
|
||||
const githubProvider = await getGithubProvider(githubProviderId);
|
||||
const githubProvider = await getGithubProvider(githubId);
|
||||
const basePath = COMPOSE_PATH;
|
||||
const outputPath = join(basePath, appName, "code");
|
||||
const octokit = authGithub(githubProvider);
|
||||
|
@ -88,18 +88,18 @@ export const cloneGitlabRepository = async (
|
||||
gitlabRepository,
|
||||
gitlabOwner,
|
||||
gitlabBranch,
|
||||
gitlabProviderId,
|
||||
gitlabId,
|
||||
gitlabProvider,
|
||||
} = entity;
|
||||
|
||||
if (!gitlabProviderId) {
|
||||
if (!gitlabId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Gitlab Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
await refreshGitlabToken(gitlabProviderId);
|
||||
await refreshGitlabToken(gitlabId);
|
||||
|
||||
const requirements = getErrorCloneRequirements(entity);
|
||||
|
||||
@ -258,18 +258,18 @@ export const cloneRawGitlabRepository = async (
|
||||
gitlabRepository,
|
||||
gitlabOwner,
|
||||
gitlabBranch,
|
||||
gitlabProviderId,
|
||||
gitlabId,
|
||||
gitlabProvider,
|
||||
} = entity;
|
||||
|
||||
if (!gitlabProviderId) {
|
||||
if (!gitlabId) {
|
||||
throw new TRPCError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Gitlab Provider not found",
|
||||
});
|
||||
}
|
||||
|
||||
await refreshGitlabToken(gitlabProviderId);
|
||||
await refreshGitlabToken(gitlabId);
|
||||
const basePath = COMPOSE_PATH;
|
||||
const outputPath = join(basePath, appName, "code");
|
||||
await recreateDirectory(outputPath);
|
||||
|
Loading…
Reference in New Issue
Block a user