code: def get_or_create_db(
      database_name: str,
      sqlalchemy_uri: str,
      always_create: bool | None = True,
  ) -> Database:
      # pylint: disable=import-outside-toplevel
      from superset import db
      from superset.models import core as models
  
      database = (
          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:
          logger.info(
              "Creating database reference for %s", database_name
          )
          database = models.Database(
              database_name=database_name, uuid=uuids.get(database_name)
          )
          db.session.add(database)
          database.set_sqlalchemy_uri(sqlalchemy_uri)
          db.session.commit()
  
      # todo: it's a bad idea to do an update in a get/create function
      if (
          database
          and database.sqlalchemy_uri_decrypted != sqlalchemy_uri
      ):
          database.set_sqlalchemy_uri(sqlalchemy_uri)
          db.session.commit()
  
      return database
  
file_path: superset/superset/utils/database.py
imports: from __future__ import annotations
  import logging
  from typing import TYPE_CHECKING
  from flask import current_app
  from superset.constants import EXAMPLES_DB_UUID
label_desc: Use image node_id 1 for calling a global function with example usage: get_or_create_db(database_name, sqlalchemy_uri, always_create) and returns: database