directus-sync icon indicating copy to clipboard operation
directus-sync copied to clipboard

Relations error when created without directus in version 3

Open Khartir opened this issue 1 year ago • 1 comments

Describe the bug I'm currently in the progress of upgrading to directus 11 and directus-sync 3. In our setup we use directus on top of an existing database, so directus is not primarily responsible for creating the schema, but we run directus-sync with the schema anyway to ensure we don't accidentally configure some schema changes. So far this has worked great. But there is a problem since the upgrade: In the CI directus is started on an empty database, then an external script runs to add the schema and then directus-sync runs. In this situation we now get an error Failed to create relation "x.y". The table x is not configured in directus at all. Until the upgrade this worked fine.

To Reproduce Steps to reproduce the behavior:

  1. Create a schema with relations which are not configured in directus.
  2. Run npx directus-sync pull.
  3. The relations are part of the dump.
  4. Create a completely new database.
  5. Start directus with this new database.
  6. Import the schema without directus-sync.
  7. Run npx directus-sync push.

Expected behavior No errors. With directus-sync 2.2/directus 10 this worked fine.

Versions (please complete the following information):

  • Directus-Sync version: [3.1.6]
  • Directus version: [11.3.3]
  • Directus environment [Docker]

Additional context The issue does not occur locally, where usually directus is started after the schema was created. I assume this is an issue with some missing caching or parsing that occurs in directus on startup. I assume this issue could be fixed by restarting the directus container after schema creation but that is unfortunately not possible in the CI. If this is not something you feel should be fixed, I would appreciate it if you could tell me if there is an endpoint or sdk-call we could make that has the same effect. (Assuming this is something you removed because it is generally not necessary).

Khartir avatar Dec 17 '24 10:12 Khartir

@Khartir I think this issue is related to Directus directly. Directus-Sync manage the schema by using the schema snapshot endpoints. Maybe you need to clear the system cache after changing the database : https://docs.directus.io/reference/system/utilities.html#clear-the-internal-cache

EdouardDem avatar Jan 16 '25 18:01 EdouardDem