Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

4.0 database changes #458

Merged
merged 2 commits into from over 2 years ago

1 participant

Josh Berkus
Josh Berkus
Collaborator

No description provided.

Josh Berkus jberkus merged commit a978f8c into from
Josh Berkus jberkus closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
27 docs/databaseadminfunctions.rst
Source Rendered
@@ -253,6 +253,33 @@ such, running either the update or backfill function replaces all existing data.
253 253 Since it needs an exclusive lock on the matview, it is possible (though
254 254 unlikely) for it to fail to obtain the lock and error out.
255 255
  256 +update_nightly_builds, backfill_nightly_builds
  257 +----------------------------------------------
  258 +
  259 +Purpose: updates "nightly_builds" based on the contents of the reports_clean table
  260 +
  261 +Called By: daily cron job
  262 +
  263 +::
  264 +
  265 + update_nightly_builds (
  266 + updateday DATE optional default yesterday,
  267 + checkdata BOOLEAN optional default true
  268 + )
  269 +
  270 + SELECT update_nightly_builds ( '2011-11-26' );
  271 +
  272 + backfill_nightly_builds (
  273 + updateday DATE optional default yesterday
  274 + )
  275 +
  276 + SELECT backfill_nightly_builds ( '2011-11-26' );
  277 +
  278 +updateday
  279 + UTC day to pull data for.
  280 +checkdata
  281 + whether or not to check dependant data and throw an error if it's not found. Optional.
  282 +
256 283
257 284 Schema Management Functions
258 285 ===========================
12 sql/upgrade/4.0/README.rst
Source Rendered
... ... @@ -0,0 +1,12 @@
  1 +4.0 Database Updates
  2 +====================
  3 +
  4 +This batch makes the following database changes:
  5 +
  6 +bug 738323
  7 + add column for startup crash count to TCBS
  8 +
  9 +...
  10 +
  11 +The above changes should take only a few minutes to deploy.
  12 +This upgrade does not require a downtime.
4 sql/upgrade/4.0/add_startup_crashes_col.sql
... ... @@ -0,0 +1,4 @@
  1 +\set ON_ERROR_STOP 1
  2 +
  3 +alter table tcbs add column startup_count int;
  4 +
76 sql/upgrade/4.0/update_tcbs.sql
... ... @@ -0,0 +1,76 @@
  1 +\set ON_ERROR_STOP 1
  2 +
  3 +create or replace function update_tcbs (
  4 + updateday date, checkdata boolean default true )
  5 +RETURNS BOOLEAN
  6 +LANGUAGE plpgsql
  7 +SET work_mem = '512MB'
  8 +SET temp_buffers = '512MB'
  9 +AS $f$
  10 +BEGIN
  11 +-- this procedure goes throught the daily TCBS update for the
  12 +-- new TCBS table
  13 +-- designed to be run only once for each day
  14 +-- this new version depends on reports_clean
  15 +
  16 +-- check that it hasn't already been run
  17 +
  18 +IF checkdata THEN
  19 + PERFORM 1 FROM tcbs
  20 + WHERE report_date = updateday LIMIT 1;
  21 + IF FOUND THEN
  22 + RAISE EXCEPTION 'TCBS has already been run for the day %.',updateday;
  23 + END IF;
  24 +END IF;
  25 +
  26 +-- check if reports_clean is complete
  27 +IF NOT reports_clean_done(updateday) THEN
  28 + IF checkdata THEN
  29 + RAISE EXCEPTION 'Reports_clean has not been updated to the end of %',updateday;
  30 + ELSE
  31 + RETURN TRUE;
  32 + END IF;
  33 +END IF;
  34 +
  35 +-- populate the matview
  36 +
  37 +INSERT INTO tcbs (
  38 + signature_id, report_date, product_version_id,
  39 + process_type, release_channel,
  40 + report_count, win_count, mac_count, lin_count, hang_count,
  41 + startup_count
  42 +)
  43 +SELECT signature_id, updateday, product_version_id,
  44 + process_type, release_channel,
  45 + count(*),
  46 + sum(case when os_name = 'Windows' THEN 1 else 0 END),
  47 + sum(case when os_name = 'Mac OS X' THEN 1 else 0 END),
  48 + sum(case when os_name = 'Linux' THEN 1 else 0 END),
  49 + count(hang_id),
  50 + sum(case when uptime < INTERVAL '1 minute' THEN 1 else 0 END)
  51 +FROM reports_clean
  52 + JOIN product_versions USING (product_version_id)
  53 + WHERE utc_day_is(date_processed, updateday)
  54 + AND tstz_between(date_processed, build_date, sunset_date)
  55 +GROUP BY signature_id, updateday, product_version_id,
  56 + process_type, release_channel;
  57 +
  58 +ANALYZE tcbs;
  59 +
  60 +-- tcbs_ranking removed until it's being used
  61 +
  62 +-- done
  63 +RETURN TRUE;
  64 +END;
  65 +$f$;
  66 +
  67 +
  68 +
  69 +
  70 +
  71 +
  72 +
  73 +
  74 +
  75 +
  76 +
24 sql/upgrade/4.0/upgrade.sh
... ... @@ -0,0 +1,24 @@
  1 +#!/bin/bash
  2 +#please see README
  3 +
  4 +set -e
  5 +
  6 +CURDIR=$(dirname $0)
  7 +VERSION=4.0
  8 +
  9 +#echo '*********************************************************'
  10 +#echo 'support functions'
  11 +#psql -f ${CURDIR}/support_functions.sql breakpad
  12 +
  13 +echo '*********************************************************'
  14 +echo 'add startup crash count to TCBS'
  15 +echo 'bug 738323'
  16 +psql -f ${CURDIR}/add_startup_crashes_col.sql breakpad
  17 +psql -f ${CURDIR}/update_tcbs.sql breakpad
  18 +
  19 +#change version in DB
  20 +psql -c "SELECT update_socorro_db_version( '$VERSION' )" breakpad
  21 +
  22 +echo "$VERSION upgrade done"
  23 +
  24 +exit 0

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.