Skip to content

fix: don't sync the documentId of the default roles and locale - #249

Open
marcelxpfeifer wants to merge 1 commit into
pluginpal:masterfrom
marcelxpfeifer:fix/ignore-bootstrap-document-ids
Open

marcelxpfeifer wants to merge 1 commit into
pluginpal:masterfrom
marcelxpfeifer:fix/ignore-bootstrap-document-ids

Conversation

@marcelxpfeifer

Copy link
Copy Markdown

What does it do?

  • Adds an ignoreDocumentId option to config types. For such a type the top-level documentId is not exported and not compared. It's set for the default admin-role, user-role and i18n-locale types, which are matched by their uid.
  • Sorts the relations in a config file by their 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 with strapi.documents().update(), which can't change a documentId. So on every database other than the one the files were exported from, config-sync diff lists these configs as Different, however often you import, and importOnBootstrap imports 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 through strapi.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 (.tmp in the playground), run config-sync import -y, then config-sync diff. Before this change the roles and the en locale are listed as Different, with documentId as the only change. With it there are no differences.

New tests in playground/__tests__/cli.test.js:

  • On a new database, import followed by diff shows no differences, and the exported role and locale files have no documentId.
  • A documentId left in a role or locale file from an older export doesn't make it Different.
  • Reversing the permissions in admin-role.strapi-editor and in user-role.public doesn't make them Different.

Ran yarn eslint and yarn test:integration locally (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 documentId until 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 its documentId is no longer reported. That change can't be imported anyway.

How to revert: revert the commit. Files exported without documentId keep working: the next export after the revert writes it back.

Related issue(s)/PR(s)

#190

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant