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
- Configure schema-sync with a custom collection in
config.js
- Export schema + data from a working instance
- Tear down the environment with
docker compose down -v (removing volumes for a clean database)
- Start fresh with
docker compose up -d — Directus boots, schema-sync runs via SCHEMA_SYNC=BOTH in the app.before hook
- 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
Describe the Bug
Description
When using
SCHEMA_SYNC=BOTHon 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
Setup
SCHEMA_SYNC=BOTHSCHEMA_SYNC_MERGE=trueSCHEMA_SYNC_SPLIT=false/directus/schema-syncConfig
config.js (custom collections):
directus_config.js syncs:
directus_folders,directus_roles,directus_policies,directus_permissions,directus_access,directus_settings,directus_users— all withgetKeyby name,onExport/onImportresolvers for UUID→name mapping, andSCHEMA_SYNC_MERGE=true.To Reproduce
Dockerfile
Docker Compose (minimal reproduction)
The key part is the bind-mount
./backend/schema-sync:/directus/schema-syncwithSCHEMA_SYNC=BOTHin the env file.Steps to Reproduce
config.jsdocker compose down -v(removing volumes for a clean database)docker compose up -d— Directus boots, schema-sync runs viaSCHEMA_SYNC=BOTHin theapp.beforehookSchema for [collection] not foundVersion
3.3.1
Installed Extension Via
Docker file