Commit 84c988a2 authored by Adrià Labay's avatar Adrià Labay

dump mysql without root

parent 5fe3276a
Pipeline #34276 passed with stages
in 5 minutes and 28 seconds
......@@ -78,7 +78,7 @@ test_py:
MYSQL_DATABASE: "course_test"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
script:
- echo -e "\nMYSQL_HOST = 'mysql'\nMYSQL_USER = 'root'\nMYSQL_PSW = None" >> zesje_test_cfg.py
- echo -e "\nMYSQL_HOST = 'mysql'\nMYSQL_USER = 'root'\nMYSQL_PASSWORD = None" >> zesje_test_cfg.py
- yarn test:py:cov
artifacts:
paths:
......
......@@ -90,20 +90,20 @@ def create_config(config_instance, extra_config):
)
user = config_instance['MYSQL_USER']
psw = config_instance['MYSQL_PSW']
password = config_instance['MYSQL_PASSWORD']
host = config_instance['MYSQL_HOST']
database = config_instance['MYSQL_DATABASE']
# Force MySQL to use a TCP connection
host = host.replace('localhost', '127.0.0.1')
# Interpret None as no password
psw = psw if psw is not None else ''
password = password if password is not None else ''
config_instance.update(
MYSQL_HOST=host,
MYSQL_DIRECTORY=os.path.join(config_instance['DATA_DIRECTORY'], 'mysql'),
SQLALCHEMY_DATABASE_URI=f'mysql://{user}:{psw}@{host}/{database}',
SQLALCHEMY_PASSWORD=psw,
SQLALCHEMY_DATABASE_URI=f'mysql://{user}:{password}@{host}/{database}',
SQLALCHEMY_PASSWORD=password,
SQLALCHEMY_TRACK_MODIFICATIONS=False # Suppress future deprecation warning
)
......
......@@ -16,11 +16,11 @@ import jinja2
INIT_FILE_TEMPLATE = """CREATE DATABASE IF NOT EXISTS course;
CREATE DATABASE IF NOT EXISTS course_test;
CREATE USER IF NOT EXISTS '{{MYSQL_USER}}'@'%' IDENTIFIED BY '{{MYSQL_PSW}}';
CREATE USER IF NOT EXISTS '{{MYSQL_USER}}'@'%' IDENTIFIED BY '{{MYSQL_PASSWORD}}';
GRANT ALL ON course.* TO '{{MYSQL_USER}}'@'%';
GRANT ALL ON course_test.* TO '{{MYSQL_USER}}'@'%';
ALTER USER 'root'@'localhost' IDENTIFIED BY '{{MYSQL_ROOT_PSW}}';
ALTER USER 'root'@'localhost' IDENTIFIED BY '{{MYSQL_ROOT_PASSWORD}}';
FLUSH PRIVILEGES;
"""
......@@ -97,9 +97,9 @@ def start(config, interactive=False, allow_running=False):
def stop(config):
psw = config['MYSQL_ROOT_PSW']
password = config['MYSQL_ROOT_PASSWORD']
host = config['MYSQL_HOST']
os.system(f'mysqladmin --host={host} --user=root --password={psw} shutdown')
os.system(f'mysqladmin --host={host} --user=root --password={password} shutdown')
def is_running(config):
......@@ -115,12 +115,13 @@ def is_running(config):
return False
def dump(config, database=None):
psw = config['MYSQL_ROOT_PSW']
def dump(config, database):
user = config['MYSQL_USER']
password = config['MYSQL_PASSWORD']
host = config['MYSQL_HOST']
database = database if database is not None else config['MYSQL_DATABASE']
p = sp.Popen(
['mysqldump', '-uroot', f'--password={psw}', f'--host={host}', database],
['mysqldump', f'--user={user}', f'--password={password}', f'--host={host}', database],
stdin=sp.PIPE,
stdout=sp.PIPE,
stderr=sp.PIPE
......
......@@ -14,8 +14,8 @@ SMTP_PASSWORD = None
# MySQL host
MYSQL_USER = 'zesje'
MYSQL_ROOT_PSW = 'rootpsw'
MYSQL_PSW = 'zesjepsw'
MYSQL_ROOT_PASSWORD = 'rootpsw'
MYSQL_PASSWORD = 'zesjepsw'
MYSQL_HOST = 'localhost'
MYSQL_DATABASE = 'course'
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment