-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ft/climatemapped-remove-usestyles-hurumap
- Loading branch information
Showing
7 changed files
with
109 additions
and
166 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
apps/civicsignalblog/migrations/20241122_054517_migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { MigrateUpArgs, MigrateDownArgs } from "@payloadcms/db-mongodb"; | ||
import mongoose from "mongoose"; | ||
|
||
const mongoURL = process.env.MONGO_URL; | ||
const oldGlobalConfigType = "settings-site"; | ||
const newGlobalConfigType = "settings-research-site"; | ||
|
||
export async function up({ payload }: MigrateUpArgs): Promise<void> { | ||
await mongoose.connect(mongoURL); | ||
const db = mongoose.connection.db; | ||
|
||
const existingOldGlobalConfig = await db.collection("globals").findOne({ | ||
globalType: oldGlobalConfigType, | ||
}); | ||
|
||
if (!existingOldGlobalConfig) { | ||
payload.logger.info( | ||
`No existing global settings [${oldGlobalConfigType}] config found, exiting...`, | ||
); | ||
return; | ||
} | ||
|
||
const existingNewGlobalConfig = await db.collection("globals").findOne({ | ||
globalType: newGlobalConfigType, | ||
}); | ||
|
||
if (existingNewGlobalConfig) { | ||
payload.logger.error( | ||
`Migration 20241122_054517 failed: Global type [${newGlobalConfigType}] already exists.`, | ||
); | ||
return; | ||
} | ||
|
||
try { | ||
const { _id, globalType, ...newGlobalConfig } = existingOldGlobalConfig; | ||
newGlobalConfig.globalType = newGlobalConfigType; | ||
await db.collection("globals").insertOne(newGlobalConfig); | ||
payload.logger.info( | ||
`✓ Successfully migrated global config [${oldGlobalConfigType}] to [${newGlobalConfigType}]`, | ||
); | ||
} catch (error) { | ||
payload.logger.error("Error: Migration 20241122_054517 failed."); | ||
throw error; | ||
} | ||
} | ||
export async function down({ payload }: MigrateDownArgs): Promise<void> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters