From 2105c2f14dfed67c6ec6c0e37b7183bcf7162ac5 Mon Sep 17 00:00:00 2001 From: Josh Berkus Date: Wed, 22 Aug 2012 17:35:39 -0700 Subject: [PATCH] Add_product function, add B2G to database. Fixes bug 774290 --- sql/upgrade/17.7/README.rst | 16 +++++++ sql/upgrade/17.7/add_b2g.sql | 3 ++ sql/upgrade/17.7/add_product.sql | 73 ++++++++++++++++++++++++++++++++ sql/upgrade/17.7/upgrade.sh | 30 +++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 sql/upgrade/17.7/README.rst create mode 100644 sql/upgrade/17.7/add_b2g.sql create mode 100644 sql/upgrade/17.7/add_product.sql create mode 100755 sql/upgrade/17.7/upgrade.sh diff --git a/sql/upgrade/17.7/README.rst b/sql/upgrade/17.7/README.rst new file mode 100644 index 0000000000..775238faeb --- /dev/null +++ b/sql/upgrade/17.7/README.rst @@ -0,0 +1,16 @@ +.. This Source Code Form is subject to the terms of the Mozilla Public +.. License, v. 2.0. If a copy of the MPL was not distributed with this +.. file, You can obtain one at http://mozilla.org/MPL/2.0/. + +17.7 Database Updates +===================== + +This batch makes the following database changes: + +bug #774290 + Add B2G to database. + +... + +The above changes should take only a few minutes to deploy. +This upgrade does not require a downtime. \ No newline at end of file diff --git a/sql/upgrade/17.7/add_b2g.sql b/sql/upgrade/17.7/add_b2g.sql new file mode 100644 index 0000000000..bfc98c96a3 --- /dev/null +++ b/sql/upgrade/17.7/add_b2g.sql @@ -0,0 +1,3 @@ +\set ON_ERROR_STOP 1 + +SELECT add_new_product('B2G','17.0','{3c2e2abc-06d4-11e1-ac3b-374f68613e61}','b2g'); \ No newline at end of file diff --git a/sql/upgrade/17.7/add_product.sql b/sql/upgrade/17.7/add_product.sql new file mode 100644 index 0000000000..1b5af4e59a --- /dev/null +++ b/sql/upgrade/17.7/add_product.sql @@ -0,0 +1,73 @@ +-- This Source Code Form is subject to the terms of the Mozilla Public +-- License, v. 2.0. If a copy of the MPL was not distributed with this +-- file, You can obtain one at http://mozilla.org/MPL/2.0/. + +\set ON_ERROR_STOP 1 + +create or replace function add_new_product( + prodname text, + initversion major_version, + prodid text default null, + ftpname text default null, + release_throttle numeric default 1.0 ) +returns boolean +language plpgsql +as $f$ +declare current_sort int; + rel_name text; +begin + +IF prodname IS NULL OR initversion IS NULL THEN + RAISE EXCEPTION 'a product name and initial version are required'; +END IF; + +-- check if product already exists +PERFORM 1 FROM products +WHERE product_name = prodname; + +IF FOUND THEN + RAISE INFO 'product % is already in the database'; + RETURN FALSE; +END IF; + +-- add the product +SELECT max(sort) INTO current_sort +FROM products; + +INSERT INTO products ( product_name, sort, rapid_release_version, + release_name ) +VALUES ( prodname, current_sort + 1, initversion, + COALESCE(ftpname, prodname)); + +-- add the release channels + +INSERT INTO product_release_channels ( product_name, release_channel ) +SELECT prodname, release_channel +FROM release_channels; + +-- if throttling, change throttle for release versions + +IF release_throttle < 1.0 THEN + + UPDATE product_release_channels + SET throttle = release_throttle + WHERE product_name = prodname + AND release_channel = 'release'; + +END IF; + +-- add the productid map + +IF prodid IS NOT NULL THEN + INSERT INTO product_productid_map ( product_name, + productid, version_began ) + VALUES ( prodname, prodid, initversion ); +END IF; + +RETURN TRUE; + +END;$f$; + + + + diff --git a/sql/upgrade/17.7/upgrade.sh b/sql/upgrade/17.7/upgrade.sh new file mode 100755 index 0000000000..8c1d1bc719 --- /dev/null +++ b/sql/upgrade/17.7/upgrade.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#please see README + +set -e + +CURDIR=$(dirname $0) +DBNAME=$1 +: ${DBNAME:="breakpad"} +VERSION=17.7 + +#echo '*********************************************************' +#echo 'support functions' +#psql -f ${CURDIR}/support_functions.sql $DBNAME + +echo '*********************************************************' +echo 'add add_new_product function and B2G to database' +echo 'bug 774290' +psql -f ${CURDIR}/add_product.sql $DBNAME +psql -f ${CURDIR}/add_b2g.sql $DBNAME + +#change version in DB +psql -c "SELECT update_socorro_db_version( '$VERSION' )" $DBNAME + +echo "$VERSION upgrade done" + +exit 0 \ No newline at end of file