Repository navigation
fix: don't sync the documentId of the default roles and locale - #249
Open
marcelxpfeifer wants to merge 1 commit into
Open
marcelxpfeifer wants to merge 1 commit into
marcelxpfeifer wants to merge 1 commit into
Conversation
Strapi creates the default admin roles, the users-permissions roles and the default i18n locale itself at bootstrap, each with a random documentId that an import can't change (documents().update keeps the documentId). So on any database other than the one the files were exported from, these configs showed as Different after every import, and import on bootstrap imported them on every start. Config types get an ignoreDocumentId option that leaves the documentId out of the export and the comparison; it's set for admin-role, user-role and i18n-locale, which are matched by their uid. The relations in a config file are now sorted by their relationSortFields like the database side, so a file that lists its permissions in another order (edited by hand, or merged) isn't Different either.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does it do?
ignoreDocumentIdoption to config types. For such a type the top-leveldocumentIdis not exported and not compared. It's set for the defaultadmin-role,user-roleandi18n-localetypes, which are matched by their uid.relationSortFields, the way the database side already sorts them, before comparing.Why is it needed?
Strapi creates the default admin roles, the users-permissions Public and Authenticated roles and the default locale itself at bootstrap, each with a random
documentId. The import updates them withstrapi.documents().update(), which can't change adocumentId. So on every database other than the one the files were exported from,config-sync difflists these configs as Different, however often you import, andimportOnBootstrapimports them again on every start. Re-exporting from one environment only moves the difference to the others. This is part of what #190 describes.The permission
documentIds don't have this problem: the relation update goes throughstrapi.query().update(), which sets them, so they match after one import.The sorting fixes a related false difference: a role file that lists its permissions in another order, for example after a hand edit or a merge, showed as Different although the permissions were the same.
How to test it?
Export, delete the database (
.tmpin the playground), runconfig-sync import -y, thenconfig-sync diff. Before this change the roles and theenlocale are listed as Different, withdocumentIdas the only change. With it there are no differences.New tests in
playground/__tests__/cli.test.js:documentId.documentIdleft in a role or locale file from an older export doesn't make it Different.admin-role.strapi-editorand inuser-role.publicdoesn't make them Different.Ran
yarn eslintandyarn test:integrationlocally (Node 26, SQLite): all pass. On master the new-database test fails, and without the sorting the two reversed-permission tests fail. I didn't run the Cypress e2e tests.Risk: existing files keep their
documentIduntil the config is exported again, which then drops it. It's ignored when comparing either way, and still used when an import creates the entry. A role or locale that changed only itsdocumentIdis no longer reported. That change can't be imported anyway.How to revert: revert the commit. Files exported without
documentIdkeep working: the next export after the revert writes it back.Related issue(s)/PR(s)
#190