From b9032781c722e513d2575f4f44bb564a7938e377 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Wed, 11 Apr 2018 18:11:44 +0200 Subject: [PATCH 1/2] feat(settings): allow to make a PR which changes both the settings and the data We need this change, because right now, if we merge a PR which changes the index settings, they are immediately applied to the production index, which could not have the correct data yet Flow before this PR: 1. setSettings on production index 2. setSettings on bootstrap index 3. bootstrap 4. copy production settings to bootstrap index 5. move bootstrap index to production index 6. delete bootstrap index 7. replicate 8. watch Flow after this PR 1. setSettings on bootstrap index 3. bootstrap (will set settings to prod if up to date) 5. move bootstrap index to production index with its settings 6. delete bootstrap index 7. replicate 8. watch --- src/index.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index bb8c690a4..fa912838a 100644 --- a/src/index.js +++ b/src/index.js @@ -28,7 +28,7 @@ const { index: mainIndex, client } = createAlgoliaIndex(c.indexName); const { index: bootstrapIndex } = createAlgoliaIndex(c.bootstrapIndexName); const stateManager = createStateManager(mainIndex); -setSettings(mainIndex) +Promise.resolve() .then(() => setSettings(bootstrapIndex)) .then(() => stateManager.check()) .then(bootstrap) @@ -83,6 +83,7 @@ function infoDocs(offset, nbDocs, emoji) { async function bootstrap(state) { if (state.seq > 0 && state.bootstrapDone === true) { + await setSettings(mainIndex); log.info('⛷ Bootstrap: done'); return state; } @@ -148,14 +149,13 @@ async function bootstrap(state) { async function moveToProduction() { log.info('🚚 starting move to production'); - await client.copyIndex(c.indexName, c.bootstrapIndexName, [ + + const currentState = await stateManager.get(); + await client.copyIndex(c.bootstrapIndexName, c.indexName, [ 'settings', 'synonyms', 'rules', ]); - - const currentState = await stateManager.get(); - await client.copyIndex(c.bootstrapIndexName, c.indexName); await stateManager.save(currentState); log.info('🗑 old bootstrap'); From 0675e8e8ec5ed9b24294a26d94ad528cf075acf2 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Fri, 13 Apr 2018 12:57:13 +0200 Subject: [PATCH 2/2] feat: don't delete bootstrap after it's done only deleted when a new bootstrap starts from 0 --- src/index.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index fa912838a..69aa59d40 100644 --- a/src/index.js +++ b/src/index.js @@ -151,15 +151,9 @@ async function moveToProduction() { log.info('🚚 starting move to production'); const currentState = await stateManager.get(); - await client.copyIndex(c.bootstrapIndexName, c.indexName, [ - 'settings', - 'synonyms', - 'rules', - ]); - await stateManager.save(currentState); + await client.copyIndex(c.bootstrapIndexName, c.indexName); - log.info('🗑 old bootstrap'); - await client.deleteIndex(c.bootstrapIndexName); + return stateManager.save(currentState); } async function replicate({ seq }) {