def _export(model: Database) -> Iterator[Tuple[str, str]]: database_slug = secure_filename(model.database_name) file_name = f"databases/{database_slug}.yaml" payload = model.export_to_dict( recursive=False, include_parent_ref=False, include_defaults=True, export_uuids=True, ) # TODO (betodealmeida): move this logic to export_to_dict once this # becomes the default export endpoint if payload.get("extra"): payload["extra"] = parse_extra(payload["extra"]) payload["version"] = EXPORT_VERSION file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content for dataset in model.tables: dataset_slug = secure_filename(dataset.table_name) file_name = f"datasets/{database_slug}/{dataset_slug}.yaml" payload = dataset.export_to_dict( recursive=True, include_parent_ref=False, include_defaults=True, export_uuids=True, ) payload["version"] = EXPORT_VERSION payload["database_uuid"] = str(model.uuid) file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content
def _export(model: Database, export_related: bool = True) -> Iterator[Tuple[str, str]]: database_slug = secure_filename(model.database_name) file_name = f"databases/{database_slug}.yaml" payload = model.export_to_dict( recursive=False, include_parent_ref=False, include_defaults=True, export_uuids=True, ) # https://github.com/apache/superset/pull/16756 renamed ``allow_csv_upload`` # to ``allow_file_upload`, but we can't change the V1 schema replacements = {"allow_file_upload": "allow_csv_upload"} # this preserves key order, which is important payload = { replacements.get(key, key): value for key, value in payload.items() } # TODO (betodealmeida): move this logic to export_to_dict once this # becomes the default export endpoint if payload.get("extra"): extra = payload["extra"] = parse_extra(payload["extra"]) # ``schemas_allowed_for_csv_upload`` was also renamed to # ``schemas_allowed_for_file_upload``, we need to change to preserve the # V1 schema if "schemas_allowed_for_file_upload" in extra: extra["schemas_allowed_for_csv_upload"] = extra.pop( "schemas_allowed_for_file_upload") payload["version"] = EXPORT_VERSION file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content if export_related: for dataset in model.tables: dataset_slug = secure_filename(dataset.table_name) file_name = f"datasets/{database_slug}/{dataset_slug}.yaml" payload = dataset.export_to_dict( recursive=True, include_parent_ref=False, include_defaults=True, export_uuids=True, ) payload["version"] = EXPORT_VERSION payload["database_uuid"] = str(model.uuid) file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content
def export_database(database: Database) -> Iterator[Tuple[str, str]]: name = sanitize(database.database_name) file_name = f"databases/{name}.yaml" payload = database.export_to_dict( recursive=False, include_parent_ref=False, include_defaults=True, export_uuids=True, ) # TODO (betodealmeida): move this logic to export_to_dict once this # becomes the default export endpoint if "extra" in payload: try: payload["extra"] = json.loads(payload["extra"]) except json.decoder.JSONDecodeError: pass payload["version"] = IMPORT_EXPORT_VERSION file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content # TODO (betodealmeida): reuse logic from ExportDatasetCommand once # it's implemented for dataset in database.tables: name = sanitize(dataset.table_name) file_name = f"datasets/{name}.yaml" payload = dataset.export_to_dict( recursive=True, include_parent_ref=False, include_defaults=True, export_uuids=True, ) payload["version"] = IMPORT_EXPORT_VERSION payload["database_uuid"] = str(database.uuid) file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content
def _export(model: Database) -> Iterator[Tuple[str, str]]: database_slug = secure_filename(model.database_name) file_name = f"databases/{database_slug}.yaml" payload = model.export_to_dict( recursive=False, include_parent_ref=False, include_defaults=True, export_uuids=True, ) # TODO (betodealmeida): move this logic to export_to_dict once this # becomes the default export endpoint if "extra" in payload: try: payload["extra"] = json.loads(payload["extra"]) except json.decoder.JSONDecodeError: logger.info("Unable to decode `extra` field: %s", payload["extra"]) payload["version"] = EXPORT_VERSION file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content for dataset in model.tables: dataset_slug = secure_filename(dataset.table_name) file_name = f"datasets/{database_slug}/{dataset_slug}.yaml" payload = dataset.export_to_dict( recursive=True, include_parent_ref=False, include_defaults=True, export_uuids=True, ) payload["version"] = EXPORT_VERSION payload["database_uuid"] = str(model.uuid) file_content = yaml.safe_dump(payload, sort_keys=False) yield file_name, file_content