mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
feat: confirm overwrite when importing (#11982)
* feat: confirm overwrite when importing * Skip flaky test
This commit is contained in:
@@ -744,11 +744,19 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
|
||||
---
|
||||
post:
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/zip:
|
||||
multipart/form-data:
|
||||
schema:
|
||||
type: string
|
||||
format: binary
|
||||
type: object
|
||||
properties:
|
||||
formData:
|
||||
type: string
|
||||
format: binary
|
||||
passwords:
|
||||
type: string
|
||||
overwrite:
|
||||
type: bool
|
||||
responses:
|
||||
200:
|
||||
description: Database import result
|
||||
@@ -782,8 +790,11 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
|
||||
if "passwords" in request.form
|
||||
else None
|
||||
)
|
||||
overwrite = request.form.get("overwrite") == "true"
|
||||
|
||||
command = ImportDatabasesCommand(contents, passwords=passwords)
|
||||
command = ImportDatabasesCommand(
|
||||
contents, passwords=passwords, overwrite=overwrite
|
||||
)
|
||||
try:
|
||||
command.run()
|
||||
return self.response(200, message="OK")
|
||||
|
||||
@@ -35,6 +35,7 @@ class ImportDatabasesCommand(ImportModelsCommand):
|
||||
|
||||
dao = DatabaseDAO
|
||||
model_name = "database"
|
||||
prefix = "databases/"
|
||||
schemas: Dict[str, Schema] = {
|
||||
"databases/": ImportV1DatabaseSchema(),
|
||||
"datasets/": ImportV1DatasetSchema(),
|
||||
@@ -42,12 +43,14 @@ class ImportDatabasesCommand(ImportModelsCommand):
|
||||
import_error = DatabaseImportError
|
||||
|
||||
@staticmethod
|
||||
def _import(session: Session, configs: Dict[str, Any]) -> None:
|
||||
def _import(
|
||||
session: Session, configs: Dict[str, Any], overwrite: bool = False
|
||||
) -> None:
|
||||
# first import databases
|
||||
database_ids: Dict[str, int] = {}
|
||||
for file_name, config in configs.items():
|
||||
if file_name.startswith("databases/"):
|
||||
database = import_database(session, config, overwrite=True)
|
||||
database = import_database(session, config, overwrite=overwrite)
|
||||
database_ids[str(database.uuid)] = database.id
|
||||
|
||||
# import related datasets
|
||||
|
||||
Reference in New Issue
Block a user