Skip to content
Snippets Groups Projects
Commit b45dcc090821 authored by Vincent Hatakeyama's avatar Vincent Hatakeyama
Browse files

:ambulance: docker_dev_start: fix restore and pre script options

In the case of a database not started by the script, some information was missing.
parent 57306b630a9f
No related branches found
No related tags found
1 merge request!133🚑 docker_dev_start: fix restore and pre script options
......@@ -2,6 +2,11 @@
History
=======
16.7.3
------
docker_dev_start: Fix restoring database and applying script.
16.7.2
------
......
......@@ -42,5 +42,5 @@
_logger = logging.getLogger(__name__)
__version__ = "3.6.1"
__version__ = "3.6.2"
__date__ = "2017-08-11"
......@@ -46,5 +46,5 @@
__date__ = "2017-08-11"
__updated__ = "2022-09-07"
__updated__ = "2022-09-15"
def __parser(project_name: str) -> ArgumentParser:
......@@ -891,6 +891,7 @@
host=db_host,
port=dbport,
) as connection:
connection.autocommit = True
_logger.info("Creating database %s", database)
with connection.cursor() as cursor:
cursor.execute(f'CREATE DATABASE "{database}"')
......@@ -894,5 +895,6 @@
_logger.info("Creating database %s", database)
with connection.cursor() as cursor:
cursor.execute(f'CREATE DATABASE "{database}"')
connection.close()
if not start_postgresql and not odoo_help and restore_filename:
_logger.info("Restoring database %s", database)
......@@ -897,3 +899,11 @@
if not start_postgresql and not odoo_help and restore_filename:
_logger.info("Restoring database %s", database)
env = {
"PGHOST": db_host,
"PGPASSWORD": password,
"PGUSER": user,
"PG_COLOR": "always",
}
if dbport is not None:
env["PGPORT"] = dbport
restore = call(
......@@ -899,3 +909,11 @@
restore = call(
["pg_restore", "-U", user, "-O", "-d", database, restore_filename]
[
"pg_restore",
"--no-owner",
"--job=4",
"--dbname",
database,
restore_filename,
],
env=env,
)
......@@ -901,5 +919,6 @@
)
if not restore:
if restore != 0:
_logger.fatal("Errors during restoration")
return 15
# --- Pre SQL script ---
......@@ -932,8 +951,16 @@
# remove script
pg.exec_run(["rm", inside_pre_sql_script])
else:
_logger.info("Running SQL script %s in %s", pre_sql_script, database)
script = call(["psql", "-U", user, "-d", database, "-f", pre_sql_script])
_logger.info("Running SQL script %s on %s", pre_sql_script, database)
env = {
"PGHOST": db_host,
"PGPASSWORD": password,
"PGUSER": user,
"PG_COLOR": "always",
}
if dbport is not None:
env["PGPORT"] = dbport
script = call(["psql", "--dbname", database, "-f", pre_sql_script], env=env)
if script > 0:
_logger.fatal("Error when running SQL script %s", script)
return 16
......
......@@ -126,7 +126,8 @@
config.local_tag,
{
"entrypoint": "pylint",
"command": modules + ["--load-plugins=pylint_odoo"],
# "command": modules + ["--load-plugins=pylint_odoo"],
"command": modules,
# needed to write in the cache
"user": "root",
"mounts": mounts,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment