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"""
|
||||
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 = (
|
||||
"psql"
|
||||
" --username=odoo"
|
||||
f" --dbname={database or 'postgres'}"
|
||||
f' --command "{request}"'
|
||||
f' --command "{escaped_request}"'
|
||||
f" {' '.join(psql_args)}"
|
||||
)
|
||||
logger.warning("command: ", command)
|
||||
logger.debug(
|
||||
"Executing the following command in postgres container\n"
|
||||
"%s" % (command)
|
||||
|
|
@ -154,10 +160,12 @@ def ensure_database(ctx, database: str, state="present", template: str = ""):
|
|||
|
||||
if template:
|
||||
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:
|
||||
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)
|
||||
|
||||
else:
|
||||
|
|
@ -165,7 +173,7 @@ def ensure_database(ctx, database: str, state="present", template: str = ""):
|
|||
return
|
||||
|
||||
logger.info("Drop database '%s' ..." % database)
|
||||
request = "DROP DATABASE {database};".format(database=database)
|
||||
request = f'DROP DATABASE "{database}";'
|
||||
execute_psql_command(ctx, request)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from pytest import raises
|
|||
|
||||
from odoo_openupgrade_wizard.tools.tools_postgres import (
|
||||
ensure_database,
|
||||
execute_psql_command,
|
||||
execute_sql_request,
|
||||
)
|
||||
|
||||
from . import (
|
||||
|
|
@ -38,12 +38,7 @@ def test_cli_psql():
|
|||
" WHERE state ='installed'"
|
||||
" AND name='base';"
|
||||
)
|
||||
output = execute_psql_command(
|
||||
ctx,
|
||||
request,
|
||||
database=db_name,
|
||||
psql_args=("--tuples-only",),
|
||||
)
|
||||
output = execute_sql_request(ctx, request)
|
||||
assert output.strip() == "base"
|
||||
|
||||
# test via cli ok
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ def test_cli_copydb(mocker):
|
|||
move_to_test_folder()
|
||||
mock_odoo_rpc_url(mocker)
|
||||
|
||||
db_name = "database_test_cli___copydb"
|
||||
db_dest_name = "database_test_cli___copydb__copy"
|
||||
db_name = "database_test_cli___copydb-TEST"
|
||||
db_dest_name = "database_test_cli___copydb-TEST__copy"
|
||||
ctx = build_ctx_from_config_file()
|
||||
|
||||
# Ensure environment is clean
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user