Last active
August 23, 2024 13:51
-
-
Save debpu06/65793940a81161bee4b9d6e63e438e54 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env node | |
import { saveDataToContentful, updateExistingEntry } from "./contentful/data-source"; | |
import { createClient } from 'contentful-management'; | |
import chalk from 'chalk'; | |
import { findExistingEntryWithDatabaseId, sleep } from "./contentful/utility/api-util"; | |
import dotenv from 'dotenv'; | |
dotenv.config(); | |
process.argv.forEach(function (val, index, array) { | |
if (index >= 2) | |
migrate(val); | |
}); | |
async function migrate(tableName) { | |
const client = createClient({ | |
accessToken: process.env.CONTENTFUL_MANAGEMENT_TOKEN ?? '' | |
}); | |
const space = await client.getSpace(process.env.CONTENTFUL_SPACE_ID ?? ''); | |
const environment = await space.getEnvironment(process.env.CONTENTFUL_ENVIRONMENT ?? ''); | |
// could make this a argument to the script | |
let updating = false; | |
databaseRows.forEach(async (row) => { | |
await saveDataToContentful(mapping.contentfulType, row, null, environment); | |
sleep(500); // Sleep for 500ms to avoid rate limiting | |
}); | |
console.log(chalk.red('Migration complete with', errors, 'errors')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment