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

Automatic Import not working #10

Closed Natetronn closed 5 months ago

Natetronn commented 6 months ago

Describe the Bug

Honestly, I'm not sure if it's a bug or if it's something on my end, but automatic import doesn't work, even with SCHEMA_SYNC set to BOTH.

Note: I tried both SCHEMA_SYNC: "BOTH" and SCHEMA_SYNC: BOTH too. This after destroying the instance and starting it fresh to make sure the change was indeed set.

Manual importing using the cli does work, however. Auto export also works; when creating or updating items in the same collection, I see the changes locally in the json files.

I'm using SQLite to test with. This is my docker-compose.yml and Dockerfile for testing purposes. I'm on Linux. I opened up all file/folder permissions wide, since it was for testing:

docker-compose.yml

version: "3"
services:
  directus:
    # image: directus/directus:10.8.3
    build:
      context: ./
    container_name: schema-sync-extenstion
    ports:
      - 8077:8055
    volumes:
      - ./database:/directus/database
      - ./uploads:/directus/uploads
      - ./extensions:/directus/extensions
      - ./schema-sync:/directus/schema-sync
    environment:
      KEY: "b8df1afc-6257-43a7-a5e0-55274b3425c1"
      SECRET: "dfce0a6d-267b-4970-b7b8-45b4e89665a3"
      ADMIN_EMAIL: "admin@example.com"
      ADMIN_PASSWORD: "123"
      DB_CLIENT: "sqlite3"
      DB_FILENAME: "/directus/database/data.db"
      WEBSOCKETS_ENABLED: true
      SCHEMA_SYNC: "BOTH"

Dockerfile

FROM directus/directus:10.8.3

USER root
RUN corepack enable
USER node

RUN pnpm install directus-extension-schema-sync
COPY ./schema-sync ./schema-sync

To Reproduce

After installing directus-schema-sync, per the docs, including making the tables etc, making sure SCHEMA_SYNC is set to BOTH and making sure permissions and everything else is in working order, create a collection with at least one input field and create an item or two. Make sure this collection is in the config.js file and ready to go per the example and comments in that file.

Then try running an export automatically by creating new items. You should see the collection's json file was exported with the items in the collection, along with the other files for directus system tables and a schema file too. Now, edit the collection's json file by adding a new item to the object, with a new id and some new data in the field/s, and then save the file. You'd expect to see the changes made in the Studio App at this point, since it should be automated and see the new item listed with the others, but that's not the case.

Note: after that we tried restarting the docker container to see if helped, but it didn't seem to. We also tried a empty cache and hard reload in the browser as well.

You can see that importing via the cli does in fact work by running the npx directus schema-sync import and this does import the changes, so importing can work at least. It's only the auto importing that isn't working, at least in our case.

Version

1.6.1

Installed Extension Via

Docker file

u12206050 commented 6 months ago

AH I see where the misunderstanding comes it. So when you edit a json file directly, you will need to recalculate the hash by running the npx directus schema-sync hash command. This will update the hash.txt file so the plugin knows a change has actually occurred. NOTE: This will only import the new data on the next server start up.

u12206050 commented 5 months ago

I assume the solution I mentioned worked. Let me know then we can reopen the issue