Skip to content

Commit 26ea62d

Browse files
[OU-IMP] openupgrade_framework: remove FKs of obsolete tables/columns
1 parent 568c9c5 commit 26ea62d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

odoo/addons/base/models/ir_model.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from odoo.tools import pycompat
1414
from odoo.tools.safe_eval import safe_eval
1515

16-
from odoo.openupgrade import openupgrade_log, openupgrade_loading
1716
from openupgradelib import openupgrade
1817

1918
_logger = logging.getLogger(__name__)
@@ -182,12 +181,14 @@ def _drop_table(self):
182181
for model in self:
183182
current_model = self.env.get(model.model)
184183
if current_model is not None:
185-
# OpenUpgrade: do not run the new table cleanup
184+
# OpenUpgrade: do not drop the table
185+
table = current_model._table
186+
if tools.table_kind(self._cr, table) == "r":
187+
openupgrade.remove_tables_fks(self.env.cr, [table])
186188
openupgrade.message(
187189
self._cr, 'Unknown', False, False,
188190
"Not dropping the table or view of model %s", model.model)
189191
continue
190-
table = current_model._table
191192
kind = tools.table_kind(self._cr, table)
192193
if kind == 'v':
193194
self._cr.execute('DROP VIEW "%s"' % table)
@@ -610,13 +611,21 @@ def _drop_column(self):
610611
if field.name in models.MAGIC_COLUMNS:
611612
continue
612613
# OpenUpgrade: do not drop columns
614+
model = self.env.get(field.model)
615+
if (
616+
field.store
617+
and field.ttype == "many2one"
618+
and model is not None
619+
and tools.column_exists(self._cr, model._table, field.name)
620+
and tools.table_kind(self._cr, model._table) == "r"
621+
):
622+
openupgrade.lift_constraints(self.env.cr, model._table, field.name)
613623
openupgrade.message(
614624
self._cr, 'Unknown', False, False,
615625
"Not dropping the column of field %s of model %s", field.name,
616626
field.model,
617627
)
618628
continue
619-
model = self.env.get(field.model)
620629
is_model = model is not None
621630
if field.store:
622631
# TODO: Refactor this brol in master

0 commit comments

Comments
 (0)