diff --git a/CHANGELOG.md b/CHANGELOG.md index b359edd..999914e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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'}` diff --git a/README.md b/README.md index 5ed1fff..6a60f1c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 0550ff2..689e2b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "directus-extension-schema-sync", - "version": "1.4.1", + "version": "1.4.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "directus-extension-schema-sync", - "version": "1.4.1", + "version": "1.4.2", "devDependencies": { "@directus/extensions-sdk": "10.1.11", "@directus/types": "^10.1.6", diff --git a/package.json b/package.json index 097219f..e0f19fa 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/index.ts b/src/index.ts index 35ec6b8..f98b4a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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); @@ -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 { @@ -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}`);