Skip to content

Commit

Permalink
feat(settings): allow to make a PR which changes both the settings an…
Browse files Browse the repository at this point in the history
…d the data (#179)

* 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

* feat: don't delete bootstrap after it's done

only deleted when a new bootstrap starts from 0
  • Loading branch information
Haroenv authored and vvo committed Apr 13, 2018
1 parent 067c79c commit e8f7c2a
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -148,18 +149,11 @@ async function bootstrap(state) {

async function moveToProduction() {
log.info('🚚 starting move to production');
await client.copyIndex(c.indexName, c.bootstrapIndexName, [
'settings',
'synonyms',
'rules',
]);

const currentState = await stateManager.get();
await client.copyIndex(c.bootstrapIndexName, c.indexName);
await stateManager.save(currentState);

log.info('🗑 old bootstrap');
await client.deleteIndex(c.bootstrapIndexName);
return stateManager.save(currentState);
}

async function replicate({ seq }) {
Expand Down

0 comments on commit e8f7c2a

Please sign in to comment.