mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 12:26:05 +00:00
Update external-migration-fns.ts
This commit is contained in:
@@ -143,16 +143,31 @@ export const importDataIntoInfisicalFn = async ({
|
|||||||
logger.error(e, `Failed to import to project [name:${project.name}]`);
|
logger.error(e, `Failed to import to project [name:${project.name}]`);
|
||||||
throw new BadRequestError({ message: `Failed to import to project [name:${project.name}]` });
|
throw new BadRequestError({ message: `Failed to import to project [name:${project.name}]` });
|
||||||
});
|
});
|
||||||
|
|
||||||
originalToNewProjectId.set(project.id, newProject.id);
|
originalToNewProjectId.set(project.id, newProject.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import environments
|
// Import environments
|
||||||
if (data.environments) {
|
if (data.environments) {
|
||||||
for await (const environment of data.environments) {
|
for await (const environment of data.environments) {
|
||||||
const projectId = originalToNewProjectId.get(environment.projectId)!;
|
let projectId = originalToNewProjectId.get(environment.projectId);
|
||||||
const slug = slugify(`${environment.name}-${alphaNumericNanoId(4)}`);
|
const slug = slugify(`${environment.name}-${alphaNumericNanoId(4)}`);
|
||||||
|
|
||||||
|
// case: if for some reason the project ID is not found, we will create a new project and import the corresponding environment into it.
|
||||||
|
if (!projectId) {
|
||||||
|
const newProject = await projectService.createProject({
|
||||||
|
actor,
|
||||||
|
actorId,
|
||||||
|
actorOrgId,
|
||||||
|
actorAuthMethod,
|
||||||
|
workspaceName: `project-import-${environment.projectId}`,
|
||||||
|
createDefaultEnvs: false,
|
||||||
|
tx
|
||||||
|
});
|
||||||
|
|
||||||
|
originalToNewProjectId.set(environment.projectId, newProject.id);
|
||||||
|
projectId = newProject.id;
|
||||||
|
}
|
||||||
|
|
||||||
const existingEnv = await projectEnvDAL.findOne({ projectId, slug }, tx);
|
const existingEnv = await projectEnvDAL.findOne({ projectId, slug }, tx);
|
||||||
|
|
||||||
if (existingEnv) {
|
if (existingEnv) {
|
||||||
|
|||||||
Reference in New Issue
Block a user