Project

General

Profile

« Previous | Next » 

Revision 13512

fix: schemas/util.sql: force_recreate(): renamed to just recreate(), because "force" normally implies that things will be deleted, which this function does not do

View differences:

util.sql
1822 1822

  
1823 1823

  
1824 1824
--
1825
-- Name: force_recreate(text, text[]); Type: FUNCTION; Schema: util; Owner: -
1826
--
1827

  
1828
CREATE FUNCTION force_recreate(cmd text, users text[] DEFAULT NULL::text[]) RETURNS void
1829
    LANGUAGE plpgsql
1830
    AS $_$
1831
DECLARE
1832
	PG_EXCEPTION_DETAIL text;
1833
	restore_views_info util.restore_views_info;
1834
BEGIN
1835
	restore_views_info = util.save_drop_views(users);
1836
	PERFORM util.eval(cmd);
1837
	PERFORM util.restore_views(restore_views_info);
1838
EXCEPTION
1839
WHEN dependent_objects_still_exist THEN
1840
	IF users IS NOT NULL THEN RAISE; END IF; -- save_drop_views() didn't fix it
1841
	GET STACKED DIAGNOSTICS PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL;
1842
	users = array(SELECT * FROM util.regexp_matches_group(
1843
		PG_EXCEPTION_DETAIL, '(?m)^view (.*) depends on [[:lower:]]+ .*$'));
1844
		-- will be in forward dependency order
1845
	PERFORM util.debug_print_var('PG_EXCEPTION_DETAIL', PG_EXCEPTION_DETAIL);
1846
	PERFORM util.debug_print_var('users', users);
1847
	IF util.is_empty(users) THEN RAISE; END IF;
1848
	PERFORM util.force_recreate(cmd, users);
1849
END;
1850
$_$;
1851

  
1852

  
1853
--
1854
-- Name: FUNCTION force_recreate(cmd text, users text[]); Type: COMMENT; Schema: util; Owner: -
1855
--
1856

  
1857
COMMENT ON FUNCTION force_recreate(cmd text, users text[]) IS '
1858
usage:
1859
SELECT util.force_recreate($$
1860
-- trigger the dependent_objects_still_exist exception
1861
DROP VIEW schemas.main_view; -- *not* CASCADE; it must trigger an exception
1862

  
1863
CREATE VIEW schemas.main_view AS _;
1864

  
1865
-- manually restore views that need to be updated for the changes
1866
CREATE VIEW schemas.dependent_view AS _;
1867
$$);
1868

  
1869
idempotent
1870

  
1871
users: not necessary to provide this because it will be autopopulated
1872
';
1873

  
1874

  
1875
--
1876 1825
-- Name: force_update_view(text, text); Type: FUNCTION; Schema: util; Owner: -
1877 1826
--
1878 1827

  
......
3077 3026

  
3078 3027

  
3079 3028
--
3029
-- Name: recreate(text, text[]); Type: FUNCTION; Schema: util; Owner: -
3030
--
3031

  
3032
CREATE FUNCTION recreate(cmd text, users text[] DEFAULT NULL::text[]) RETURNS void
3033
    LANGUAGE plpgsql
3034
    AS $_$
3035
DECLARE
3036
	PG_EXCEPTION_DETAIL text;
3037
	restore_views_info util.restore_views_info;
3038
BEGIN
3039
	restore_views_info = util.save_drop_views(users);
3040
	PERFORM util.eval(cmd);
3041
	PERFORM util.restore_views(restore_views_info);
3042
EXCEPTION
3043
WHEN dependent_objects_still_exist THEN
3044
	IF users IS NOT NULL THEN RAISE; END IF; -- save_drop_views() didn't fix it
3045
	GET STACKED DIAGNOSTICS PG_EXCEPTION_DETAIL = PG_EXCEPTION_DETAIL;
3046
	users = array(SELECT * FROM util.regexp_matches_group(
3047
		PG_EXCEPTION_DETAIL, '(?m)^view (.*) depends on [[:lower:]]+ .*$'));
3048
		-- will be in forward dependency order
3049
	PERFORM util.debug_print_var('PG_EXCEPTION_DETAIL', PG_EXCEPTION_DETAIL);
3050
	PERFORM util.debug_print_var('users', users);
3051
	IF util.is_empty(users) THEN RAISE; END IF;
3052
	PERFORM util.recreate(cmd, users);
3053
END;
3054
$_$;
3055

  
3056

  
3057
--
3058
-- Name: FUNCTION recreate(cmd text, users text[]); Type: COMMENT; Schema: util; Owner: -
3059
--
3060

  
3061
COMMENT ON FUNCTION recreate(cmd text, users text[]) IS '
3062
usage:
3063
SELECT util.recreate($$
3064
-- trigger the dependent_objects_still_exist exception
3065
DROP VIEW schemas.main_view; -- *not* CASCADE; it must trigger an exception
3066

  
3067
CREATE VIEW schemas.main_view AS _;
3068

  
3069
-- manually restore views that need to be updated for the changes
3070
CREATE VIEW schemas.dependent_view AS _;
3071
$$);
3072

  
3073
idempotent
3074

  
3075
users: not necessary to provide this because it will be autopopulated
3076
';
3077

  
3078

  
3079
--
3080 3080
-- Name: regexp_matches_group(text, text, integer); Type: FUNCTION; Schema: util; Owner: -
3081 3081
--
3082 3082

  

Also available in: Unified diff