# points
#
-class Events(base.Object):
- def init(self):
- # Create events view
- self.db.execute("""
- CREATE TEMPORARY VIEW events AS (
- -- Build creation times
- SELECT
- 'build-created'::text AS type,
- builds.created_at AS t,
- 4 AS priority,
- builds.id AS build,
- NULL::integer AS by_build,
- NULL::integer AS build_comment,
- NULL::integer AS build_group,
- NULL::integer AS job,
- NULL::text AS package_name,
- NULL::integer AS mirror,
- NULL::integer AS user,
- builds.owner_id AS by_user,
- NULL::integer AS builder,
- NULL::integer AS repository,
- NULL::integer AS release,
- NULL::integer AS bug,
- NULL::text AS error,
- NULL::integer AS points
- FROM
- builds
-
- UNION ALL
-
- -- Build finish/failed times
- SELECT
- CASE
- WHEN builds.failed IS TRUE
- THEN 'build-failed'::text
- ELSE 'build-finished'::text
- END AS type,
- builds.finished_at AS t,
- CASE
- WHEN builds.failed IS TRUE
- THEN 8
- ELSE 4
- END AS priority,
- builds.id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- builds
- WHERE
- builds.finished_at IS NOT NULL
-
- UNION ALL
-
- -- Deleted Builds
- SELECT
- 'build-deleted' AS type,
- builds.deleted_at AS t,
- 4 AS priority,
- builds.id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- builds.deleted_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- builds
- WHERE
- builds.deleted_at IS NOT NULL
-
- UNION ALL
-
- -- Deprecated Builds
-
- SELECT
- 'build-deprecated' AS type,
- builds.deprecated_at AS t,
- 4 AS priority,
- builds.id AS build,
- builds.deprecating_build_id AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- builds.deprecated_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- builds
- WHERE
- builds.deleted_at IS NULL
- AND
- builds.deprecated_at IS NOT NULL
-
- UNION ALL
-
- -- Build Comments
- SELECT
- 'build-comment' AS type,
- build_comments.created_at AS t,
- 5 AS priority,
- build_comments.build_id AS build,
- NULL AS by_build,
- build_comments.id AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- build_comments.user_id AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- build_comments
- WHERE
- deleted IS FALSE
-
- UNION ALL
-
- -- Build Watchers added
- SELECT
- 'build-watcher-added' AS type,
- build_watchers.added_at AS t,
- 1 AS priority,
- build_watchers.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- build_watchers.user_id AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- build_watchers
-
- UNION ALL
-
- -- Build Watchers removed
- SELECT
- 'build-watcher-removed' AS type,
- build_watchers.deleted_at AS t,
- 1 AS priority,
- build_watchers.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- build_watchers.user_id AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- build_watchers
- WHERE
- deleted_at IS NOT NULL
-
- UNION ALL
-
- -- Bugs added to builds
- SELECT
- 'build-bug-added' AS type,
- build_bugs.added_at AS t,
- 4 AS priority,
- build_bugs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- build_bugs.added_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- build_bugs.bug_id AS bug,
- NULL AS error,
- NULL AS points
- FROM
- build_bugs
-
- UNION ALL
-
- -- Bugs removed from builds
-
- SELECT
- 'build-bug-removed' AS type,
- build_bugs.removed_at AS t,
- 4 AS priority,
- build_bugs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- build_bugs.removed_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- build_bugs.bug_id AS bug,
- NULL AS error,
- NULL AS points
- FROM
- build_bugs
- WHERE
- removed_at IS NOT NULL
-
- UNION ALL
-
- -- Build added to repository
- SELECT
- 'repository-build-added' AS type,
- repository_builds.added_at AS t,
- 5 AS priority,
- repository_builds.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- repository_builds.added_by AS by_user,
- NULL AS builder,
- repository_builds.repo_id AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- repository_builds
-
- UNION ALL
-
- -- Build removed from repository
- SELECT
- 'repository-build-removed' AS type,
- repository_builds.removed_at AS t,
- 5 AS priority,
- repository_builds.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- repository_builds.removed_by AS by_user,
- NULL AS builder,
- repository_builds.repo_id AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- repository_builds
- WHERE
- removed_at IS NOT NULL
-
- UNION ALL
-
- -- Build Points
-
- SELECT
- 'build-points' AS type,
- build_points.created_at AS t,
- 1 AS priority,
- build_points.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- build_points.user_id AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- build_points.points AS points
- FROM
- build_points
-
- UNION ALL
-
- -- Test Builds
- SELECT
- CASE WHEN build_groups.failed IS TRUE THEN 'test-builds-failed'
- ELSE 'test-builds-succeeded' END AS type,
- build_groups.finished_at AS t,
- 4 AS priority,
- builds.id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- build_groups.id AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- builds
- JOIN
- build_groups ON builds.test_group_id = build_groups.id
- WHERE
- builds.deleted_at IS NULL
- AND
- build_groups.deleted_at IS NULL
- AND
- build_groups.finished_at IS NOT NULL
-
- UNION ALL
-
- -- Jobs Creations
- SELECT
- 'job-created' AS type,
- jobs.created_at AS t,
- 1 AS priority,
- jobs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- jobs.id AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- jobs
- WHERE
- jobs.deleted_at IS NULL
-
- UNION ALL
-
- -- Failed Jobs
- SELECT
- 'job-failed' AS type,
- jobs.finished_at AS t,
- 5 AS priority,
- jobs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- jobs.id AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- jobs.builder_id AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- jobs
- WHERE
- jobs.deleted_at IS NULL
- AND
- jobs.finished_at IS NOT NULL
- AND
- jobs.aborted IS FALSE
- AND
- jobs.failed IS TRUE
-
- UNION ALL
-
- -- Finished Jobs
- SELECT
- 'job-finished' AS type,
- jobs.finished_at AS t,
- 4 AS priority,
- jobs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- jobs.id AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- jobs.builder_id AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- jobs
- WHERE
- jobs.deleted_at IS NULL
- AND
- jobs.finished_at IS NOT NULL
- AND
- jobs.aborted IS FALSE
- AND
- jobs.failed IS FALSE
-
- UNION ALL
-
- -- Aborted Jobs
- SELECT
- 'job-aborted' AS type,
- jobs.finished_at AS t,
- 4 AS priority,
- jobs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- jobs.id AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- jobs.aborted_by AS by_user,
- jobs.builder_id AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- jobs
- WHERE
- jobs.deleted_at IS NULL
- AND
- jobs.aborted IS TRUE
-
- UNION ALL
-
- -- Dispatched Jobs
- SELECT
- 'job-dispatched' AS type,
- jobs.started_at AS t,
- 1 AS priority,
- jobs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- jobs.id AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- jobs.builder_id AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- jobs
- WHERE
- jobs.deleted_at IS NULL
- AND
- jobs.started_at IS NOT NULL
-
- UNION ALL
-
- -- Retried jobs
- SELECT
- 'job-retry' AS type,
- jobs.created_at AS t,
- 4 AS priority,
- jobs.build_id AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- jobs.id AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- jobs
- JOIN
- jobs superseeded_jobs ON superseeded_jobs.superseeded_by = jobs.id
- WHERE
- jobs.deleted_at IS NULL
-
- UNION ALL
-
- -- Builders Created
- SELECT
- 'builder-created' AS type,
- builders.created_at AS t,
- 5 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- builders.created_by AS by_user,
- builders.id AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- builders
-
- UNION ALL
-
- -- Builders Deleted
- SELECT
- 'builder-deleted' AS type,
- builders.deleted_at AS t,
- 5 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- builders.deleted_by AS by_user,
- builders.id AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- builders
- WHERE
- builders.deleted_at IS NOT NULL
-
- UNION ALL
-
- -- Releases Created
- SELECT
- 'release-created' AS type,
- releases.created_at AS t,
- 1 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- releases.created_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- releases.id AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- releases
-
- UNION ALL
-
- -- Releases Deleted
- SELECT
- 'release-deleted' AS type,
- releases.deleted_at AS t,
- 1 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- releases.deleted_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- releases.id AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- releases
- WHERE
- deleted_at IS NOT NULL
-
- UNION ALL
-
- -- Releases Published
- SELECT
- 'release-published' AS type,
- releases.published_at AS t,
- CASE WHEN releases.stable IS TRUE
- THEN 5 ELSE 4 END AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- NULL AS mirror,
- NULL AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- releases.id AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- releases
- WHERE
- published_at IS NOT NULL
- AND
- published_at <= CURRENT_TIMESTAMP
-
- UNION ALL
-
- -- Mirrors Created
- SELECT
- 'mirror-created' AS type,
- mirrors.created_at AS t,
- 5 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- mirrors.id AS mirror,
- NULL AS user,
- mirrors.created_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- mirrors
-
- UNION ALL
-
- -- Mirrors Deleted
- SELECT
- 'mirror-deleted' AS type,
- mirrors.deleted_at AS t,
- 5 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- mirrors.id AS mirror,
- NULL AS user,
- mirrors.deleted_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- mirrors
- WHERE
- deleted_at IS NOT NULL
-
- UNION ALL
-
- -- Mirror Status Changes
- SELECT
- CASE
- WHEN mirror_status_changes.new_status IS TRUE
- THEN 'mirror-online'
- WHEN mirror_status_changes.new_status IS FALSE
- THEN 'mirror-offline'
- END AS type,
- mirror_status_changes.checked_at AS t,
- 4 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- NULL AS package_name,
- mirror_status_changes.mirror_id AS mirror,
- NULL AS user,
- NULL AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- mirror_status_changes.error AS error,
- NULL AS points
- FROM (
- SELECT
- mirror_checks.mirror_id AS mirror_id,
- mirror_checks.checked_at AS checked_at,
- mirror_checks.success AS new_status,
- LAG(success) OVER (
- PARTITION BY mirror_id
- ORDER BY checked_at ASC
- ) AS old_status,
- mirror_checks.error AS error
- FROM
- mirror_checks
- ) mirror_status_changes
- WHERE
- mirror_status_changes.old_status <> mirror_status_changes.new_status
-
- UNION ALL
-
- -- Release Monitoring Created
- SELECT
- 'release-monitoring-created' AS type,
- release_monitorings.created_at AS t,
- 4 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- release_monitorings.name AS package_name,
- NULL AS mirror,
- NULL AS user,
- release_monitorings.created_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- release_monitorings
-
- UNION ALL
-
- -- Release Monitoring Deleted
- SELECT
- 'release-monitoring-deleted' AS type,
- release_monitorings.deleted_at AS t,
- 4 AS priority,
- NULL AS build,
- NULL AS by_build,
- NULL AS build_comment,
- NULL AS build_group,
- NULL AS job,
- release_monitorings.name AS package_name,
- NULL AS mirror,
- NULL AS user,
- release_monitorings.deleted_by AS by_user,
- NULL AS builder,
- NULL AS repository,
- NULL AS release,
- NULL AS bug,
- NULL AS error,
- NULL AS points
- FROM
- release_monitorings
- WHERE
- deleted_at IS NOT NULL
- )
- """)
+EVENTS_CTE = """
+ WITH events AS (
+ -- Build creation times
+ SELECT
+ 'build-created'::text AS type,
+ builds.created_at AS t,
+ 4 AS priority,
+ builds.id AS build,
+ NULL::integer AS by_build,
+ NULL::integer AS build_comment,
+ NULL::integer AS build_group,
+ NULL::integer AS job,
+ NULL::text AS package_name,
+ NULL::integer AS mirror,
+ NULL::integer AS user,
+ builds.owner_id AS by_user,
+ NULL::integer AS builder,
+ NULL::integer AS repository,
+ NULL::integer AS release,
+ NULL::integer AS bug,
+ NULL::text AS error,
+ NULL::integer AS points
+ FROM
+ builds
+
+ UNION ALL
+
+ -- Build finish/failed times
+ SELECT
+ CASE
+ WHEN builds.failed IS TRUE
+ THEN 'build-failed'::text
+ ELSE 'build-finished'::text
+ END AS type,
+ builds.finished_at AS t,
+ CASE
+ WHEN builds.failed IS TRUE
+ THEN 8
+ ELSE 4
+ END AS priority,
+ builds.id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ builds
+ WHERE
+ builds.finished_at IS NOT NULL
+
+ UNION ALL
+
+ -- Deleted Builds
+ SELECT
+ 'build-deleted' AS type,
+ builds.deleted_at AS t,
+ 4 AS priority,
+ builds.id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ builds.deleted_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ builds
+ WHERE
+ builds.deleted_at IS NOT NULL
+
+ UNION ALL
+
+ -- Deprecated Builds
+
+ SELECT
+ 'build-deprecated' AS type,
+ builds.deprecated_at AS t,
+ 4 AS priority,
+ builds.id AS build,
+ builds.deprecating_build_id AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ builds.deprecated_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ builds
+ WHERE
+ builds.deleted_at IS NULL
+ AND
+ builds.deprecated_at IS NOT NULL
+
+ UNION ALL
+
+ -- Build Comments
+ SELECT
+ 'build-comment' AS type,
+ build_comments.created_at AS t,
+ 5 AS priority,
+ build_comments.build_id AS build,
+ NULL AS by_build,
+ build_comments.id AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ build_comments.user_id AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ build_comments
+ WHERE
+ deleted IS FALSE
+
+ UNION ALL
+
+ -- Build Watchers added
+ SELECT
+ 'build-watcher-added' AS type,
+ build_watchers.added_at AS t,
+ 1 AS priority,
+ build_watchers.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ build_watchers.user_id AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ build_watchers
+
+ UNION ALL
+
+ -- Build Watchers removed
+ SELECT
+ 'build-watcher-removed' AS type,
+ build_watchers.deleted_at AS t,
+ 1 AS priority,
+ build_watchers.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ build_watchers.user_id AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ build_watchers
+ WHERE
+ deleted_at IS NOT NULL
+
+ UNION ALL
+
+ -- Bugs added to builds
+ SELECT
+ 'build-bug-added' AS type,
+ build_bugs.added_at AS t,
+ 4 AS priority,
+ build_bugs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ build_bugs.added_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ build_bugs.bug_id AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ build_bugs
+
+ UNION ALL
+
+ -- Bugs removed from builds
+
+ SELECT
+ 'build-bug-removed' AS type,
+ build_bugs.removed_at AS t,
+ 4 AS priority,
+ build_bugs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ build_bugs.removed_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ build_bugs.bug_id AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ build_bugs
+ WHERE
+ removed_at IS NOT NULL
+
+ UNION ALL
+
+ -- Build added to repository
+ SELECT
+ 'repository-build-added' AS type,
+ repository_builds.added_at AS t,
+ 5 AS priority,
+ repository_builds.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ repository_builds.added_by AS by_user,
+ NULL AS builder,
+ repository_builds.repo_id AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ repository_builds
+
+ UNION ALL
+
+ -- Build removed from repository
+ SELECT
+ 'repository-build-removed' AS type,
+ repository_builds.removed_at AS t,
+ 5 AS priority,
+ repository_builds.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ repository_builds.removed_by AS by_user,
+ NULL AS builder,
+ repository_builds.repo_id AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ repository_builds
+ WHERE
+ removed_at IS NOT NULL
+
+ UNION ALL
+
+ -- Build Points
+
+ SELECT
+ 'build-points' AS type,
+ build_points.created_at AS t,
+ 1 AS priority,
+ build_points.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ build_points.user_id AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ build_points.points AS points
+ FROM
+ build_points
+
+ UNION ALL
+
+ -- Test Builds
+ SELECT
+ CASE WHEN build_groups.failed IS TRUE THEN 'test-builds-failed'
+ ELSE 'test-builds-succeeded' END AS type,
+ build_groups.finished_at AS t,
+ 4 AS priority,
+ builds.id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ build_groups.id AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ builds
+ JOIN
+ build_groups ON builds.test_group_id = build_groups.id
+ WHERE
+ builds.deleted_at IS NULL
+ AND
+ build_groups.deleted_at IS NULL
+ AND
+ build_groups.finished_at IS NOT NULL
+
+ UNION ALL
+
+ -- Jobs Creations
+ SELECT
+ 'job-created' AS type,
+ jobs.created_at AS t,
+ 1 AS priority,
+ jobs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ jobs.id AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ jobs
+ WHERE
+ jobs.deleted_at IS NULL
+
+ UNION ALL
+
+ -- Failed Jobs
+ SELECT
+ 'job-failed' AS type,
+ jobs.finished_at AS t,
+ 5 AS priority,
+ jobs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ jobs.id AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ jobs.builder_id AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ jobs
+ WHERE
+ jobs.deleted_at IS NULL
+ AND
+ jobs.finished_at IS NOT NULL
+ AND
+ jobs.aborted IS FALSE
+ AND
+ jobs.failed IS TRUE
+
+ UNION ALL
+
+ -- Finished Jobs
+ SELECT
+ 'job-finished' AS type,
+ jobs.finished_at AS t,
+ 4 AS priority,
+ jobs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ jobs.id AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ jobs.builder_id AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ jobs
+ WHERE
+ jobs.deleted_at IS NULL
+ AND
+ jobs.finished_at IS NOT NULL
+ AND
+ jobs.aborted IS FALSE
+ AND
+ jobs.failed IS FALSE
+
+ UNION ALL
+
+ -- Aborted Jobs
+ SELECT
+ 'job-aborted' AS type,
+ jobs.finished_at AS t,
+ 4 AS priority,
+ jobs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ jobs.id AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ jobs.aborted_by AS by_user,
+ jobs.builder_id AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ jobs
+ WHERE
+ jobs.deleted_at IS NULL
+ AND
+ jobs.aborted IS TRUE
+
+ UNION ALL
+
+ -- Dispatched Jobs
+ SELECT
+ 'job-dispatched' AS type,
+ jobs.started_at AS t,
+ 1 AS priority,
+ jobs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ jobs.id AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ jobs.builder_id AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ jobs
+ WHERE
+ jobs.deleted_at IS NULL
+ AND
+ jobs.started_at IS NOT NULL
+
+ UNION ALL
+
+ -- Retried jobs
+ SELECT
+ 'job-retry' AS type,
+ jobs.created_at AS t,
+ 4 AS priority,
+ jobs.build_id AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ jobs.id AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ jobs
+ JOIN
+ jobs superseeded_jobs ON superseeded_jobs.superseeded_by = jobs.id
+ WHERE
+ jobs.deleted_at IS NULL
+
+ UNION ALL
+
+ -- Builders Created
+ SELECT
+ 'builder-created' AS type,
+ builders.created_at AS t,
+ 5 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ builders.created_by AS by_user,
+ builders.id AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ builders
+
+ UNION ALL
+
+ -- Builders Deleted
+ SELECT
+ 'builder-deleted' AS type,
+ builders.deleted_at AS t,
+ 5 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ builders.deleted_by AS by_user,
+ builders.id AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ builders
+ WHERE
+ builders.deleted_at IS NOT NULL
+
+ UNION ALL
+
+ -- Releases Created
+ SELECT
+ 'release-created' AS type,
+ releases.created_at AS t,
+ 1 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ releases.created_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ releases.id AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ releases
+
+ UNION ALL
+
+ -- Releases Deleted
+ SELECT
+ 'release-deleted' AS type,
+ releases.deleted_at AS t,
+ 1 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ releases.deleted_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ releases.id AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ releases
+ WHERE
+ deleted_at IS NOT NULL
+
+ UNION ALL
+
+ -- Releases Published
+ SELECT
+ 'release-published' AS type,
+ releases.published_at AS t,
+ CASE WHEN releases.stable IS TRUE
+ THEN 5 ELSE 4 END AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ releases.id AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ releases
+ WHERE
+ published_at IS NOT NULL
+ AND
+ published_at <= CURRENT_TIMESTAMP
+
+ UNION ALL
+
+ -- Mirrors Created
+ SELECT
+ 'mirror-created' AS type,
+ mirrors.created_at AS t,
+ 5 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ mirrors.id AS mirror,
+ NULL AS user,
+ mirrors.created_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ mirrors
+
+ UNION ALL
+
+ -- Mirrors Deleted
+ SELECT
+ 'mirror-deleted' AS type,
+ mirrors.deleted_at AS t,
+ 5 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ mirrors.id AS mirror,
+ NULL AS user,
+ mirrors.deleted_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ mirrors
+ WHERE
+ deleted_at IS NOT NULL
+
+ UNION ALL
+
+ -- Mirror Status Changes
+ SELECT
+ CASE
+ WHEN mirror_status_changes.new_status IS TRUE
+ THEN 'mirror-online'
+ WHEN mirror_status_changes.new_status IS FALSE
+ THEN 'mirror-offline'
+ END AS type,
+ mirror_status_changes.checked_at AS t,
+ 4 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ NULL AS package_name,
+ mirror_status_changes.mirror_id AS mirror,
+ NULL AS user,
+ NULL AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ mirror_status_changes.error AS error,
+ NULL AS points
+ FROM (
+ SELECT
+ mirror_checks.mirror_id AS mirror_id,
+ mirror_checks.checked_at AS checked_at,
+ mirror_checks.success AS new_status,
+ LAG(success) OVER (
+ PARTITION BY mirror_id
+ ORDER BY checked_at ASC
+ ) AS old_status,
+ mirror_checks.error AS error
+ FROM
+ mirror_checks
+ ) mirror_status_changes
+ WHERE
+ mirror_status_changes.old_status <> mirror_status_changes.new_status
+
+ UNION ALL
+
+ -- Release Monitoring Created
+ SELECT
+ 'release-monitoring-created' AS type,
+ release_monitorings.created_at AS t,
+ 4 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ release_monitorings.name AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ release_monitorings.created_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ release_monitorings
+
+ UNION ALL
+
+ -- Release Monitoring Deleted
+ SELECT
+ 'release-monitoring-deleted' AS type,
+ release_monitorings.deleted_at AS t,
+ 4 AS priority,
+ NULL AS build,
+ NULL AS by_build,
+ NULL AS build_comment,
+ NULL AS build_group,
+ NULL AS job,
+ release_monitorings.name AS package_name,
+ NULL AS mirror,
+ NULL AS user,
+ release_monitorings.deleted_by AS by_user,
+ NULL AS builder,
+ NULL AS repository,
+ NULL AS release,
+ NULL AS bug,
+ NULL AS error,
+ NULL AS points
+ FROM
+ release_monitorings
+ WHERE
+ deleted_at IS NOT NULL
+ )
+"""
+class Events(base.Object):
@lazy_property
def map(self):
return {
values.append(priority)
# Fetch all events
- events = self.db.query("""
+ events = self.db.query(
+ """
+ %s
+
-- Filter out everything we want
SELECT
*
%%s
LIMIT
%%s
- """ % " AND ".join(conditions) or "TRUE",
+ """ % (EVENTS_CTE, " AND ".join(conditions) or "TRUE"),
*values, offset, limit,
)