Skip to content

Commit

Permalink
[MIG] database_cleanup: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneMangin committed Feb 1, 2022
1 parent 99fcae3 commit b68617c
Show file tree
Hide file tree
Showing 28 changed files with 411 additions and 222 deletions.
62 changes: 45 additions & 17 deletions database_cleanup/README.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
===================
Base Technical User
===================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/14.0/database_cleanup
:alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-database_cleanup
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/149/14.0
:alt: Try me on Runbot

================
Database cleanup
================
|badge1| |badge2| |badge3| |badge4| |badge5|

Clean your Odoo database from remnants of modules, models, columns and
tables left by uninstalled modules (prior to 7.0) or a homebrew database
Expand All @@ -16,6 +35,11 @@ with the technical details of the Odoo data model of *all* the modules
that have ever been installed on your database, and do not purge any module,
model, column or table if you do not know exactly what you are doing.

**Table of contents**

.. contents::
:local:

Usage
=====

Expand All @@ -28,42 +52,46 @@ in one big step (if you are *really* confident).

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/11.0
:target: https://runbot.odoo-community.org/runbot/149/14.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/database_cleanup/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20database_cleanup%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Images
------
Authors
~~~~~~~

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* Therp BV

Contributors
------------
~~~~~~~~~~~~

* Stefan Rijnhart <[email protected]>
* Holger Brunn <[email protected]>
* Stéphane Mangin <[email protected]>

Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:[email protected]>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.
Maintainers
~~~~~~~~~~~

Maintainer
----------
This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/14.0/base_technical_user>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Copyright 2014-2016 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp SA <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Database cleanup",
"version": "12.0.1.0.1",
"version": "14.0.1.0.0",
"author": "Therp BV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools",
"depends": ["base"],
"license": "AGPL-3",
"category": "Tools",
Expand All @@ -18,6 +20,7 @@
"views/create_indexes.xml",
"views/purge_properties.xml",
"views/menu.xml",
"security/ir.model.access.csv",
],
"installable": True,
}
2 changes: 1 addition & 1 deletion database_cleanup/i18n/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ msgstr "Purge obsolete modules"
#, fuzzy
#| msgid "Purge obsolete models"
msgid "Purge obsolete properties"
msgstr "Purge obsolete models"
msgstr "Purge obsolete properties"

#. module: database_cleanup
#: model:ir.ui.menu,name:database_cleanup.menu_purge_tables
Expand Down
9 changes: 3 additions & 6 deletions database_cleanup/models/create_indexes.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Copyright 2017 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
from odoo import api, fields, models
from odoo import fields, models

from ..identifier_adapter import IdentifierAdapter


class CreateIndexesLine(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.create_indexes.line"
_description = "Cleanup Create Indexes line"

purged = fields.Boolean("Created")
wizard_id = fields.Many2one("cleanup.create_indexes.wizard")
field_id = fields.Many2one("ir.model.fields", required=True)

@api.multi
def purge(self):
tables = set()
for field in self.mapped("field_id"):
model = self.env[field.model]
name = "{}_{}_index".format(model._table, field.name)
Expand All @@ -28,8 +28,6 @@ def purge(self):
IdentifierAdapter(field.name),
),
)
tables.add(model._table)
for table in tables:
self.env.cr.execute("analyze %s", (IdentifierAdapter(model._table),))
self.write(
{
Expand All @@ -48,7 +46,6 @@ class CreateIndexesWizard(models.TransientModel):
"wizard_id",
)

@api.multi
def find(self):
res = list()
for field in self.env["ir.model.fields"].search(
Expand Down
6 changes: 3 additions & 3 deletions database_cleanup/models/purge_columns.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014-2016 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
from odoo import _, api, fields, models
Expand All @@ -10,14 +11,13 @@
class CleanupPurgeLineColumn(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.purge.line.column"
_description = "Purge Column Wizard Lines"
_description = "Cleanup Purge Line Column"

model_id = fields.Many2one("ir.model", "Model", required=True, ondelete="CASCADE")
wizard_id = fields.Many2one(
"cleanup.purge.wizard.column", "Purge Wizard", readonly=True
)

@api.multi
def purge(self):
"""
Unlink columns upon manual confirmation.
Expand Down Expand Up @@ -123,7 +123,7 @@ def find(self):
model_pool
)

for table, model_spec in table2model.items():
for _table, model_spec in table2model.items():
for column in self.get_orphaned_columns(model_spec[1]):
res.append((0, 0, {"name": column, "model_id": model_spec[0]}))
if not res:
Expand Down
3 changes: 2 additions & 1 deletion database_cleanup/models/purge_data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014-2016 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
Expand All @@ -9,13 +10,13 @@
class CleanupPurgeLineData(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.purge.line.data"
_description = "Cleanup Purge Line Data"

data_id = fields.Many2one("ir.model.data", "Data entry")
wizard_id = fields.Many2one(
"cleanup.purge.wizard.data", "Purge Wizard", readonly=True
)

@api.multi
def purge(self):
"""Unlink data entries upon manual confirmation."""
if self:
Expand Down
7 changes: 3 additions & 4 deletions database_cleanup/models/purge_menus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014-2016 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
from odoo import _, api, fields, models
Expand All @@ -8,13 +9,13 @@
class CleanupPurgeLineMenu(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.purge.line.menu"
_description = "Cleanup Purge Line Menu"

wizard_id = fields.Many2one(
"cleanup.purge.wizard.menu", "Purge Wizard", readonly=True
)
menu_id = fields.Many2one("ir.ui.menu", "Menu entry")

@api.multi
def purge(self):
"""Unlink menu entries upon manual confirmation."""
if self:
Expand Down Expand Up @@ -47,9 +48,7 @@ def find(self):
):
if menu.action.type != "ir.actions.act_window":
continue
if (menu.action.res_model and menu.action.res_model not in self.env) or (
menu.action.src_model and menu.action.src_model not in self.env
):
if menu.action.res_model and menu.action.res_model not in self.env:
res.append(
(
0,
Expand Down
5 changes: 2 additions & 3 deletions database_cleanup/models/purge_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014-2016 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
from odoo import _, api, fields, models
Expand All @@ -25,7 +26,6 @@ def _inherited_models(self):
class IrModelFields(models.Model):
_inherit = "ir.model.fields"

@api.multi
def _prepare_update(self):
"""this function crashes for undefined models"""
existing = self.filtered(lambda x: x.model in self.env)
Expand All @@ -35,13 +35,12 @@ def _prepare_update(self):
class CleanupPurgeLineModel(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.purge.line.model"
_description = "Purge models"
_description = "Cleanup Purge Line Model"

wizard_id = fields.Many2one(
"cleanup.purge.wizard.model", "Purge Wizard", readonly=True
)

@api.multi
def purge(self):
"""
Unlink models upon manual confirmation.
Expand Down
3 changes: 2 additions & 1 deletion database_cleanup/models/purge_modules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2014-2016 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
from odoo import _, api, fields, models
Expand Down Expand Up @@ -33,12 +34,12 @@ def _module_data_uninstall(self, modules_to_remove):
class CleanupPurgeLineModule(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.purge.line.module"
_description = "Cleanup Purge Line Module"

wizard_id = fields.Many2one(
"cleanup.purge.wizard.module", "Purge Wizard", readonly=True
)

@api.multi
def purge(self):
"""
Uninstall modules upon manual confirmation, then reload
Expand Down
36 changes: 14 additions & 22 deletions database_cleanup/models/purge_properties.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
# Copyright 2017 Therp BV <http://therp.nl>
# Copyright 2021 Camptocamp <https://camptocamp.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
# pylint: disable=consider-merging-classes-inherited
from odoo import api, fields, models

REASON_DUPLICATE = 1
REASON_DEFAULT = 2
REASON_DEFAULT_FALSE = 3
REASON_UNKNOWN_MODEL = 4
REASON_DUPLICATE = "REASON_DUPLICATE"
REASON_DEFAULT = "REASON_DEFAULT"
REASON_DEFAULT_FALSE = "REASON_DEFAULT_FALSE"
REASON_UNKNOWN_MODEL = "REASON_UNKNOWN_MODEL"


class CleanupPurgeLineProperty(models.TransientModel):
_inherit = "cleanup.purge.line"
_name = "cleanup.purge.line.property"
_description = "Purge properties"
_description = "Cleanup Purge Line Property"

wizard_id = fields.Many2one(
"cleanup.purge.wizard.property", "Purge Wizard", readonly=True
Expand All @@ -27,7 +28,6 @@ class CleanupPurgeLineProperty(models.TransientModel):
]
)

@api.multi
def purge(self):
"""Delete properties"""
self.write({"purged": True})
Expand Down Expand Up @@ -58,12 +58,7 @@ def find(self):
except KeyError:
result.append(
{
"name": "%s@%s: %s"
% (
prop.name,
prop.res_id,
value,
),
"name": "{}@{}: {}".format(prop.name, prop.res_id, value),
"property_id": prop.id,
"reason": REASON_UNKNOWN_MODEL,
}
Expand All @@ -72,12 +67,7 @@ def find(self):
if not value:
result.append(
{
"name": "%s@%s: %s"
% (
prop.name,
prop.res_id,
value,
),
"name": "{}@{}: {}".format(prop.name, prop.res_id, value),
"property_id": prop.id,
"reason": REASON_DEFAULT_FALSE,
}
Expand Down Expand Up @@ -127,8 +117,9 @@ def find(self):
for redundant_property in self.env["ir.property"].search(domain):
result.append(
{
"name": "%s@%s: %s"
% (prop.name, redundant_property.res_id, prop.get_by_record()),
"name": "{}@{}: {}".format(
prop.name, redundant_property.res_id, prop.get_by_record()
),
"property_id": redundant_property.id,
"reason": REASON_DEFAULT,
}
Expand All @@ -148,8 +139,9 @@ def find(self):
for prop in self.env["ir.property"].search([("id", "in", ids)])[1:]:
result.append(
{
"name": "%s@%s: %s"
% (prop.name, prop.res_id, prop.get_by_record()),
"name": "{}@{}: {}".format(
prop.name, prop.res_id, prop.get_by_record()
),
"property_id": prop.id,
"reason": REASON_DUPLICATE,
}
Expand Down
Loading

0 comments on commit b68617c

Please sign in to comment.