chore: isolate examples database by default (#25003)
This commit is contained in:
parent
10abb68288
commit
269c99293f
|
|
@ -47,6 +47,7 @@ services:
|
||||||
- "127.0.0.1:5432:5432"
|
- "127.0.0.1:5432:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- db_home:/var/lib/postgresql/data
|
- db_home:/var/lib/postgresql/data
|
||||||
|
- ./docker/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
|
||||||
|
|
||||||
superset:
|
superset:
|
||||||
env_file: docker/.env
|
env_file: docker/.env
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,12 @@ DATABASE_HOST=db
|
||||||
DATABASE_PASSWORD=superset
|
DATABASE_PASSWORD=superset
|
||||||
DATABASE_USER=superset
|
DATABASE_USER=superset
|
||||||
|
|
||||||
|
EXAMPLES_DB=examples
|
||||||
|
EXAMPLES_HOST=db
|
||||||
|
EXAMPLES_USER=examples
|
||||||
|
EXAMPLES_PASSWORD=examples
|
||||||
|
EXAMPLES_PORT=5432
|
||||||
|
|
||||||
# database engine specific environment variables
|
# database engine specific environment variables
|
||||||
# change the below if you prefer another database engine
|
# change the below if you prefer another database engine
|
||||||
DATABASE_PORT=5432
|
DATABASE_PORT=5432
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
# Creates the examples database and repective user. This database location
|
||||||
|
# and access credentials are defined on the environment variables
|
||||||
|
# ------------------------------------------------------------------------
|
||||||
|
set -e
|
||||||
|
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER}" <<-EOSQL
|
||||||
|
CREATE USER ${EXAMPLES_USER} WITH PASSWORD '${EXAMPLES_PASSWORD}';
|
||||||
|
CREATE DATABASE ${EXAMPLES_DB};
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE ${EXAMPLES_DB} TO ${EXAMPLES_USER};
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "${POSTGRES_USER}" -d "${EXAMPLES_DB}" <<-EOSQL
|
||||||
|
GRANT ALL ON SCHEMA public TO ${EXAMPLES_USER};
|
||||||
|
EOSQL
|
||||||
|
|
@ -51,14 +51,24 @@ DATABASE_HOST = get_env_variable("DATABASE_HOST")
|
||||||
DATABASE_PORT = get_env_variable("DATABASE_PORT")
|
DATABASE_PORT = get_env_variable("DATABASE_PORT")
|
||||||
DATABASE_DB = get_env_variable("DATABASE_DB")
|
DATABASE_DB = get_env_variable("DATABASE_DB")
|
||||||
|
|
||||||
|
EXAMPLES_USER = get_env_variable("EXAMPLES_USER")
|
||||||
|
EXAMPLES_PASSWORD = get_env_variable("EXAMPLES_PASSWORD")
|
||||||
|
EXAMPLES_HOST = get_env_variable("EXAMPLES_HOST")
|
||||||
|
EXAMPLES_PORT = get_env_variable("EXAMPLES_PORT")
|
||||||
|
EXAMPLES_DB = get_env_variable("EXAMPLES_DB")
|
||||||
|
|
||||||
|
|
||||||
# The SQLAlchemy connection string.
|
# The SQLAlchemy connection string.
|
||||||
SQLALCHEMY_DATABASE_URI = "{}://{}:{}@{}:{}/{}".format(
|
SQLALCHEMY_DATABASE_URI = (
|
||||||
DATABASE_DIALECT,
|
f"{DATABASE_DIALECT}://"
|
||||||
DATABASE_USER,
|
f"{DATABASE_USER}:{DATABASE_PASSWORD}@"
|
||||||
DATABASE_PASSWORD,
|
f"{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_DB}"
|
||||||
DATABASE_HOST,
|
)
|
||||||
DATABASE_PORT,
|
|
||||||
DATABASE_DB,
|
SQLALCHEMY_EXAMPLES_URI = (
|
||||||
|
f"{DATABASE_DIALECT}://"
|
||||||
|
f"{EXAMPLES_USER}:{EXAMPLES_PASSWORD}@"
|
||||||
|
f"{EXAMPLES_HOST}:{EXAMPLES_PORT}/{EXAMPLES_DB}"
|
||||||
)
|
)
|
||||||
|
|
||||||
REDIS_HOST = get_env_variable("REDIS_HOST")
|
REDIS_HOST = get_env_variable("REDIS_HOST")
|
||||||
|
|
|
||||||
|
|
@ -1452,7 +1452,7 @@ SEND_FILE_MAX_AGE_DEFAULT = int(timedelta(days=365).total_seconds())
|
||||||
|
|
||||||
# URI to database storing the example data, points to
|
# URI to database storing the example data, points to
|
||||||
# SQLALCHEMY_DATABASE_URI by default if set to `None`
|
# SQLALCHEMY_DATABASE_URI by default if set to `None`
|
||||||
SQLALCHEMY_EXAMPLES_URI = None
|
SQLALCHEMY_EXAMPLES_URI = "sqlite:///" + os.path.join(DATA_DIR, "examples.db")
|
||||||
|
|
||||||
# Optional prefix to be added to all static asset paths when rendering the UI.
|
# Optional prefix to be added to all static asset paths when rendering the UI.
|
||||||
# This is useful for hosting assets in an external CDN, for example
|
# This is useful for hosting assets in an external CDN, for example
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,7 @@ def get_or_create_db(
|
||||||
|
|
||||||
|
|
||||||
def get_example_database() -> Database:
|
def get_example_database() -> Database:
|
||||||
db_uri = (
|
return get_or_create_db("examples", current_app.config["SQLALCHEMY_EXAMPLES_URI"])
|
||||||
current_app.config.get("SQLALCHEMY_EXAMPLES_URI")
|
|
||||||
or current_app.config["SQLALCHEMY_DATABASE_URI"]
|
|
||||||
)
|
|
||||||
return get_or_create_db("examples", db_uri)
|
|
||||||
|
|
||||||
|
|
||||||
def get_main_database() -> Database:
|
def get_main_database() -> Database:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue