-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #576 from jberkus/master
9.0 SQL database changes.
- Loading branch information
Showing
9 changed files
with
385 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
\set ON_ERROR_STOP 1 | ||
|
||
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 | ||
) | ||
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 | ||
SELECT validate_lookup('products','product_name',product,'product'); | ||
--validate channel | ||
SELECT 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 + '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 | ||
SELECT update_product_versions(); | ||
END IF; | ||
|
||
--return | ||
RETURN TRUE; | ||
|
||
--exception clause, mainly catches duplicate rows. | ||
EXCEPTION | ||
WHEN UNIQUE_VIOLATION THEN | ||
RAISE EXCEPTION 'the release you have entered is already present in he database'; | ||
END;$f$; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
\set ON_ERROR_STOP 1 | ||
|
||
CREATE OR REPLACE FUNCTION edit_featured_versions ( | ||
product citext, | ||
VARIADIC featured_versions text | ||
) | ||
RETURNS boolean | ||
LANGUAGE plpgsql | ||
AS $f$ | ||
-- this function allows admins to change the featured versions | ||
-- for a particular product | ||
BEGIN | ||
|
||
--check required parameters | ||
IF NOT ( nonzero_string(product) AND nonzero_string(featured_versions[1]) ) THEN | ||
RAISE EXCEPTION 'a product name and at least one version are required'; | ||
END IF; | ||
|
||
--check that all versions are not expired | ||
SELECT 1 FROM product_verstions | ||
WHERE product_name = product | ||
AND version_string = ANY ( featured_versions ) | ||
AND sunset_date < current_date; | ||
IF FOUND THEN | ||
RAISE EXCEPTION 'one or more of the versions you have selected is already expired'; | ||
END IF; | ||
|
||
--Remove disfeatured versions | ||
UPDATE product_versions SET featured_version = false | ||
WHERE featured_version | ||
AND NOT ( version_string = ANY( featured_versions ) ); | ||
|
||
--feature new versions | ||
UPDATE product_versions SET featured_version = true | ||
WHERE version_string = ANY ( featured_versions ) | ||
AND NOT featured_version; | ||
|
||
RETURN TRUE; | ||
|
||
END;$f$; |
Oops, something went wrong.