Skip to content

Commit

Permalink
Add cli commands for schema only
Browse files Browse the repository at this point in the history
  • Loading branch information
u12206050 committed Nov 15, 2023
1 parent c1de365 commit 8d0a2b1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Version 1.4.1
# Version 1.4.2

- Add `import-schema` and `export-schema` commands to import/export only the schema.

## Version 1.4.1

- Fixed config for `directus_presets` getKey should be `${o.role ?? 'all'}-${o.collection}-${o.bookmark || 'default'}` instead of `${o.role ?? 'all'}-${o.collection}-${o.name || 'default'}`

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ Besides auto importing and exporting, you can also run the commands manually.
| `import` | Import the schema and data to the Directus API (options: `merge`) |
| `hash`| Recalculate the hash for all the data files (already happens after export) |
| `install` | Install the extension's columns in the database and add the config folder (options: `force`) |
| `export-schema` | Export only the schema |
| `import-schema` | Import only the schema |

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "directus-extension-schema-sync",
"description": "Sync schema and data betwreen Directus instances",
"icon": "sync_alt",
"version": "1.4.1",
"version": "1.4.2",
"repository": {
"type": "git",
"url": "https://github.com/bcc-code/directus-schema-sync.git"
Expand Down
32 changes: 29 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,38 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab
init('cli.before', async ({ program }) => {
const dbCommand = program.command('schema-sync');

dbCommand
.command('export-schema')
.description('Export only the schema file')
.action(async () => {
logger.info('Exporting schema...');
const exportSchema = new SchemaExporter(getSchemaService, logger);
await exportSchema.export();

await updateMeta();

logger.info('Done!');
process.exit(0);
});

dbCommand
.command('import-schema')
.description('Import only the schema file')
.action(async () => {
logger.info('Importing schema...');
const exportSchema = new SchemaExporter(getSchemaService, logger);
await exportSchema.load();

logger.info('Done!');
process.exit(0);
});

dbCommand
.command('install')
.description('Ensures the DB is ready for schema sync, and creates the schema-sync config folder')
.option('--force', 'Override schema-sync config folder')
.action(async ({ force }: { force: boolean }) => {
console.log('Installing Schema sync...');
logger.info('Installing Schema sync...');
await updateManager.ensureInstalled();
await copyConfig(force);

Expand All @@ -130,7 +156,7 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab

dbCommand
.command('import')
.description('Import all the available data from file to DB.')
.description('Import the schema and all available data from file to DB.')
.option('--merge', 'Only upsert data and not delete')
.action(async ({ merge }: { merge: boolean }) => {
try {
Expand All @@ -148,7 +174,7 @@ const registerHook: HookConfig = async ({ action, init }, { env, services, datab

dbCommand
.command('export')
.description('Export all data as configured from DB to file')
.description('Export the schema and all data as configured from DB to file')
.action(async () => {
try {
logger.info(`Exporting everything to: ${ExportHelper.dataDir}`);
Expand Down

0 comments on commit 8d0a2b1

Please sign in to comment.