Skip to content

Schema for [collection] not found on custom collection data import #110

@Brkns93

Description

@Brkns93

Describe the Bug

Description

When using SCHEMA_SYNC=BOTH on a fresh database, the extension successfully applies the schema diff (creating custom collection tables) but then fails to load custom collection data because the in-memory schema cache is stale.

System/directus collections (folders, roles, policies, etc.) load fine because they already exist in the cached schema. Custom collections that were just created by the schema diff are not in the cache, causing the error.

Error

INFO: Applying schema diff...
INFO: Schema updated
DEBUG: Inserting 1 x directus_folders items
DEBUG: Inserting 3 x directus_roles items
DEBUG: Inserting 2 x directus_policies items
DEBUG: Inserting 116 x directus_permissions items
DEBUG: Inserting 3 x directus_access items
DEBUG: Updating 1 x directus_settings items
DEBUG: Inserting 1 x directus_users items
ERROR: Failed loading "subscription_policies".
ERROR: Schema for subscription_policies not found

Setup

  • directus-extension-schema-sync: 3.3.1
  • Directus: 11.14.1
  • Database: PostgreSQL
  • Environment:
    • SCHEMA_SYNC=BOTH
    • SCHEMA_SYNC_MERGE=true
    • SCHEMA_SYNC_SPLIT=false
  • Deployment: Docker Compose with schema-sync directory bind-mounted to /directus/schema-sync

Config

config.js (custom collections):

export const syncCustomCollections = {
  subscription_policies: {
    watch: ['subscription_policies.items'],
    excludeFields: ['id', 'user_created', 'user_updated'],
    getKey: (o) => o.name,
    query: {
      sort: ['name'],
    },
  },
};

directus_config.js syncs: directus_folders, directus_roles, directus_policies, directus_permissions, directus_access, directus_settings, directus_users — all with getKey by name, onExport/onImport resolvers for UUID→name mapping, and SCHEMA_SYNC_MERGE=true.

To Reproduce

Dockerfile

FROM directus/directus:11.14.1

USER node
RUN printf '%s\n' \
  'only-built-dependencies[]=argon2' \
  'only-built-dependencies[]=better-sqlite3' \
  'only-built-dependencies[]=canvas' \
  'only-built-dependencies[]=esbuild' \
  'only-built-dependencies[]=isolated-vm' \
  'only-built-dependencies[]=oracledb' \
  'only-built-dependencies[]=pg' \
  'only-built-dependencies[]=sharp' \
  'only-built-dependencies[]=sqlite3' \
  'only-built-dependencies[]=vue-demi' \
  > .npmrc

RUN pnpm install directus-extension-schema-sync@3.3.1 --force

Docker Compose (minimal reproduction)

services:
  directus:
    build:
      context: ./backend/docker
      dockerfile: Dockerfile.local
    ports:
      - "8055:8055"
    volumes:
      - ./backend/schema-sync:/directus/schema-sync
    env_file:
      - ./env/directus.env
    depends_on:
      postgres:
        condition: service_healthy

  postgres:
    image: postgres:17-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: directus
      POSTGRES_PASSWORD: directus
      POSTGRES_DB: directus
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  postgres_data:

The key part is the bind-mount ./backend/schema-sync:/directus/schema-sync with SCHEMA_SYNC=BOTH in the env file.

Steps to Reproduce

  1. Configure schema-sync with a custom collection in config.js
  2. Export schema + data from a working instance
  3. Tear down the environment with docker compose down -v (removing volumes for a clean database)
  4. Start fresh with docker compose up -d — Directus boots, schema-sync runs via SCHEMA_SYNC=BOTH in the app.before hook
  5. The schema diff applies successfully, system collection data loads, but custom collection data fails with Schema for [collection] not found

Version

3.3.1

Installed Extension Via

Docker file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions