From 8a7997423202ff6d281099657bdc1366c73ed61f Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Thu, 6 Jul 2023 16:20:20 +0200 Subject: [PATCH 1/2] [REF] Use f-string to make the code lighter [FIX] execute_psql_command: make optional database argument working correctly [FIX] execute_psql_command: avoid to have an error --- odoo_openupgrade_wizard/tools/tools_postgres.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/odoo_openupgrade_wizard/tools/tools_postgres.py b/odoo_openupgrade_wizard/tools/tools_postgres.py index 3df9b5f..819a236 100644 --- a/odoo_openupgrade_wizard/tools/tools_postgres.py +++ b/odoo_openupgrade_wizard/tools/tools_postgres.py @@ -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) From c813f3ddd43f839de0d5f43b5d936874aa642a5e Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Thu, 6 Jul 2023 16:21:15 +0200 Subject: [PATCH 2/2] -[DOC] psl command : add description --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/README.md b/README.md index 9b830c1..4d56aca 100644 --- a/README.md +++ b/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) @@ -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 + + + +## 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: +``` + + + + + + + + + +
idname
3Administrator
+

(1 row)
+

+ +``` + +See all the options here https://www.postgresql.org/docs/current/app-psql.html