Skip to content

Instantly share code, notes, and snippets.

@debpu06
Last active August 23, 2024 13:51
Show Gist options
  • Save debpu06/65793940a81161bee4b9d6e63e438e54 to your computer and use it in GitHub Desktop.
Save debpu06/65793940a81161bee4b9d6e63e438e54 to your computer and use it in GitHub Desktop.
#!/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