From 03da1e9339c9e1088a712c4547918e4e533fa537 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Thu, 21 Sep 2017 12:05:27 +0200 Subject: [PATCH] [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. --- runbot/__openerp__.py | 4 +-- .../migrations/1.3/post-logging-build_id.py | 21 ++++++++++++ runbot/runbot.py | 32 +++++++++++++++++-- 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 runbot/migrations/1.3/post-logging-build_id.py diff --git a/runbot/__openerp__.py b/runbot/__openerp__.py index 3cebde6a..471709ac 100644 --- a/runbot/__openerp__.py +++ b/runbot/__openerp__.py @@ -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'], diff --git a/runbot/migrations/1.3/post-logging-build_id.py b/runbot/migrations/1.3/post-logging-build_id.py new file mode 100644 index 00000000..dc3375af --- /dev/null +++ b/runbot/migrations/1.3/post-logging-build_id.py @@ -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+-.+'; + """) diff --git a/runbot/runbot.py b/runbot/runbot.py index 264294dc..3be5516e 100644 --- a/runbot/runbot.py +++ b/runbot/runbot.py @@ -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 = {