Skip to content

Commit

Permalink
Merge pull request #50 from bcc-code/auto-install-on-import
Browse files Browse the repository at this point in the history
Automatically install schema sync database on import
  • Loading branch information
u12206050 authored Sep 16, 2024
2 parents f7f34a2 + 66be525 commit c3c0602
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Once it is running, run the following command (from host) to install the extensi

```bash
// docker exec -it <container> <command>
docker-compose exec -it my-directus npx directus schema-sync install --force
docker compose exec -it my-directus npx directus schema-sync install --force
```

We are using force since we do want to replace the `schema-sync` folder already added as a volumn
Expand Down
11 changes: 11 additions & 0 deletions install/schema-sync/directus_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ export const syncDirectusCollections = {
sort: ['parent', 'id'],
},
},
/* directus_files: {
watch: ['files'],
excludeFields: [],
query: {
filter: {
storage: {
_eq: 'local',
},
}
},
},*/
directus_roles: {
watch: ['roles'],
linkedFields: ['parent'],
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
logger.info('Installing Schema sync...');
await updateManager.ensureInstalled();
await copyConfig(force, { logger });
(await exportManager()).exportAll();
await updateMeta();

logger.info('Done!');
process.exit(0);
Expand Down
10 changes: 10 additions & 0 deletions src/updateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export class UpdateManager {
if (this._locked || this._locking) return false;
this._locking = true;

// Don't lock if schema sync is not installed yet
const isInstalled = await this.db.schema.hasColumn(this.tableName, 'mv_hash');
if (!isInstalled) {
this._locking = false;
return true;
}

const succeeded = await this.db.transaction(async trx => {
const rows = await trx(this.tableName)
.select('*')
Expand Down Expand Up @@ -94,6 +101,7 @@ export class UpdateManager {
return true;
}


public async ensureInstalled() {
const tableName = 'directus_settings';

Expand All @@ -105,6 +113,8 @@ export class UpdateManager {
table.timestamp('mv_ts', { useTz: true }).defaultTo('2020-01-01').notNullable();
table.boolean('mv_locked').defaultTo(false).notNullable();
});
return true;
}
return false;
}
}

0 comments on commit c3c0602

Please sign in to comment.