Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
bugfix(sanity-migration): attempt to fix sync-after-feature scripts; (#…
Browse files Browse the repository at this point in the history
…4804)

Co-authored-by: VWSCoronaDashboard26 <[email protected]>
  • Loading branch information
VWSCoronaDashboard26 and VWSCoronaDashboard26 authored Jun 30, 2023
1 parent 25a0666 commit fb908c3
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions packages/cms/src/lokalize/scripts/sync-after-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import { hasValueAtKey } from 'ts-is-present';
import { client } from '../../studio/client';
import { AddMutation, DeleteMutation, finalizeMoveMutations, getCollapsedAddDeleteMutations, getCollapsedMoveMutations, readTextMutations } from '../utils/mutation-utilities';

const developmentClient = client.withConfig({ dataset: 'development' });
const productionClient = client.withConfig({ dataset: 'production' });

/**
* Remove the documents that were marked for deletion from the development set.
* Here we intentionally DO NOT USE the document id from the mutation log, but
Expand All @@ -37,10 +34,10 @@ const applyDeletionsToDevelopment = async (deletions: DeleteMutation[]) => {
return;
}

const developmentClient = client.withConfig({ dataset: 'development' });

// Query both published and draft documents, because we want to delete both from development
const allTexts = (await developmentClient.fetch(`//groq
*[_type == 'lokalizeText'] | order(subject asc)
`)) as LokalizeText[];
const allTexts = (await developmentClient.fetch(`*[_type == 'lokalizeText'] | order(subject asc))`)) as LokalizeText[];

// We need to find both draft and published versions of the document
const documentIdsToDelete = deletions.flatMap(({ key }) => allTexts.filter((allText) => allText.key === key)).map((key) => key._id);
Expand All @@ -59,13 +56,13 @@ const syncAdditionsToProduction = async (mutations: AddMutation[]) => {
return;
}

// Workaround for add mutations that have no document id yet, so that we can lookup the document by key.
const allPublishedTexts = (await developmentClient.fetch(`//groq
*[_type == 'lokalizeText' && !(_id in path("drafts.**"))] | order(subject asc)
`)) as LokalizeText[];

const developmentClient = client.withConfig({ dataset: 'development' });
const productionClient = client.withConfig({ dataset: 'production' });
const productionTransation = productionClient.transaction();

// Workaround for add mutations that have no document id yet, so that we can lookup the document by key.
const allPublishedTexts = (await developmentClient.fetch(`*[_type == 'lokalizeText' && !(_id in path("drafts.**"))] | order(subject asc)`)) as LokalizeText[];

let successCount = 0;
let failureCount = 0;

Expand All @@ -92,9 +89,7 @@ const syncAdditionsToProduction = async (mutations: AddMutation[]) => {
};

// Double check to see if the given key doesn't already exist on production
const count = await productionClient.fetch(`//groq
count(*[_type == 'lokalizeText' && key == '${documentToInject.key}'])
`);
const count = await productionClient.fetch(`count(*[_type == 'lokalizeText' && key == '${documentToInject.key}'])`);

if (count === 0) {
/**
Expand Down Expand Up @@ -154,6 +149,6 @@ const syncAdditionsToProduction = async (mutations: AddMutation[]) => {

await syncAdditionsToProduction(additions);
})().catch((error) => {
console.error('An error occurred:', error.message);
console.error('An error occurred:', error);
process.exit(1);
});

0 comments on commit fb908c3

Please sign in to comment.