From b4230dec378bbb00d234ff56ea979cff4f7eb5af Mon Sep 17 00:00:00 2001 From: "wouter.thys" Date: Mon, 26 Jun 2023 14:24:23 +0200 Subject: [PATCH 1/3] add option enables syncing of datasources without their corresponding dimension values --- src/cli.js | 8 +++++--- src/tasks/sync-commands/datasources.js | 20 +++++++++++++------- src/tasks/sync.js | 4 +++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/cli.js b/src/cli.js index 5b503436..b671b8cc 100755 --- a/src/cli.js +++ b/src/cli.js @@ -277,6 +277,7 @@ program .option('--operations ', 'Operations to be used for filtering. Can be: is, in, not_in, like, not_like, any_in_array, all_in_array, gt_date, lt_date, gt_int, lt_int, gt_float, lt_float. Multiple operations should be separated by comma.') .option('--values ', 'Values to be used for filtering. Any string or number. If you want to use multiple values, separate them with a comma. Multiple values should be separated by comma.') .option('--components-groups ', 'Synchronize components based on their group UUIDs separated by commas') + .option('--datasource-disable-dimensions-value-sync', 'Enables syncing of datasources without their corresponding dimension values.') .action(async (options) => { console.log(`${chalk.blue('-')} Sync data between spaces\n`) @@ -294,7 +295,8 @@ program keys, operations, values, - componentsGroups + componentsGroups, + datasourceDisableDimensionsValueSync } = options const _componentsGroups = componentsGroups ? componentsGroups.split(',') : null @@ -307,7 +309,6 @@ program }) const filterQuery = filter ? buildFilterQuery(keys, operations, values) : undefined - const token = creds.get().token || null await tasks.sync(_types, { api, @@ -316,7 +317,8 @@ program target, startsWith, filterQuery, - _componentsGroups + _componentsGroups, + datasourceDisableDimensionsValueSync }) console.log('\n' + chalk.green('✓') + ' Sync data between spaces successfully completed') diff --git a/src/tasks/sync-commands/datasources.js b/src/tasks/sync-commands/datasources.js index e6d1e658..9427a2cb 100644 --- a/src/tasks/sync-commands/datasources.js +++ b/src/tasks/sync-commands/datasources.js @@ -4,7 +4,7 @@ const api = require('../../utils/api') class SyncDatasources { /** - * @param {{ sourceSpaceId: string, targetSpaceId: string, oauthToken: string }} options + * @param {{ sourceSpaceId: string, targetSpaceId: string, oauthToken: string, datasourceDisableDimensionsValueSync: boolean }} options */ constructor (options) { this.targetDatasources = [] @@ -13,6 +13,7 @@ class SyncDatasources { this.targetSpaceId = options.targetSpaceId this.oauthToken = options.oauthToken this.client = api.getClient() + this.datasourceDisableDimensionsValueSync = options.datasourceDisableDimensionsValueSync } async sync () { @@ -139,11 +140,14 @@ class SyncDatasources { ) const { data } = await this.createDatasourcesDimensions(datasourcesToAdd[i].dimensions, newDatasource.data.datasource) await this.syncDatasourceEntries(datasourcesToAdd[i].id, newDatasource.data.datasource.id) - console.log( - ` ${chalk.blue('-')} Sync dimensions values...` - ) - await this.syncDatasourceDimensionsValues(datasourcesToAdd[i], data.datasource) - console.log(` ${chalk.green('✓')} Created datasource ${datasourcesToAdd[i].name}`) + if (!this.datasourceDisableDimensionsValueSync) { + console.log( + ` ${chalk.blue('-')} Sync dimensions values...` + ) + await this.syncDatasourceDimensionsValues(datasourcesToAdd[i], data.datasource) + + console.log(` ${chalk.green('✓')} Created datasource ${datasourcesToAdd[i].name}`) + } } else { await this.syncDatasourceEntries(datasourcesToAdd[i].id, newDatasource.data.datasource.id) console.log(` ${chalk.green('✓')} Created datasource ${datasourcesToAdd[i].name}`) @@ -191,7 +195,9 @@ class SyncDatasources { await this.syncDatasourceEntries(sourceDatasource.id, datasourcesToUpdate[i].id) - await this.syncDatasourceDimensionsValues(sourceDatasource, datasourceToSyncDimensionsValues) + if (!this.datasourceDisableDimensionsValueSync) { + await this.syncDatasourceDimensionsValues(sourceDatasource, datasourceToSyncDimensionsValues) + } console.log(`${chalk.green('✓')} Updated datasource ${datasourcesToUpdate[i].name}`) } else { await this.syncDatasourceEntries(sourceDatasource.id, datasourcesToUpdate[i].id) diff --git a/src/tasks/sync.js b/src/tasks/sync.js index 8c357ce6..bb8d5d62 100644 --- a/src/tasks/sync.js +++ b/src/tasks/sync.js @@ -19,6 +19,7 @@ const SyncSpaces = { this.filterQuery = options.filterQuery this.client = api.getClient() this.componentsGroups = options._componentsGroups + this.datasourceDisableDimensionsValueSync = options.datasourceDisableDimensionsValueSync }, async getStoryWithTranslatedSlugs (sourceStory, targetStory) { @@ -252,7 +253,8 @@ const SyncSpaces = { const syncDatasourcesInstance = new SyncDatasources({ sourceSpaceId: this.sourceSpaceId, targetSpaceId: this.targetSpaceId, - oauthToken: this.oauthToken + oauthToken: this.oauthToken, + datasourceDisableDimensionsValueSync: this.datasourceDisableDimensionsValueSync }) try { From 6028d8334da790bfcdb24eb58c0075b6a71baca2 Mon Sep 17 00:00:00 2001 From: "wouter.thys" Date: Mon, 26 Jun 2023 15:23:33 +0200 Subject: [PATCH 2/3] update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 148a5a9b..eb5c712e 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,7 @@ $ storyblok sync --type --source --target * `filter`: sync stories based on the given filter. Required Options: Required options: `--keys`, `--operations`, `--values` * `keys`: Multiple keys should be separated by comma. Example: `--keys key1,key2`, `--keys key1` * `operations`: Operations to be used for filtering. Can be: `is`, `in`, `not_in`, `like`, `not_like`, `any_in_array`, `all_in_array`, `gt_date`, `lt_date`, `gt_int`, `lt_int`, `gt_float`, `lt_float`. Multiple operations should be separated by comma. +*`datasource-disable-dimensions-value-sync`: Enables syncing of datasources without their corresponding dimension values. #### Examples From 641c1f5d4b4bd34d49f2a67f2a774cb4c3a785d1 Mon Sep 17 00:00:00 2001 From: Wouter Thys <93272674+CaprinaeWT@users.noreply.github.com> Date: Thu, 10 Aug 2023 10:16:36 +0200 Subject: [PATCH 3/3] Remove filterQuery --- src/cli.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cli.js b/src/cli.js index b8cdfd96..dab40b87 100755 --- a/src/cli.js +++ b/src/cli.js @@ -299,9 +299,6 @@ program throw new Error(`The type ${_type} is not valid`) } }) - - const filterQuery = filter ? buildFilterQuery(keys, operations, values) : undefined - const token = creds.get().token || null await tasks.sync(_types, { api,