bcc-code / directus-schema-sync

The better way to sync your Directus schema and data between environments
Apache License 2.0
90 stars 4 forks source link

Invalid Payload. "collection" is required. #45

Open boring-joey opened 3 weeks ago

boring-joey commented 3 weeks ago

Describe the Bug

When running the migrations in our acceptance environment, we encounter an error indicating that one of the JSON collections is missing a 'collection' field. This is our interpretation of the error message. We have reviewed the JSON files, and all of them include a 'collection' field.

Do you have any insights into what might be causing this issue or suggestions on how we can better debug it?

Error log:

[19:09:54.921] INFO: Importing schema...
[19:09:54.950] INFO: Stitched 59 partial schema files
<ref *1> Error [DirectusError]: Invalid payload. "collection" is required.
    at CollectionsService.createOne (file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_nogpcmhnljm46iilmpvjfvq4be/node_modules/@directus/api/dist/services/collections.js:43:19)
    at createCollections (file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_nogpcmhnljm46iilmpvjfvq4be/node_modules/@directus/api/dist/utils/apply-diff.js:52:50)
    at file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_nogpcmhnljm46iilmpvjfvq4be/node_modules/@directus/api/dist/utils/apply-diff.js:124:15
    at file:///directus/node_modules/.pnpm/@directus+api@file+api_@aws-sdk+client-sso-oidc@3.569.0_@aws-sdk+client-sts@3.569.0_@types+no_nogpcmhnljm46iilmpvjfvq4be/node_modules/@directus/api/dist/utils/transaction.js:17:52
    at /directus/node_modules/.pnpm/knex@3.1.0_pg@8.11.5/node_modules/knex/lib/execution/transaction.js:233:22
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  extensions: { reason: '"collection" is required' },
  code: 'INVALID_PAYLOAD',
  status: 400,
  originalError: [Circular *1]
}
[19:09:56.282] ERROR: Failed to create collection "dbl_section_newsletter"

Our JSON file:

{
  "collection": "dbl_section_newsletter",
  "meta": {
    "accountability": "all",
    "archive_app_filter": true,
    "archive_field": null,
    "archive_value": null,
    "collapse": "open",
    "collection": "dbl_section_newsletter",
    "color": "#6644FF",
    "display_template": null,
    "group": "Sections",
    "hidden": false,
 ....

To Reproduce

We use the command: npx directus schema-sync import on our docker container.

Version

2.1.2

Installed Extension Via

Docker file

u12206050 commented 2 weeks ago

Hmm very interesting... is this on a new db or an existing one?

boring-joey commented 2 weeks ago

It’s on a existing database and the collection ‘ dbl_section_newsletter’ already exists on both databases

u12206050 commented 2 weeks ago

Hmm, so it is trying to recreate a collection even though it already exists. This library just uses the default schema apply functionality of Directus, and by the looks of the log that does seem to be where it is failing, so not much I am able to do yet.

Could you test if it works if you disable the schema split option. If it then still fails we know 100% the issue is within Directus schema diff apply, otherwise if it works, then it might be in the way the split schema files are joined together again, it may be possible the ordering of it could affect the import.

boring-joey commented 2 weeks ago

I will check that and update the status here. Another strange part is that when i remove the failing table 'dbl_section_newsletter' in the target database it will create the table but won't add any fields in it.