Skip to content

Commit

Permalink
Merge pull request mozilla-services#448 from jberkus/master
Browse files Browse the repository at this point in the history
3.0 new function get_product_version_ids, drop build_date
  • Loading branch information
jberkus committed Mar 21, 2012
2 parents 26b486f + 24cfcb2 commit e0a574d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/databasemiscfunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,15 @@ get_product_version_ids
versions VARIADIC CITEXT
)
SELECT get_product_version_ids ( 'Firefox','11.0a1' );
SELECT get_product_version_ids ( 'Firefox','11.0a1','11.0a2','11.0b1');
Takes a product name and a list of version_strings, and returns an array (list) of surrogate keys (product_version_ids) which can then be used in queries like:

::

SELECT * FROM reports_clean WHERE date_processed BETWEEN '2012-03-21' AND '2012-03-38'
WHERE product_version_id = ANY ( $list );
Expand Down
16 changes: 16 additions & 0 deletions sql/upgrade/3.0/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
3.0 Database Updates
====================

This batch makes the following database changes:

No Bug
Add function for middleware to retrieve lists of product_versions
from the DB.

729208
Drop redundant build_date column from reports.

...

Bug 729208 may require locking on reports, and thus require a brief (5 minutes) processor downtime.
Aside from locking, neither should take more than a couple minutes to run.
10 changes: 10 additions & 0 deletions sql/upgrade/3.0/drop_reports_build_date.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
\set ON_ERROR_STOP 1

DO $f$
BEGIN

PERFORM try_lock_table('reports','ACCESS EXCLUSIVE');

ALTER TABLE reports DROP COLUMN build_date;

END;$f$;
16 changes: 16 additions & 0 deletions sql/upgrade/3.0/get_product_version_ids.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
\set ON_ERROR_STOP 1

CREATE OR REPLACE FUNCTION get_product_version_ids (
product CITEXT,
VARIADIC versions CITEXT[]
)
returns INT[]
language sql
as $f$
SELECT array_agg(product_version_id)
FROM product_versions
WHERE product_name = $1
AND version_string = ANY ( $2 );
$f$;


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

set -e

CURDIR=$(dirname $0)
VERSION=3.0

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

echo '*********************************************************'
echo 'add middleware function for retrieving lists of product-versions'
echo 'no bug'
psql -f ${CURDIR}/get_product_version_ids.sql breakpad

echo '*********************************************************'
echo 'drop build_date column from reports'
echo 'bug #729208'
psql -f ${CURDIR}/drop_reports_build_date.sql breakpad

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

echo "$VERSION upgrade done"

exit 0

0 comments on commit e0a574d

Please sign in to comment.