Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP][BR000757][t20513]modify the dpg_dump and docker_client for odoo database clean co… #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker_postgres_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def cmd(self):
docker_cmd = ' '.join(self.docker_cmd())
container_cmd = ' '.join(self.container_cmd())
return '''docker run -it --link %s:db %s \
--rm %s sh -c \'exec %s\'
--rm %s sh -c \"%s\"
''' % (args.container, docker_cmd, tag, container_cmd)

def docker_cmd(self):
Expand Down
35 changes: 33 additions & 2 deletions dpg_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@


class PgDump(Client):

def parser(self):
parser = super(PgDump, self).parser()
parser.add_argument('database', help="Database name")
parser.add_argument('-f', '--file', help="Exported file name")
parser.add_argument('-o', '--clean-odoo-db',
help="Clean Odoo Database With Optional Query File")
return parser

def docker_cmd(self):
Expand All @@ -43,12 +46,40 @@ def docker_cmd(self):
def container_cmd(self):
# mount a volume if a file is passed as argument
args = self.args
res = ['pg_dump -h db -p %s -U %s -d %s' % (
args.port, args.user, args.database)]
res = []
if args.clean_odoo_db:
res = \
["psql -h db -p %s -U %s -d %s "
"-c 'CREATE DATABASE duplicate_db "
"WITH TEMPLATE %s OWNER %s;' &&" % (
args.port,
args.user,
args.database,
args.database,
args.user)]
res.append("echo '1---Finish Create duplicate_db' &&")
res.append(
'psql -h db -p %s -U %s -d duplicate_db -f /tmp/%s &&' % (
args.port, args.user, args.clean_odoo_db))
res.append("echo '2---Finish Clean duplicate_db' &&")
res.append('pg_dump -h db -p %s -U %s -d duplicate_db' % (
args.port, args.user))
else:
res.append('pg_dump -h db -p %s -U %s -d %s' % (
args.port, args.user, args.database))
if args.file:
res.append('> /tmp/%s' % args.file)
else:
res.append('> /tmp/%s.out' % args.database)

if args.clean_odoo_db:
res.append("&& echo '3---Finish Dump duplicate_db' &&")
res.append(
"psql -h db -p %s -U %s -d %s "
"-c 'Drop DATABASE duplicate_db'"% (
args.port,
args.user,
args.database))
return res


Expand Down
11 changes: 11 additions & 0 deletions test_clean_query.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
 DELETE FROM fetchmail_server;

DELETE FROM ir_mail_server;

UPDATE ir_cron SET active = FALSE;

DELETE FROM ir_config_parameter WHERE key = 'dead_mans_switch_client.url';

UPDATE ir_config_parameter SET value = md5(random()::text || clock_timestamp()::text)::uuid WHERE key = 'database.uuid';

DELETE FROM ir_config_parameter WHERE key IN ('database.enterprise_code', 'database.expiration_date', 'database.expiration_reason');