mirror of
https://github.com/apache/superset.git
synced 2024-09-17 11:09:47 -04:00
chore: set UUID of examples DB (#15724)
This commit is contained in:
parent
2d0056507b
commit
eeba326f8b
@ -70,7 +70,7 @@ class ImportExamplesCommand(ImportModelsCommand):
|
|||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
raise self.import_error()
|
raise self.import_error()
|
||||||
|
|
||||||
# pylint: disable=too-many-locals, arguments-differ
|
# pylint: disable=too-many-locals, arguments-differ, too-many-branches
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _import(
|
def _import(
|
||||||
session: Session,
|
session: Session,
|
||||||
@ -86,16 +86,23 @@ class ImportExamplesCommand(ImportModelsCommand):
|
|||||||
database_ids[str(database.uuid)] = database.id
|
database_ids[str(database.uuid)] = database.id
|
||||||
|
|
||||||
# import datasets
|
# import datasets
|
||||||
# TODO (betodealmeida): once we have all examples being imported we can
|
# If database_uuid is not in the list of UUIDs it means that the examples
|
||||||
# have a stable UUID for the database stored in the dataset YAML; for
|
# database was created before its UUID was frozen, so it has a random UUID.
|
||||||
# now we need to fetch the current ID.
|
# We need to determine its ID so we can point the dataset to it.
|
||||||
examples_id = (
|
examples_db = (
|
||||||
db.session.query(Database).filter_by(database_name="examples").one().id
|
db.session.query(Database).filter_by(database_name="examples").first()
|
||||||
)
|
)
|
||||||
dataset_info: Dict[str, Dict[str, Any]] = {}
|
dataset_info: Dict[str, Dict[str, Any]] = {}
|
||||||
for file_name, config in configs.items():
|
for file_name, config in configs.items():
|
||||||
if file_name.startswith("datasets/"):
|
if file_name.startswith("datasets/"):
|
||||||
config["database_id"] = examples_id
|
# find the ID of the corresponding database
|
||||||
|
if config["database_uuid"] not in database_ids:
|
||||||
|
if examples_db is None:
|
||||||
|
raise Exception("Cannot find examples database")
|
||||||
|
config["database_id"] = examples_db.id
|
||||||
|
else:
|
||||||
|
config["database_id"] = database_ids[config["database_uuid"]]
|
||||||
|
|
||||||
dataset = import_dataset(
|
dataset = import_dataset(
|
||||||
session, config, overwrite=overwrite, force_data=force_data
|
session, config, overwrite=overwrite, force_data=force_data
|
||||||
)
|
)
|
||||||
|
@ -21,6 +21,10 @@
|
|||||||
NULL_STRING = "<NULL>"
|
NULL_STRING = "<NULL>"
|
||||||
|
|
||||||
|
|
||||||
|
# UUID for the examples database
|
||||||
|
EXAMPLES_DB_UUID = "a2dc77af-e654-49bb-b321-40f6b559a1ee"
|
||||||
|
|
||||||
|
|
||||||
class RouteMethod: # pylint: disable=too-few-public-methods
|
class RouteMethod: # pylint: disable=too-few-public-methods
|
||||||
"""
|
"""
|
||||||
Route methods are a FAB concept around ModelView and RestModelView
|
Route methods are a FAB concept around ModelView and RestModelView
|
||||||
|
@ -73,4 +73,4 @@ columns:
|
|||||||
description: null
|
description: null
|
||||||
python_date_format: null
|
python_date_format: null
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
database_uuid: 566ca280-3da8-967e-4aa4-4b349218736a
|
database_uuid: a2dc77af-e654-49bb-b321-40f6b559a1ee
|
||||||
|
@ -85,6 +85,7 @@ from typing_extensions import TypedDict
|
|||||||
|
|
||||||
import _thread # pylint: disable=C0411
|
import _thread # pylint: disable=C0411
|
||||||
from superset.constants import (
|
from superset.constants import (
|
||||||
|
EXAMPLES_DB_UUID,
|
||||||
EXTRA_FORM_DATA_APPEND_KEYS,
|
EXTRA_FORM_DATA_APPEND_KEYS,
|
||||||
EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS,
|
EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS,
|
||||||
EXTRA_FORM_DATA_OVERRIDE_REGULAR_MAPPINGS,
|
EXTRA_FORM_DATA_OVERRIDE_REGULAR_MAPPINGS,
|
||||||
@ -1168,9 +1169,16 @@ def get_or_create_db(
|
|||||||
db.session.query(models.Database).filter_by(database_name=database_name).first()
|
db.session.query(models.Database).filter_by(database_name=database_name).first()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# databases with a fixed UUID
|
||||||
|
uuids = {
|
||||||
|
"examples": EXAMPLES_DB_UUID,
|
||||||
|
}
|
||||||
|
|
||||||
if not database and always_create:
|
if not database and always_create:
|
||||||
logger.info("Creating database reference for %s", database_name)
|
logger.info("Creating database reference for %s", database_name)
|
||||||
database = models.Database(database_name=database_name)
|
database = models.Database(
|
||||||
|
database_name=database_name, uuid=uuids.get(database_name)
|
||||||
|
)
|
||||||
db.session.add(database)
|
db.session.add(database)
|
||||||
|
|
||||||
if database:
|
if database:
|
||||||
|
Loading…
Reference in New Issue
Block a user