Merge branch '21-psql-command-improvement-sylvain' into '21-psql-command'
Improve #31 See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!38
This commit is contained in:
commit
a436490a68
70
README.md
70
README.md
|
|
@ -39,6 +39,7 @@ and provides helpers to run (and replay) migrations until it works.
|
|||
* [Command ``upgrade`` (BETA)](#command-upgrade)
|
||||
* [Command ``generate-module-analysis`` (BETA)](#command-generate-module-analysis)
|
||||
* [Command ``estimate-workload`` (BETA)](#command-estimate-workload)
|
||||
* [Command ``psql``](#command-psql)
|
||||
|
||||
<a name="installation"/>
|
||||
|
||||
|
|
@ -365,3 +366,72 @@ the work to do for the migration.
|
|||
renaming or merging of modules)
|
||||
- check that the analysis and migration have been done for the official
|
||||
modules present in odoo/odoo
|
||||
|
||||
<a name="command-psql"/>
|
||||
|
||||
## Command: ``psql``
|
||||
|
||||
**Prerequites:** init
|
||||
|
||||
```
|
||||
odoo-openupgrade-wizard psql
|
||||
--database DB_NAME
|
||||
--command "SQL_REQUEST"
|
||||
```
|
||||
|
||||
Execute an SQL Request on the target database.
|
||||
|
||||
**Optional arguments**
|
||||
|
||||
* If no ``database`` is provided, default ``postgres`` database will be used. exemple:
|
||||
|
||||
```
|
||||
odoo-openupgrade-wizard psql --command "\l";
|
||||
```
|
||||
Result:
|
||||
```
|
||||
List of databases
|
||||
Name | Owner | Encoding | Collate | Ctype | Access privileges
|
||||
------------+-------+----------+------------+------------+-------------------
|
||||
postgres | odoo | UTF8 | en_US.utf8 | en_US.utf8 |
|
||||
template0 | odoo | UTF8 | en_US.utf8 | en_US.utf8 | =c/odoo +
|
||||
| | | | | odoo=CTc/odoo
|
||||
template1 | odoo | UTF8 | en_US.utf8 | en_US.utf8 | =c/odoo +
|
||||
| | | | | odoo=CTc/odoo
|
||||
test_psql | odoo | UTF8 | en_US.utf8 | en_US.utf8 |
|
||||
|
||||
```
|
||||
|
||||
* if you execute request that return long result, you can choose to select ``pager`` or ``-no-pager``
|
||||
option to display the result via the click function ``echo_via_pager``.
|
||||
(see : https://click.palletsprojects.com/en/8.1.x/utils/#pager-support)
|
||||
|
||||
Note : Pager is enabled by default.
|
||||
|
||||
|
||||
* you can pass extra psql arguments inline.
|
||||
|
||||
```
|
||||
odoo-openupgrade-wizard psql
|
||||
--database=test_psql
|
||||
--command "select id, name from res_partner where name ilike '%admin%';"
|
||||
-H
|
||||
```
|
||||
Result:
|
||||
```
|
||||
<table border="1">
|
||||
<tr>
|
||||
<th align="center">id</th>
|
||||
<th align="center">name</th>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<td align="right">3</td>
|
||||
<td align="left">Administrator</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>(1 row)<br />
|
||||
</p>
|
||||
|
||||
```
|
||||
|
||||
See all the options here https://www.postgresql.org/docs/current/app-psql.html
|
||||
|
|
|
|||
|
|
@ -116,19 +116,17 @@ def execute_sql_request(ctx, request, database="postgres"):
|
|||
|
||||
|
||||
def execute_psql_command(
|
||||
ctx, request: str, database: str = "postgres", psql_args=None
|
||||
ctx, request: str, database: str = None, psql_args: tuple = ()
|
||||
):
|
||||
"""Execute psql request in postgres container with psql_args on database"""
|
||||
if psql_args and not isinstance(psql_args, str):
|
||||
psql_args = " ".join(psql_args)
|
||||
container = get_postgres_container(ctx)
|
||||
command = (
|
||||
"psql"
|
||||
" --username=odoo"
|
||||
" --dbname={database}"
|
||||
' --command "{request}"'
|
||||
" {psql_args}"
|
||||
).format(database=database, request=request, psql_args=psql_args)
|
||||
f" --dbname={database or 'postgres'}"
|
||||
f' --command "{request}"'
|
||||
f" {' '.join(psql_args)}"
|
||||
)
|
||||
logger.debug(
|
||||
"Executing the following command in postgres container\n"
|
||||
"%s" % (command)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user