Skip to content

Commit

Permalink
bug 855423 Change all RAISE ERROR -> NOTICE in stored procs
Browse files Browse the repository at this point in the history
* Add alembic migration (yay!)
* Fix a test that no longer needs to expect an exception
* Add OR REPLACE to CREATE FUNCTION
  • Loading branch information
selenamarie committed Apr 25, 2013
1 parent 5ac6f6d commit 53fcbaf
Show file tree
Hide file tree
Showing 111 changed files with 252 additions and 223 deletions.
33 changes: 0 additions & 33 deletions alembic/versions/5316d4cfc03a_adding_raw_crashes_a.py

This file was deleted.

54 changes: 54 additions & 0 deletions alembic/versions/5e14d46c725_bug_855423_change_ra.py
@@ -0,0 +1,54 @@
"""bug 855423 change RAISE EXCEPTION to RAISE NOTICE
Revision ID: 5e14d46c725
Revises: e5eb3c07f2a
Create Date: 2013-04-11 17:35:34.174009
"""

# revision identifiers, used by Alembic.
revision = '5e14d46c725'
down_revision = None

from alembic import op
import os

def upgrade():
# Load up all the new procedures
app_path=os.getcwd()
procs = [
'001_update_reports_clean.sql',
'add_column_if_not_exists.sql',
'add_new_product.sql',
'add_new_release.sql',
'backfill_matviews.sql',
'crontabber_nodelete.sql',
'drop_old_partitions.sql',
'edit_featured_versions.sql',
'edit_product_info.sql',
'update_adu.sql',
'update_build_adu.sql',
'update_correlations.sql',
'update_crashes_by_user_build.sql',
'update_crashes_by_user.sql',
'update_daily_crashes.sql',
'update_explosiveness.sql',
'update_hang_report.sql',
'update_home_page_graph_build.sql',
'update_home_page_graph.sql',
'update_nightly_builds.sql',
'update_os_versions.sql',
'update_rank_compare.sql',
'update_signatures.sql',
'update_tcbs_build.sql',
'update_tcbs.sql',
'validate_lookup.sql'
]
for myfile in [app_path + '/socorro/external/postgresql/raw_sql/procs/' + line for line in procs]:
proc = open(myfile, 'r').read()
op.execute(proc)

def downgrade():
# Tricky. Need to checkout previous revision in repo
# to do this, so leaving for now.
return True
26 changes: 0 additions & 26 deletions alembic/versions/e5eb3c07f2a_adding_uuid_to_exten.py

This file was deleted.

3 changes: 1 addition & 2 deletions alembic.ini → config/alembic.ini-dist
Expand Up @@ -11,8 +11,7 @@ file_template = %%(rev)s_%%(slug)s
# the 'revision' command, regardless of autogenerate
# revision_environment = false

sqlalchemy.url = postgresql://selena:death@localhost/breakpad

sqlalchemy.url = postgresql://breakpad_rw@localhost/breakpad

# Logging configuration
[loggers]
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION update_reports_clean(fromtime timestamp with time zone, fortime interval DEFAULT '01:00:00'::interval, checkdata boolean DEFAULT true, analyze_it boolean DEFAULT true) RETURNS boolean
CREATE OR REPLACE FUNCTION update_reports_clean(fromtime timestamp with time zone, fortime interval DEFAULT '01:00:00'::interval, checkdata boolean DEFAULT true, analyze_it boolean DEFAULT true) RETURNS boolean
LANGUAGE plpgsql
SET client_min_messages TO 'ERROR'
AS $_$
Expand Down Expand Up @@ -31,7 +31,8 @@ END IF;
-- prevent calling for a period of more than one day

IF fortime > INTERVAL '1 day' THEN
RAISE EXCEPTION 'you may not execute this function on more than one day of data';
RAISE NOTICE 'you may not execute this function on more than one day of data';
RETURN FALSE;
END IF;

-- create a temporary table from the hour of reports you want to
Expand Down Expand Up @@ -76,7 +77,8 @@ PERFORM 1 FROM new_reports
LIMIT 1;
IF NOT FOUND THEN
IF checkdata THEN
RAISE EXCEPTION 'no report data found for period %',fromtime;
RAISE NOTICE 'no report data found for period %',fromtime;
RETURN FALSE;
ELSE
DROP TABLE new_reports;
RETURN TRUE;
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION version_sort_digit(digit text) RETURNS text
CREATE OR REPLACE FUNCTION version_sort_digit(digit text) RETURNS text
LANGUAGE sql IMMUTABLE
AS $_$
-- converts an individual part of a version number
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION major_version_sort(version text) RETURNS text
CREATE OR REPLACE FUNCTION major_version_sort(version text) RETURNS text
LANGUAGE sql IMMUTABLE
AS $_$
-- converts a major_version string into a padded,
Expand Down
4 changes: 2 additions & 2 deletions socorro/external/postgresql/raw_sql/procs/004_crash_hadu.sql
@@ -1,4 +1,4 @@
CREATE FUNCTION crash_hadu(crashes bigint, adu bigint, throttle numeric DEFAULT 1.0) RETURNS numeric
CREATE OR REPLACE FUNCTION crash_hadu(crashes bigint, adu bigint, throttle numeric DEFAULT 1.0) RETURNS numeric
LANGUAGE sql
AS $_$
SELECT CASE WHEN $2 = 0 THEN 0::numeric
Expand All @@ -7,7 +7,7 @@ ELSE
END;
$_$;

CREATE FUNCTION crash_hadu(crashes bigint, adu numeric, throttle numeric DEFAULT 1.0) RETURNS numeric
CREATE OR REPLACE FUNCTION crash_hadu(crashes bigint, adu numeric, throttle numeric DEFAULT 1.0) RETURNS numeric
LANGUAGE sql
AS $_$
SELECT CASE WHEN $2 = 0 THEN 0::numeric
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION add_column_if_not_exists(tablename text, columnname text, datatype text, nonnull boolean DEFAULT false, defaultval text DEFAULT ''::text, constrainttext text DEFAULT ''::text) RETURNS boolean
CREATE OR REPLACE FUNCTION add_column_if_not_exists(tablename text, columnname text, datatype text, nonnull boolean DEFAULT false, defaultval text DEFAULT ''::text, constrainttext text DEFAULT ''::text) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand All @@ -11,19 +11,20 @@ BEGIN

-- validate input
IF nonnull AND ( defaultval = '' ) THEN
RAISE EXCEPTION 'for NOT NULL columns, you must add a default';
RAISE NOTICE 'for NOT NULL columns, you must add a default';
RETURN FALSE;
END IF;

IF defaultval <> '' THEN
defaultval := ' DEFAULT ' || quote_literal(defaultval);
END IF;

-- check if the column already exists.
PERFORM 1
PERFORM 1
FROM information_schema.columns
WHERE table_name = tablename
AND column_name = columnname;

IF FOUND THEN
RETURN FALSE;
END IF;
Expand Down
5 changes: 3 additions & 2 deletions socorro/external/postgresql/raw_sql/procs/add_new_product.sql
@@ -1,12 +1,13 @@
CREATE FUNCTION add_new_product(prodname text, initversion major_version, prodid text DEFAULT NULL::text, ftpname text DEFAULT NULL::text, release_throttle numeric DEFAULT 1.0, rapid_beta_version numeric DEFAULT 999.0) RETURNS boolean
CREATE OR REPLACE FUNCTION add_new_product(prodname text, initversion major_version, prodid text DEFAULT NULL::text, ftpname text DEFAULT NULL::text, release_throttle numeric DEFAULT 1.0, rapid_beta_version numeric DEFAULT 999.0) RETURNS boolean
LANGUAGE plpgsql
AS $$
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';
RAISE NOTICE 'a product name and initial version are required';
RETURN FALSE;
END IF;

-- check if product already exists
Expand Down
14 changes: 9 additions & 5 deletions socorro/external/postgresql/raw_sql/procs/add_new_release.sql
@@ -1,4 +1,4 @@
CREATE FUNCTION add_new_release(product citext, version citext, release_channel citext, build_id numeric, platform citext, beta_number integer DEFAULT NULL::integer, repository text DEFAULT 'release'::text, update_products boolean DEFAULT false, ignore_duplicates boolean DEFAULT false) RETURNS 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::integer, repository text DEFAULT 'release'::text, update_products boolean DEFAULT false, ignore_duplicates boolean DEFAULT false) RETURNS boolean
LANGUAGE plpgsql
AS $$
DECLARE rname citext;
Expand All @@ -11,7 +11,8 @@ BEGIN
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';
RAISE NOTICE 'product, version, release_channel, platform and build ID are all required';
RETURN FALSE;
END IF;

-- product
Expand All @@ -23,7 +24,8 @@ IF rname IS NULL THEN
SELECT release_name INTO rname
FROM products WHERE product_name = product;
IF rname IS NULL THEN
RAISE EXCEPTION 'You must supply a valid product or product release name';
RAISE NOTICE 'You must supply a valid product or product release name';
RETURN FALSE;
END IF;
END IF;

Expand All @@ -32,7 +34,8 @@ PERFORM validate_lookup('release_channels','release_channel',release_channel,'re
--validate build
IF NOT ( build_date(build_id) BETWEEN '2005-01-01'
AND (current_date + INTERVAL '1 month') ) THEN
RAISE EXCEPTION 'invalid buildid';
RAISE NOTICE 'invalid buildid';
RETURN FALSE;
END IF;

--add row
Expand All @@ -57,7 +60,8 @@ EXCEPTION
IF ignore_duplicates THEN
RETURN FALSE;
ELSE
RAISE EXCEPTION 'the release you have entered is already present in he database';
RAISE NOTICE 'the release you have entered is already present in he database';
RETURN FALSE;
END IF;
END;$$;

Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION add_old_release(product_name text, new_version text, release_type release_enum DEFAULT 'major'::release_enum, release_date date DEFAULT ('now'::text)::date, is_featured boolean DEFAULT false) RETURNS boolean
CREATE OR REPLACE FUNCTION add_old_release(product_name text, new_version text, release_type release_enum DEFAULT 'major'::release_enum, release_date date DEFAULT ('now'::text)::date, is_featured boolean DEFAULT false) RETURNS boolean
LANGUAGE plpgsql
AS $$
DECLARE last_date DATE;
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION aurora_or_nightly(version text) RETURNS text
CREATE OR REPLACE FUNCTION aurora_or_nightly(version text) RETURNS text
LANGUAGE sql IMMUTABLE STRICT
AS $_$
-- figures out "aurora" or "nightly" from a version string
Expand Down
2 changes: 1 addition & 1 deletion socorro/external/postgresql/raw_sql/procs/backfill_adu.sql
@@ -1,5 +1,5 @@

CREATE FUNCTION backfill_adu(updateday date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_adu(updateday date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_all_dups(start_date timestamp without time zone, end_date timestamp without time zone) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_all_dups(start_date timestamp without time zone, end_date timestamp without time zone) RETURNS boolean
LANGUAGE plpgsql
AS $$
declare this_time timestamp;
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_build_adu(updateday date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_build_adu(updateday date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_correlations(updateday date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_correlations(updateday date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_crashes_by_user(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_crashes_by_user(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_crashes_by_user_build(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_crashes_by_user_build(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_daily_crashes(updateday date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_daily_crashes(updateday date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_explosiveness(updateday date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_explosiveness(updateday date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_hang_report(backfilldate date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_hang_report(backfilldate date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_home_page_graph(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_home_page_graph(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_home_page_graph_build(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_home_page_graph_build(updateday date, check_period interval DEFAULT '01:00:00'::interval) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_matviews(firstday date, lastday date DEFAULT NULL::date, reportsclean boolean DEFAULT true) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_matviews(firstday date, lastday date DEFAULT NULL::date, reportsclean boolean DEFAULT true) RETURNS boolean
LANGUAGE plpgsql
SET "TimeZone" TO 'UTC'
AS $$
Expand All @@ -24,7 +24,8 @@ first_rc := firstday AT TIME ZONE 'UTC';

-- check parameters
IF firstday > current_date OR lastday > current_date THEN
RAISE EXCEPTION 'date parameter error: cannot backfill into the future';
RAISE NOTICE 'date parameter error: cannot backfill into the future';
RETURN FALSE;
END IF;

-- set optional end date
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_nightly_builds(updateday date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_nightly_builds(updateday date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_one_day() RETURNS text
CREATE OR REPLACE FUNCTION backfill_one_day() RETURNS text
LANGUAGE plpgsql
AS $$
declare datematch text;
Expand Down Expand Up @@ -42,7 +42,7 @@ begin
END; $$;


CREATE FUNCTION backfill_one_day(bkdate date) RETURNS text
CREATE OR REPLACE FUNCTION backfill_one_day(bkdate date) RETURNS text
LANGUAGE plpgsql
AS $$
declare datematch text;
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_rank_compare(updateday date DEFAULT NULL::date) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_rank_compare(updateday date DEFAULT NULL::date) RETURNS boolean
LANGUAGE plpgsql
AS $$
BEGIN
Expand Down
@@ -1,4 +1,4 @@
CREATE FUNCTION backfill_reports_clean(begin_time timestamp with time zone, end_time timestamp with time zone DEFAULT NULL::timestamp with time zone) RETURNS boolean
CREATE OR REPLACE FUNCTION backfill_reports_clean(begin_time timestamp with time zone, end_time timestamp with time zone DEFAULT NULL::timestamp with time zone) RETURNS boolean
LANGUAGE plpgsql
AS $$
-- administrative utility for backfilling reports_clean to the selected date
Expand Down

0 comments on commit 53fcbaf

Please sign in to comment.