From 34e9bfbabc58035d7b139f034f78c4df5c0e4f10 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 23 Oct 2019 11:35:11 +0200 Subject: [PATCH] [MIG] contract: Create contract sequence for allowing to create records --- contract/migrations/12.0.4.0.0/pre-migration.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/contract/migrations/12.0.4.0.0/pre-migration.py b/contract/migrations/12.0.4.0.0/pre-migration.py index 3e28c29e..dad488eb 100644 --- a/contract/migrations/12.0.4.0.0/pre-migration.py +++ b/contract/migrations/12.0.4.0.0/pre-migration.py @@ -101,6 +101,13 @@ def create_contract_records(cr): sql.Identifier(contract_field_name), ), ) + # Handle id sequence + cr.execute("CREATE SEQUENCE IF NOT EXISTS contract_contract_id_seq") + cr.execute("SELECT setval('contract_contract_id_seq', " + "(SELECT MAX(id) FROM contract_contract))") + cr.execute("ALTER TABLE contract_contract ALTER id " + "SET DEFAULT NEXTVAL('contract_contract_id_seq')") + # Move common stuff from one table to the other mapping = [ ('ir_attachment', 'res_model', 'res_id'), ('mail_message', 'model', 'res_id'), @@ -108,7 +115,6 @@ def create_contract_records(cr): ('mail_followers', 'res_model', 'res_id'), ] for table, model_column, id_column in mapping: - # Move common stuff from one table to the other openupgrade.logged_query( cr, sql.SQL(""" UPDATE {table} SET {model_column}='contract.contract'