()
| 73 | } |
| 74 | |
| 75 | async function runStagingEnvironmentMigration() { |
| 76 | try { |
| 77 | await prisma.$transaction(async (tx) => { |
| 78 | const existingDataMigration = await tx.dataMigration.findUnique({ |
| 79 | where: { |
| 80 | name: "2023-09-27-AddStagingEnvironments", |
| 81 | }, |
| 82 | }); |
| 83 | |
| 84 | if (existingDataMigration) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | await tx.dataMigration.create({ |
| 89 | data: { |
| 90 | name: "2023-09-27-AddStagingEnvironments", |
| 91 | }, |
| 92 | }); |
| 93 | |
| 94 | console.log("Running data migration 2023-09-27-AddStagingEnvironments"); |
| 95 | |
| 96 | const projectsWithoutStagingEnvironments = await tx.project.findMany({ |
| 97 | where: { |
| 98 | environments: { |
| 99 | none: { |
| 100 | type: "STAGING", |
| 101 | }, |
| 102 | }, |
| 103 | }, |
| 104 | include: { |
| 105 | organization: true, |
| 106 | }, |
| 107 | }); |
| 108 | |
| 109 | for (const project of projectsWithoutStagingEnvironments) { |
| 110 | try { |
| 111 | console.log( |
| 112 | `Creating staging environment for project ${project.slug} on org ${project.organization.slug}` |
| 113 | ); |
| 114 | |
| 115 | await createEnvironment(project.organization, project, "STAGING", undefined, tx); |
| 116 | } catch (error) { |
| 117 | console.error(error); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | await tx.dataMigration.update({ |
| 122 | where: { |
| 123 | name: "2023-09-27-AddStagingEnvironments", |
| 124 | }, |
| 125 | data: { |
| 126 | completedAt: new Date(), |
| 127 | }, |
| 128 | }); |
| 129 | }); |
| 130 | } catch (error) { |
| 131 | console.error(error); |
| 132 | } |
no test coverage detected
searching dependent graphs…