allow hyphen-minus character in database names
This commit is contained in:
parent
93dc52ee5f
commit
bb2b3be3b4
1
newsfragments/allow-minus-in-database-names.bugfix
Normal file
1
newsfragments/allow-minus-in-database-names.bugfix
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Allow hyphen-minus character in database names.
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import time
|
import time
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
@ -125,7 +126,7 @@ def execute_psql_command(
|
||||||
"psql"
|
"psql"
|
||||||
" --username=odoo"
|
" --username=odoo"
|
||||||
f" --dbname={database or 'postgres'}"
|
f" --dbname={database or 'postgres'}"
|
||||||
f' --command "{request}"'
|
f" --command {shlex.quote(request)}"
|
||||||
f" {' '.join(psql_args)}"
|
f" {' '.join(psql_args)}"
|
||||||
)
|
)
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|
@ -151,19 +152,21 @@ def ensure_database(ctx, database: str, state="present", template: str = ""):
|
||||||
return
|
return
|
||||||
|
|
||||||
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:
|
||||||
if [database] not in result:
|
if [database] not in result:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f"Drop database '{database}' ...")
|
logger.info(f'Drop database "{database}"...')
|
||||||
request = f"DROP DATABASE {database};"
|
request = f'DROP DATABASE "{database}";'
|
||||||
execute_psql_command(ctx, request)
|
execute_psql_command(ctx, request)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user