Skip to content

mysql password supports special characters #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dandelion/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import dandelion.conf
from dandelion import constants, version
from dandelion.db.base import Base # noqa
from dandelion.db.session import connection_database

CONF: cfg = dandelion.conf.CONF

Expand All @@ -49,6 +50,7 @@

target_metadata = Base.metadata


# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
Expand All @@ -67,8 +69,9 @@ def run_migrations_offline():
script output.

"""
connection = connection_database()
context.configure(
url=CONF.database.connection,
url=connection,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
Expand All @@ -85,7 +88,8 @@ def run_migrations_online():
and associate a connection with the context.

"""
engine = create_engine(CONF.database.connection, poolclass=pool.NullPool)
connection = connection_database()
engine = create_engine(connection, poolclass=pool.NullPool)

with engine.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
Expand Down
15 changes: 13 additions & 2 deletions dandelion/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from logging import LoggerAdapter
from typing import Dict
from urllib.parse import quote_plus

from oslo_config import cfg
from oslo_log import log
Expand All @@ -25,7 +26,6 @@
CONF = cfg.CONF
LOG: LoggerAdapter = log.getLogger(__name__)


DB_SESSION_LOCAL: Session


Expand All @@ -40,9 +40,20 @@ def setup_db() -> None:
engine_cfg: Dict[str, int] = {}
engine_cfg["pool_size"] = CONF.database.max_pool_size
engine_cfg["max_overflow"] = CONF.database.max_overflow
engine = create_engine(CONF.database.connection, pool_pre_ping=True, **engine_cfg)

connection = connection_database()

engine = create_engine(connection, pool_pre_ping=True, **engine_cfg)

global DB_SESSION_LOCAL
DB_SESSION_LOCAL = sessionmaker(autocommit=False, autoflush=False, bind=engine)

LOG.info("DB setup complete")


def connection_database() -> str:
connection_list = CONF.database.connection.split(":")
index = connection_list[2].rfind("@")
connection_list[2] = quote_plus(connection_list[2][:index]) + connection_list[2][index:]
connection = ":".join(connection_list)
return connection