feat: add portal app config sync commands
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from workflows.app_registry_sync import export_portal_app_config_payload, write_portal_app_config_export
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Export PortalAppConfig to JSON for environment sync.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('--output', help='Write the export to a file instead of stdout.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
output = options.get('output')
|
||||
if output:
|
||||
path = write_portal_app_config_export(output)
|
||||
self.stdout.write(self.style.SUCCESS(f'Exported PortalAppConfig to {path}'))
|
||||
return
|
||||
|
||||
payload = export_portal_app_config_payload()
|
||||
import json
|
||||
|
||||
self.stdout.write(json.dumps(payload, indent=2, default=str))
|
||||
@@ -0,0 +1,25 @@
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from workflows.app_registry_sync import import_portal_app_config_payload, load_portal_app_config_payload
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Import PortalAppConfig JSON for environment sync.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('input', help='Path to a previously exported PortalAppConfig JSON file.')
|
||||
parser.add_argument('--dry-run', action='store_true', help='Validate and report changes without saving.')
|
||||
|
||||
def handle(self, *args, **options):
|
||||
try:
|
||||
payload = load_portal_app_config_payload(options['input'])
|
||||
summary = import_portal_app_config_payload(payload, dry_run=options['dry_run'])
|
||||
except (OSError, ValueError) as exc:
|
||||
raise CommandError(str(exc)) from exc
|
||||
|
||||
mode = 'Dry run' if options['dry_run'] else 'Import'
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{mode} complete. total={summary['total']} updated={summary['updated']} created={summary['created']}"
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user