[ADD] [database_cleanup] migrate to 11.0
parent
8d03304f64
commit
28ceb7c57e
|
@ -3,7 +3,7 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
{
|
{
|
||||||
'name': 'Database cleanup',
|
'name': 'Database cleanup',
|
||||||
'version': '10.0.1.0.0',
|
'version': '11.0.1.0.0',
|
||||||
'author': "Therp BV,Odoo Community Association (OCA)",
|
'author': "Therp BV,Odoo Community Association (OCA)",
|
||||||
'depends': ['base'],
|
'depends': ['base'],
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
|
|
|
@ -20,4 +20,6 @@ class IdentifierAdapter(ISQLQuote):
|
||||||
format_string = '"%s"'
|
format_string = '"%s"'
|
||||||
if not self.quote:
|
if not self.quote:
|
||||||
format_string = '%s'
|
format_string = '%s'
|
||||||
return format_string % filter(is_identifier_char, self.identifier)
|
return format_string % ''.join(
|
||||||
|
filter(is_identifier_char, self.identifier)
|
||||||
|
)
|
||||||
|
|
|
@ -5,6 +5,5 @@ from . import purge_columns
|
||||||
from . import purge_tables
|
from . import purge_tables
|
||||||
from . import purge_data
|
from . import purge_data
|
||||||
from . import purge_menus
|
from . import purge_menus
|
||||||
from . import ir_model_fields
|
|
||||||
from . import create_indexes
|
from . import create_indexes
|
||||||
from . import purge_properties
|
from . import purge_properties
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2014-2016 Therp BV <http://therp.nl>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
||||||
from openerp import api, models
|
|
||||||
|
|
||||||
|
|
||||||
class IrModelFields(models.Model):
|
|
||||||
_inherit = 'ir.model.fields'
|
|
||||||
|
|
||||||
# In case of purging it means the model does not exist anymore in
|
|
||||||
# installed module. In this specific case, we need to avoid to check
|
|
||||||
# if fields can be removed as it would fail.
|
|
||||||
@api.multi
|
|
||||||
def _prepare_update(self):
|
|
||||||
if self.env.context.get('purge'):
|
|
||||||
self -= self.filtered(lambda x: x.model not in self.env.registry)
|
|
||||||
return super(IrModelFields, self)._prepare_update()
|
|
|
@ -117,7 +117,7 @@ class CleanupPurgeWizardColumn(models.TransientModel):
|
||||||
model_pool._table, (model.id, [])
|
model_pool._table, (model.id, [])
|
||||||
)[1].append(model_pool)
|
)[1].append(model_pool)
|
||||||
|
|
||||||
for table, model_spec in table2model.iteritems():
|
for table, model_spec in table2model.items():
|
||||||
for column in self.get_orphaned_columns(model_spec[1]):
|
for column in self.get_orphaned_columns(model_spec[1]):
|
||||||
res.append((0, 0, {
|
res.append((0, 0, {
|
||||||
'name': column,
|
'name': column,
|
||||||
|
|
|
@ -81,8 +81,7 @@ class CleanupPurgeWizardTable(models.TransientModel):
|
||||||
Search for tables that cannot be instantiated.
|
Search for tables that cannot be instantiated.
|
||||||
Ignore views for now.
|
Ignore views for now.
|
||||||
"""
|
"""
|
||||||
# Start out with known tables with no model
|
known_tables = []
|
||||||
known_tables = ['wkf_witm_trans']
|
|
||||||
for model in self.env['ir.model'].search([]):
|
for model in self.env['ir.model'].search([]):
|
||||||
if model.model not in self.env:
|
if model.model not in self.env:
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
from psycopg2 import ProgrammingError
|
from psycopg2 import ProgrammingError
|
||||||
from odoo.modules.registry import Registry
|
from odoo.modules.registry import Registry
|
||||||
from odoo.tools import config
|
from odoo.tools import config, mute_logger
|
||||||
from odoo.tests.common import TransactionCase, at_install, post_install
|
from odoo.tests.common import TransactionCase, at_install, post_install
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,8 @@ class TestDatabaseCleanup(TransactionCase):
|
||||||
# must be removed by the wizard
|
# must be removed by the wizard
|
||||||
with self.assertRaises(ProgrammingError):
|
with self.assertRaises(ProgrammingError):
|
||||||
with self.env.registry.cursor() as cr:
|
with self.env.registry.cursor() as cr:
|
||||||
cr.execute('select database_cleanup_test from res_partner')
|
with mute_logger('odoo.sql_db'):
|
||||||
|
cr.execute('select database_cleanup_test from res_partner')
|
||||||
|
|
||||||
# create a data entry pointing nowhere
|
# create a data entry pointing nowhere
|
||||||
self.env.cr.execute('select max(id) + 1 from res_users')
|
self.env.cr.execute('select max(id) + 1 from res_users')
|
||||||
|
@ -77,8 +78,6 @@ class TestDatabaseCleanup(TransactionCase):
|
||||||
'insert into ir_attachment (name, res_model, res_id, type) values '
|
'insert into ir_attachment (name, res_model, res_id, type) values '
|
||||||
"('test attachment', 'database.cleanup.test.model', 42, 'binary')")
|
"('test attachment', 'database.cleanup.test.model', 42, 'binary')")
|
||||||
self.env.registry.models.pop('x_database.cleanup.test.model')
|
self.env.registry.models.pop('x_database.cleanup.test.model')
|
||||||
self.env.registry._fields_by_model.pop(
|
|
||||||
'x_database.cleanup.test.model')
|
|
||||||
purge_models = self.env['cleanup.purge.wizard.model'].create({})
|
purge_models = self.env['cleanup.purge.wizard.model'].create({})
|
||||||
purge_models.purge_all()
|
purge_models.purge_all()
|
||||||
# must be removed by the wizard
|
# must be removed by the wizard
|
||||||
|
@ -112,7 +111,8 @@ class TestDatabaseCleanup(TransactionCase):
|
||||||
purge_tables.purge_all()
|
purge_tables.purge_all()
|
||||||
with self.assertRaises(ProgrammingError):
|
with self.assertRaises(ProgrammingError):
|
||||||
with self.env.registry.cursor() as cr:
|
with self.env.registry.cursor() as cr:
|
||||||
cr.execute('select * from database_cleanup_test')
|
with mute_logger('odoo.sql_db'):
|
||||||
|
cr.execute('select * from database_cleanup_test')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestDatabaseCleanup, self).tearDown()
|
super(TestDatabaseCleanup, self).tearDown()
|
||||||
|
|
|
@ -39,14 +39,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_create_indexes_line" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_create_indexes_line" />
|
||||||
<field name="code">env.get('cleanup.create_indexes.line').purge()</field>
|
<field name="code">records.purge()</field>
|
||||||
</record>
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_create_indexes_line" />
|
||||||
|
|
||||||
<record id="cleanup_create_indexes_line_action_value" model="ir.values">
|
|
||||||
<field name="name">Create indexes</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.create_indexes.line</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.cleanup_create_indexes_line_action')" />
|
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -37,16 +37,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_column" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_column" />
|
||||||
<field name="code">
|
<field name="code">records.purge()</field>
|
||||||
env.get('cleanup.purge.line.column').purge()
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_column" />
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="action_purge_column_line_value" model="ir.values">
|
|
||||||
<field name="name">Purge</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.purge.line.column</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_column_line')" />
|
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -37,16 +37,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_data" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_data" />
|
||||||
<field name="code">
|
<field name="code">records.purge()</field>
|
||||||
env.get('cleanup.purge.line.data').purge()
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_data" />
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="action_purge_data_line_value" model="ir.values">
|
|
||||||
<field name="name">Purge</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.purge.line.data</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_data_line')" />
|
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -33,16 +33,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_menu" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_menu" />
|
||||||
<field name="code">
|
<field name="code">records.purge()</field>
|
||||||
env.get('cleanup.purge.line.menu').purge()
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_menu" />
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="action_purge_menu_line_value" model="ir.values">
|
|
||||||
<field name="name">Purge</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.purge.line.menu</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_menu_line')" />
|
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -33,16 +33,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_model" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_model" />
|
||||||
<field name="code">
|
<field name="code">records.purge()</field>
|
||||||
env.get('cleanup.purge.line.model').purge()
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_model" />
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="action_purge_model_line_value" model="ir.values">
|
|
||||||
<field name="name">Purge</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.purge.line.model</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_model_line')" />
|
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -33,16 +33,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_module" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_module" />
|
||||||
<field name="code">
|
<field name="code">records.purge()</field>
|
||||||
env.get('cleanup.purge.line.module').purge()
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_module" />
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="action_purge_module_line_value" model="ir.values">
|
|
||||||
<field name="name">Purge</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.purge.line.module</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_module_line')" />
|
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -33,15 +33,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_property" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_property" />
|
||||||
<field name="code">env.get('cleanup.purge.line.property').purge()</field>
|
<field name="code">records.purge()</field>
|
||||||
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_property" />
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="action_purge_property_line_value" model="ir.values">
|
|
||||||
<field name="name">Purge</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.purge.line.property</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_property_line')" />
|
|
||||||
</record>
|
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -33,16 +33,7 @@
|
||||||
<field name="type">ir.actions.server</field>
|
<field name="type">ir.actions.server</field>
|
||||||
<field name="state">code</field>
|
<field name="state">code</field>
|
||||||
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_table" />
|
<field name="model_id" ref="database_cleanup.model_cleanup_purge_line_table" />
|
||||||
<field name="code">
|
<field name="code">records.purge()</field>
|
||||||
env.get('cleanup.purge.line.table').purge()
|
<field name="binding_model_id" ref="database_cleanup.model_cleanup_purge_line_table" />
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="action_purge_table_line_value" model="ir.values">
|
|
||||||
<field name="name">Purge</field>
|
|
||||||
<field name="key">action</field>
|
|
||||||
<field name="key2">client_action_multi</field>
|
|
||||||
<field name="model">cleanup.purge.line.table</field>
|
|
||||||
<field name="value" eval="'ir.actions.server,%d' % ref('database_cleanup.action_purge_table_line')" />
|
|
||||||
</record>
|
</record>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue