[IMP] runbot: automatically link logs to build

The linked build is extracted from dbname via a trigger on new row
creation.

This improve rendering of build page.

A migration script is added to link existing logging entries to
corresponding build and remove invalid ones.
Note that this migration script can take a long time.
This commit is contained in:
Christophe Simonis 2017-09-21 12:05:27 +02:00
parent eb267ffa44
commit 03da1e9339
3 changed files with 52 additions and 5 deletions

View File

@ -2,9 +2,9 @@
'name': 'Runbot',
'category': 'Website',
'summary': 'Runbot',
'version': '1.2',
'version': '1.3',
'description': "Runbot",
'author': 'OpenERP SA',
'author': 'Odoo SA',
'depends': ['website'],
'external_dependencies': {
'python': ['matplotlib'],

View File

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
def migrate(cr, version):
cr.execute("""
WITH bad(id) AS (
SELECT split_part(dbname, '-', 1)::integer
FROM ir_logging
WHERE dbname ~ '^\d+-.+'
GROUP BY 1
EXCEPT
SELECT id
FROM runbot_build
)
DELETE FROM ir_logging
WHERE dbname ~ (SELECT CONCAT('^(', string_agg(id::text, '|'::text), ')-.+') FROM bad);
UPDATE ir_logging
SET build_id = split_part(dbname, '-', 1)::integer
WHERE build_id IS NULL
AND dbname ~ '^\d+-.+';
""")

View File

@ -1314,10 +1314,36 @@ class runbot_event(osv.osv):
TYPES = [(t, t.capitalize()) for t in 'client server runbot'.split()]
_columns = {
'build_id': fields.many2one('runbot.build', 'Build', select=True),
'build_id': fields.many2one('runbot.build', 'Build', select=True, ondelete='cascade'),
'type': fields.selection(TYPES, string='Type', required=True, select=True),
}
def init(self, cr):
super(runbot_event, self).init(cr)
cr.execute("""
CREATE OR REPLACE FUNCTION runbot_set_logging_build() RETURNS TRIGGER AS $$
BEGIN
IF (new.build_id IS NULL AND new.dbname IS NOT NULL AND new.dbname != current_database()) THEN
UPDATE ir_logging l
SET build_id = split_part(new.dbname, '-', 1)::integer
WHERE l.id = new.id;
END IF;
RETURN NULL;
END;
$$ language plpgsql;
DO $$
BEGIN
CREATE TRIGGER runbot_new_logging
AFTER INSERT ON ir_logging
FOR EACH ROW
EXECUTE PROCEDURE runbot_set_logging_build();
EXCEPTION
WHEN duplicate_object THEN
END;
$$;
""")
#----------------------------------------------------------
# Runbot Controller
#----------------------------------------------------------
@ -1535,13 +1561,13 @@ class RunbotController(http.Controller):
build_ids = Build.search(cr, uid, [('branch_id', '=', build.branch_id.id)])
other_builds = Build.browse(cr, uid, build_ids)
domain = ['|', ('dbname', '=like', '%s-%%' % real_build.dest), ('build_id', '=', real_build.id)]
domain = [('build_id', '=', real_build.id)]
#if type:
# domain.append(('type', '=', type))
#if level:
# domain.append(('level', '=', level))
if search:
domain.append(('name', 'ilike', search))
domain.append(('message', 'ilike', search))
logging_ids = Logging.search(cr, SUPERUSER_ID, domain)
context = {