|
13 | 13 | from odoo.tools import pycompat |
14 | 14 | from odoo.tools.safe_eval import safe_eval |
15 | 15 |
|
16 | | -from odoo.openupgrade import openupgrade_log, openupgrade_loading |
17 | 16 | from openupgradelib import openupgrade |
18 | 17 |
|
19 | 18 | _logger = logging.getLogger(__name__) |
@@ -182,12 +181,14 @@ def _drop_table(self): |
182 | 181 | for model in self: |
183 | 182 | current_model = self.env.get(model.model) |
184 | 183 | 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]) |
186 | 188 | openupgrade.message( |
187 | 189 | self._cr, 'Unknown', False, False, |
188 | 190 | "Not dropping the table or view of model %s", model.model) |
189 | 191 | continue |
190 | | - table = current_model._table |
191 | 192 | kind = tools.table_kind(self._cr, table) |
192 | 193 | if kind == 'v': |
193 | 194 | self._cr.execute('DROP VIEW "%s"' % table) |
@@ -610,13 +611,21 @@ def _drop_column(self): |
610 | 611 | if field.name in models.MAGIC_COLUMNS: |
611 | 612 | continue |
612 | 613 | # 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) |
613 | 623 | openupgrade.message( |
614 | 624 | self._cr, 'Unknown', False, False, |
615 | 625 | "Not dropping the column of field %s of model %s", field.name, |
616 | 626 | field.model, |
617 | 627 | ) |
618 | 628 | continue |
619 | | - model = self.env.get(field.model) |
620 | 629 | is_model = model is not None |
621 | 630 | if field.store: |
622 | 631 | # TODO: Refactor this brol in master |
|
0 commit comments