MCPcopy Index your code
hub / github.com/triggerdotdev/trigger.dev / runStagingEnvironmentMigration

Function runStagingEnvironmentMigration

apps/webapp/prisma/seed.ts:75–133  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73}
74
75async 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 }

Callers 1

runDataMigrationsFunction · 0.85

Calls 5

createEnvironmentFunction · 0.90
createMethod · 0.65
logMethod · 0.65
errorMethod · 0.65
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…