tractr / directus-sync

A CLI tool for synchronizing the schema and configuration of Directus across various environments.
GNU General Public License v3.0
254 stars 10 forks source link

Error When Syncing New Folders Between Environments: "Value for field 'id' in collection 'directus_folders' has to be unique." #92

Closed Vahagn-Zaqaryan closed 1 month ago

Vahagn-Zaqaryan commented 3 months ago

Describe the Bug

I maintain both production and testing environments, and our content writers recently organized our media files into folders. When I first attempted to sync these folders between environments, everything worked smoothly. However, after they created a few additional folders, I encountered an error: Value for field "id" in collection "directus_folders" has to be unique.

To Reproduce

Steps to reproduce the issue:

  1. Set up two empty Directus instances.
  2. Create a folder in one of the instances.
  3. Sync the folder to the other instance.
  4. Create another folder.
  5. Attempt to sync the second folder, and you should encounter the following error:
ERROR (1918487):
    errors: [
      {
        "message": "Value for field \"id\" in collection \"directus_folders\" has to be unique.",
        "extensions": {
          "collection": "directus_folders",
          "field": "id",
          "code": "RECORD_NOT_UNIQUE"
        }
      }
    ]
    response: {}

Expected Behavior

The synchronization should complete without any issues.

Versions

Additional Context

First, I want to express my gratitude for creating and maintaining this repository. It has saved us months of work, and I'm eager to assist in making it even better! 🚀

If you need any further information, please don't hesitate to ask.

NilsBaumgartner1994 commented 2 months ago

Having the same bug

NilsBaumgartner1994 commented 2 months ago

Our workaround: -pull from the server

emhoracek commented 1 month ago

My team is also having this issue. Unfortunately @NilsBaumgartner1994's fix didn't work for us, so we're a bit stuck. We're using Directus 11.1.1 and directus-sync 3.1.4. Happy to provide any additional info that might be useful.

EdouardDem commented 1 month ago

@Vahagn-Zaqaryan Thank you for your words. I will dive into this issue. When you say Create another folder., is it a standalone folder or is it a subfolder of the first one ?

pichot commented 1 month ago

Bonjour @EdouardDem,

Following up on my colleague @emhoracek's message, and to your question, in our case directus-sync is trying to create a standalone folder that doesn't exist on the destination Directus instance. The npx directus-sync push command ends in an error. Curiously, the folder DOES get created, though subsequent npx directus-sync push commands result in the same error.

On the terminal, we get:

[11:44:30.325] INFO (78575): ---- Push schema ----
[11:44:32.530] INFO (78575): [snapshot] Changes applied
[11:44:32.537] INFO (78575): ---- Clean up collections ----
[11:44:32.690] INFO (78575): [settings] Deleted 0 dangling items
[11:44:32.844] INFO (78575): [folders] Deleted 0 dangling items
[11:44:32.867] INFO (78575): [translations] Deleted 0 dangling items
[11:44:32.932] INFO (78575): [flows] Deleted 0 dangling items
[11:44:32.984] INFO (78575): [operations] Deleted 0 dangling items
[11:44:33.244] INFO (78575): [roles] Deleted 0 dangling items
[11:44:33.560] INFO (78575): [policies] Deleted 0 dangling items
[11:44:35.602] INFO (78575): [permissions] Deleted 0 dangling items
[11:44:35.632] INFO (78575): [dashboards] Deleted 0 dangling items
[11:44:35.669] INFO (78575): [panels] Deleted 0 dangling items
[11:44:35.704] INFO (78575): [presets] Deleted 0 dangling items
[11:44:35.704] INFO (78575): ---- Push: iteration 1 ----
[11:44:35.971] INFO (78575): [settings] Created 1 items
[11:44:35.971] INFO (78575): [settings] Updated 0 items
[11:44:36.127] ERROR (78575):
    errors: [
      {
        "message": "Value for field \"id\" in collection \"directus_folders\" has to be unique.",
        "extensions": {
          "collection": "directus_folders",
          "field": "id",
          "code": "RECORD_NOT_UNIQUE"
        }
      }
    ]
    response: {}

The destination Directus instance logs:

2024-10-24 11:44:35 [09:44:35] GET /directus-extension-sync/table/folders/sync_id/1f646d53-adaf-4691-986e-c1f409a767ec 404 6ms
2024-10-24 11:44:35 [09:44:35] GET /directus-extension-sync/table/folders/sync_id/42002c64-89bb-45dd-af3d-64150ad755e7 404 10ms
2024-10-24 11:44:36 [09:44:36] GET /directus-extension-sync/table/folders/sync_id/5e4557b9-8b9a-4b1e-adc2-5582742d62b0 404 12ms
2024-10-24 11:44:36 [09:44:36] GET /directus-extension-sync/table/folders/sync_id/b5f9d7fd-e9bc-416d-af53-20ee5c0b129f 404 6ms
2024-10-24 11:44:36 [09:44:36] GET /directus-extension-sync/table/folders/sync_id/df21e0e7-c3ce-4944-adc2-1bb408fa5cc7 404 6ms
2024-10-24 11:44:36 [09:44:36] GET /directus-extension-sync/table/folders/sync_id/e4f3e4e8-d0b2-400d-9352-18ef74ef4240 404 7ms
2024-10-24 11:44:36 [09:44:36] GET /directus-extension-sync/table/folders/sync_id/ee7b3cbf-f444-44a2-9b35-c28c70e5a9bc 404 8ms
2024-10-24 11:44:36 [09:44:36] GET /directus-extension-sync/table/folders 200 8ms
2024-10-24 11:44:36 [09:44:36] GET /directus-extension-sync/table/folders 200 10ms
2024-10-24 11:44:36 [09:44:36] POST /folders 200 25ms
2024-10-24 11:44:36 [09:44:36] POST /directus-extension-sync/table/folders 201 8ms
2024-10-24 11:44:36 [09:44:36] POST /folders 400 17ms

Thanks for any help!