Compare commits
2 Commits
main
...
psql-refac
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c717c04bd0 | ||
|
|
17e8040712 |
|
|
@ -122,13 +122,19 @@ def execute_psql_command(
|
||||||
):
|
):
|
||||||
"""Execute psql request in postgres container with psql_args on database"""
|
"""Execute psql request in postgres container with psql_args on database"""
|
||||||
container = get_postgres_container(ctx)
|
container = get_postgres_container(ctx)
|
||||||
|
logger.warning("DEBUG ========= execute_psql_command")
|
||||||
|
logger.warning("request: ", request)
|
||||||
|
logger.warning("database: ", database)
|
||||||
|
escaped_request = request.replace('"', '\\"')
|
||||||
|
logger.warning("escaped_request: ", escaped_request)
|
||||||
command = (
|
command = (
|
||||||
"psql"
|
"psql"
|
||||||
" --username=odoo"
|
" --username=odoo"
|
||||||
f" --dbname={database or 'postgres'}"
|
f" --dbname={database or 'postgres'}"
|
||||||
f' --command "{request}"'
|
f' --command "{escaped_request}"'
|
||||||
f" {' '.join(psql_args)}"
|
f" {' '.join(psql_args)}"
|
||||||
)
|
)
|
||||||
|
logger.warning("command: ", command)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
"Executing the following command in postgres container\n"
|
"Executing the following command in postgres container\n"
|
||||||
"%s" % (command)
|
"%s" % (command)
|
||||||
|
|
@ -154,10 +160,12 @@ def ensure_database(ctx, database: str, state="present", template: str = ""):
|
||||||
|
|
||||||
if template:
|
if template:
|
||||||
logger.info(f"Copy database '{template}' into '{database}' ...")
|
logger.info(f"Copy database '{template}' into '{database}' ...")
|
||||||
request = f"CREATE DATABASE {database} WITH TEMPLATE {template};"
|
request = (
|
||||||
|
f'CREATE DATABASE "{database}" WITH TEMPLATE "{template}";'
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
logger.info(f"Create database '{database}' ...")
|
logger.info(f"Create database '{database}' ...")
|
||||||
request = f"CREATE DATABASE {database} owner odoo;"
|
request = f'CREATE DATABASE "{database}" owner odoo;'
|
||||||
execute_psql_command(ctx, request)
|
execute_psql_command(ctx, request)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -165,7 +173,7 @@ def ensure_database(ctx, database: str, state="present", template: str = ""):
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info("Drop database '%s' ..." % database)
|
logger.info("Drop database '%s' ..." % database)
|
||||||
request = "DROP DATABASE {database};".format(database=database)
|
request = f'DROP DATABASE "{database}";'
|
||||||
execute_psql_command(ctx, request)
|
execute_psql_command(ctx, request)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from pytest import raises
|
||||||
|
|
||||||
from odoo_openupgrade_wizard.tools.tools_postgres import (
|
from odoo_openupgrade_wizard.tools.tools_postgres import (
|
||||||
ensure_database,
|
ensure_database,
|
||||||
execute_psql_command,
|
execute_sql_request,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
|
|
@ -38,12 +38,7 @@ def test_cli_psql():
|
||||||
" WHERE state ='installed'"
|
" WHERE state ='installed'"
|
||||||
" AND name='base';"
|
" AND name='base';"
|
||||||
)
|
)
|
||||||
output = execute_psql_command(
|
output = execute_sql_request(ctx, request)
|
||||||
ctx,
|
|
||||||
request,
|
|
||||||
database=db_name,
|
|
||||||
psql_args=("--tuples-only",),
|
|
||||||
)
|
|
||||||
assert output.strip() == "base"
|
assert output.strip() == "base"
|
||||||
|
|
||||||
# test via cli ok
|
# test via cli ok
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,8 @@ def test_cli_copydb(mocker):
|
||||||
move_to_test_folder()
|
move_to_test_folder()
|
||||||
mock_odoo_rpc_url(mocker)
|
mock_odoo_rpc_url(mocker)
|
||||||
|
|
||||||
db_name = "database_test_cli___copydb"
|
db_name = "database_test_cli___copydb-TEST"
|
||||||
db_dest_name = "database_test_cli___copydb__copy"
|
db_dest_name = "database_test_cli___copydb-TEST__copy"
|
||||||
ctx = build_ctx_from_config_file()
|
ctx = build_ctx_from_config_file()
|
||||||
|
|
||||||
# Ensure environment is clean
|
# Ensure environment is clean
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user