Skip to content

Commit

Permalink
Merge pull request mozilla-services#649 from jberkus/master
Browse files Browse the repository at this point in the history
13.0 DB migration scripts.
  • Loading branch information
Josh Berkus committed Jun 14, 2012
2 parents 9ea4f9f + 295337f commit b221cb1
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 5 deletions.
12 changes: 7 additions & 5 deletions sql/templates/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
set -e

CURDIR=$(dirname $0)
DBNAME=$1
: ${DBNAME:="breakpad"}
VERSION=#.#

#echo '*********************************************************'
#echo 'support functions'
#psql -f ${CURDIR}/support_functions.sql breakpad
#psql -f ${CURDIR}/support_functions.sql $DBNAME

echo '*********************************************************'
echo 'fix '
echo 'no bug'
psql -f ${CURDIR}/_____.sql breakpad
psql -f ${CURDIR}/_____.sql $DBNAME

echo '*********************************************************'
echo 'fix '
echo 'bug ######'
psql -f ${CURDIR}/_____.sql breakpad
psql -f ${CURDIR}/_____.sql breakpad
psql -f ${CURDIR}/_____.sql $DBNAME
psql -f ${CURDIR}/_____.sql $DBNAME

#change version in DB
psql -c "SELECT update_socorro_db_version( '$VERSION' )" breakpad
psql -c "SELECT update_socorro_db_version( '$VERSION' )" $DBNAME

echo "$VERSION upgrade done"

Expand Down
18 changes: 18 additions & 0 deletions sql/upgrade/13.0/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#.# Database Updates
====================

This batch makes the following database changes:

bug 764468
replace existing processor ganglia views with a new
view based on server_status

bug 763552
make add_new_releases() better for ftpscraper

...

The above changes should take only a few minutes to deploy.
This upgrade does not require a downtime. This upgrade will
break ganglia monitoring which is already displaying incorrect
results.
73 changes: 73 additions & 0 deletions sql/upgrade/13.0/add_release.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
\set ON_ERROR_STOP 1

DROP FUNCTION IF EXISTS add_new_release ( citext, citext, citext,
numeric, citext, integer, text, boolean );

CREATE OR REPLACE FUNCTION add_new_release (
product citext,
version citext,
release_channel citext,
build_id numeric,
platform citext,
beta_number integer default NULL,
repository text default 'release',
update_products boolean default false,
ignore_duplicates boolean default false
)
RETURNS boolean
LANGUAGE plpgsql
AS $f$
BEGIN
-- adds a new release to the releases_raw table
-- to be picked up by update_products later
-- does some light format validation

-- check for NULLs, blanks
IF NOT ( nonzero_string(product) AND nonzero_string(version)
AND nonzero_string(release_channel) and nonzero_string(platform)
AND build_id IS NOT NULL ) THEN
RAISE EXCEPTION 'product, version, release_channel, platform and build ID are all required';
END IF;

--validations
-- validate product
PERFORM validate_lookup('products','product_name',product,'product');
--validate channel
PERFORM validate_lookup('release_channels','release_channel',release_channel,'release channel');
--validate build
IF NOT ( build_date(build_id) BETWEEN '2005-01-01'
AND (current_date + INTERVAL '1 month') ) THEN
RAISE EXCEPTION 'invalid buildid';
END IF;

--add row
--duplicate check will occur in the EXECEPTION section
INSERT INTO releases_raw (
product_name, version, platform, build_id,
build_type, beta_number, repository )
VALUES ( product, version, platform, build_id,
release_channel, beta_number, repository );

--call update_products, if desired
IF update_products THEN
PERFORM update_product_versions();
END IF;

--return
RETURN TRUE;

--exception clause, mainly catches duplicate rows.
EXCEPTION
WHEN UNIQUE_VIOLATION THEN
IF ignore_duplicates THEN
RETURN FALSE;
ELSE
RAISE EXCEPTION 'the release you have entered is already present in he database';
END;$f$;







24 changes: 24 additions & 0 deletions sql/upgrade/13.0/processor_monitoring_views.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
\set ON_ERROR_STOP 1

DROP VIEW IF EXISTS jobs_in_queue;

DROP VIEW IF EXISTS processor_count;

CREATE OR REPLACE VIEW current_server_status AS
SELECT
date_recently_completed,
date_oldest_job_queued,
extract('epoch' from (date_created - date_oldest_job_queued)) as oldest_job_age,
avg_process_sec,
avg_wait_sec,
waiting_job_count,
processors_count,
date_created
FROM server_status
ORDER BY date_created DESC LIMIT 1;

ALTER VIEW current_server_status OWNER TO breakpad_rw;

GRANT SELECT on current_server_status TO monitoring;


26 changes: 26 additions & 0 deletions sql/upgrade/13.0/upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#please see README

set -e

CURDIR=$(dirname $0)
DBNAME=$1
: ${DBNAME:="breakpad"}
VERSION=13.0

echo '*********************************************************'
echo 'replace processor monitoring view for ganglia'
echo 'bug 764468'
psql -f ${CURDIR}/processor_monitoring.sql $DBNAME

echo '*********************************************************'
echo 'modify add_new_release to better support ftpscraper'
echo 'bug 763552'
psql -f ${CURDIR}/add_release.sql $DBNAME

#change version in DB
psql -c "SELECT update_socorro_db_version( '$VERSION' )" $DBNAME

echo "$VERSION upgrade done"

exit 0

0 comments on commit b221cb1

Please sign in to comment.