Skip to content

Commit f62fcd8

Browse files
committed
Tested with docker. Working.
1 parent 75535ec commit f62fcd8

File tree

7 files changed

+166
-5
lines changed

7 files changed

+166
-5
lines changed

extension.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ export default {
77
peerDependencies: true,
88
}),
99
],
10+
// Exclude native modules that cannot be bundled
11+
external: [/^@directus\/api/],
1012
};

install/schema-sync/directus_config.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ export const syncDirectusCollections = {
5555
excludeFields: ['id'],
5656
getKey: o => `${o.role ?? o.user ?? 'public'}-${o.policy}`,
5757
query: {
58-
sort: ['policy'],
58+
sort: ['role', 'policy'],
59+
filter: {
60+
user: { _null: true },
61+
},
5962
},
6063
},
6164
/* directus_users: {
@@ -101,25 +104,32 @@ export const syncDirectusCollections = {
101104
},
102105
directus_dashboards: {
103106
watch: ['dashboards'],
104-
excludeFields: ['user_created', 'panels'],
107+
excludeFields: ['user_created', 'date_created'],
108+
query: {
109+
sort: ['name'],
110+
},
105111
},
106112
directus_panels: {
107113
watch: ['panels'],
108-
excludeFields: ['user_created'],
114+
excludeFields: ['user_created', 'date_created'],
115+
query: {
116+
sort: ['dashboard', 'id'],
117+
},
109118
},
110119
directus_presets: {
111120
watch: ['presets'],
112121
excludeFields: ['id'],
113122
getKey: (o) => `${o.role ?? 'all'}-${o.collection}-${o.bookmark || 'default'}`,
114123
query: {
124+
sort: ['collection', 'bookmark'],
115125
filter: {
116126
user: { _null: true}
117127
}
118128
}
119129
},
120130
/*directus_flows: {
121131
watch: ['flows'],
122-
excludeFields: ['operations', 'user_created'],
132+
excludeFields: ['operations', 'user_created', 'date_created'],
123133
query: {
124134
filter: {
125135
trigger: { _neq: 'webhook' },
@@ -128,7 +138,7 @@ export const syncDirectusCollections = {
128138
},
129139
directus_operations: {
130140
watch: ['operations'],
131-
excludeFields: ['user_created'],
141+
excludeFields: ['user_created', 'date_created'],
132142
linkedFields: ['resolve', 'reject'],
133143
query: {
134144
filter: {

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
133133
}
134134

135135
init('cli.before', async ({ program }) => {
136+
if (program.commands.some(cmd => cmd.name() === 'schema-sync')) {
137+
logger.info('Already registered "schema-sync" command');
138+
return;
139+
}
136140
const dbCommand = program.command('schema-sync');
137141

138142
dbCommand

test/.dockerignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
node_modules
2+
dist
3+
.git
4+
.gitignore
5+
*.md
6+
*.png
7+
*.json
8+
!package.json
9+
!package-lock.json
10+
!extension.config.js
11+
!tsconfig.json
12+
.vscode
13+
.idea
14+
dist-test
15+
*.test.ts
16+
scripts
17+
test

test/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM directus/directus:11.14.0 AS base
2+
3+
USER root
4+
RUN corepack enable
5+
USER node
6+
7+
# Set working directory for extension
8+
WORKDIR /directus/extensions/directus-extension-schema-sync
9+
10+
# Copy package files (context is parent directory)
11+
COPY --chown=node:node package.json package-lock.json ./
12+
COPY --chown=node:node extension.config.js ./
13+
14+
# Copy source files
15+
COPY --chown=node:node dist/ ./dist
16+
17+
# Install the extension as a local package in the Directus node_modules
18+
WORKDIR /directus
19+
20+
RUN pnpm install ./extensions/directus-extension-schema-sync
21+
COPY --chown=node:node install/schema-sync/ ./schema-sync
22+
23+
RUN echo "Listing schema-sync directory:" && ls -la /directus/schema-sync
24+
25+
ENV ADMIN_EMAIL="[email protected]"
26+
ENV ADMIN_PASSWORD="admin"
27+
ENV DB_CLIENT="sqlite3"
28+
ENV DB_FILENAME="/directus/database/data.db"
29+
ENV SCHEMA_SYNC="NONE"

test/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Testing the Schema Sync Extension
2+
3+
This folder contains Docker configuration files for testing the `directus-extension-schema-sync` plugin locally.
4+
5+
## Quick Start
6+
7+
1. Build and start the container:
8+
```bash
9+
cd test
10+
docker-compose up --build
11+
```
12+
13+
2. After the container starts, install the extension's database columns:
14+
```bash
15+
docker-compose exec directus npx directus schema-sync install --force
16+
```
17+
18+
3. Access Directus at `http://localhost:8055`
19+
- Email: `[email protected]`
20+
- Password: `admin`
21+
22+
## Configuration
23+
24+
The `schema-sync` directory will be created in the project root and mounted as a volume. You can edit config files locally and they'll be available in the container.
25+
26+
Environment variables can be set in a `.env` file in the `test` directory or passed directly to `docker-compose`:
27+
28+
```bash
29+
SCHEMA_SYNC=BOTH docker-compose up
30+
```
31+
32+
## Using PostgreSQL
33+
34+
To use PostgreSQL instead of SQLite:
35+
36+
1. Uncomment the `postgres` service in `docker-compose.yml`
37+
2. Update the environment variables:
38+
```bash
39+
DB_CLIENT=pg
40+
DB_HOST=postgres
41+
DB_PORT=5432
42+
DB_DATABASE=directus
43+
DB_USER=directus
44+
DB_PASSWORD=directus
45+
```
46+
47+
## Notes
48+
49+
- The Dockerfile builds the extension from the local source code
50+
- Database and uploads are persisted in Docker volumes
51+
- The extension is automatically loaded when Directus starts

test/docker-compose.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
services:
2+
directus:
3+
build:
4+
context: ..
5+
dockerfile: test/Dockerfile
6+
container_name: directus-schema-sync-test
7+
ports:
8+
- "8055:8055"
9+
environment:
10+
KEY: ${KEY:-change-me-to-a-random-value}
11+
SECRET: ${SECRET:-change-me-to-a-random-value}
12+
ADMIN_EMAIL: ${ADMIN_EMAIL:[email protected]}
13+
ADMIN_PASSWORD: ${ADMIN_PASSWORD:-admin}
14+
DB_CLIENT: ${DB_CLIENT:-sqlite3}
15+
DB_FILENAME: /directus/database/data.db
16+
# Schema sync configuration
17+
SCHEMA_SYNC: ${SCHEMA_SYNC:-BOTH}
18+
SCHEMA_SYNC_SPLIT: ${SCHEMA_SYNC_SPLIT:-true}
19+
volumes:
20+
# Persist database
21+
- directus-database:/directus/database
22+
# Mount schema-sync data directory for persisted data files (config files come from image)
23+
- ../install/schema-sync:/directus/schema-sync
24+
# Optional: Mount uploads directory
25+
- directus-uploads:/directus/uploads
26+
restart: unless-stopped
27+
28+
# Optional: PostgreSQL database (uncomment to use instead of SQLite)
29+
# postgres:
30+
# image: postgres:16-alpine
31+
# container_name: directus-postgres
32+
# environment:
33+
# POSTGRES_USER: directus
34+
# POSTGRES_PASSWORD: directus
35+
# POSTGRES_DB: directus
36+
# volumes:
37+
# - postgres-data:/var/lib/postgresql/data
38+
# restart: unless-stopped
39+
# healthcheck:
40+
# test: ["CMD-SHELL", "pg_isready -U directus"]
41+
# interval: 10s
42+
# timeout: 5s
43+
# retries: 5
44+
45+
volumes:
46+
directus-database:
47+
directus-uploads:
48+
# postgres-data:

0 commit comments

Comments
 (0)