Project

General

Profile

« Previous | Next » 

Revision 12135

schemas/util.sql: added functions for maintaining schema bundles, groups of schemas with a common prefix

View differences:

util.sql
1898 1898

  
1899 1899

  
1900 1900
--
1901
-- Name: FUNCTION schema_bundle_get_schemas(schema_bundle text); Type: COMMENT; Schema: util; Owner: -
1902
--
1903

  
1904
COMMENT ON FUNCTION schema_bundle_get_schemas(schema_bundle text) IS 'a schema bundle is a group of schemas with a common prefix';
1905

  
1906

  
1907
--
1908
-- Name: schema_bundle_rename(text, text); Type: FUNCTION; Schema: util; Owner: -
1909
--
1910

  
1911
CREATE FUNCTION schema_bundle_rename(old text, new text) RETURNS void
1912
    LANGUAGE sql
1913
    AS $_$
1914
SELECT util.schema_rename(old_schema,
1915
	overlay(old_schema placing new from 1 for length(old))) -- replace prefix
1916
FROM util.schema_bundle_get_schemas($1) f (old_schema);
1917
SELECT NULL::void; -- don't fold away functions called in previous query
1918
$_$;
1919

  
1920

  
1921
--
1922
-- Name: schema_bundle_replace(text, text); Type: FUNCTION; Schema: util; Owner: -
1923
--
1924

  
1925
CREATE FUNCTION schema_bundle_replace(replace text, with_ text) RETURNS void
1926
    LANGUAGE plpgsql
1927
    AS $$
1928
BEGIN
1929
	-- don't schema_bundle_rm() the schema_bundle to keep!
1930
	IF replace = with_ THEN RETURN; END IF;
1931
	
1932
	PERFORM util.schema_bundle_rm(replace);
1933
	PERFORM util.schema_bundle_rename(with_, replace);
1934
END;
1935
$$;
1936

  
1937

  
1938
--
1939
-- Name: schema_bundle_rm(text); Type: FUNCTION; Schema: util; Owner: -
1940
--
1941

  
1942
CREATE FUNCTION schema_bundle_rm(schema_bundle text) RETURNS void
1943
    LANGUAGE sql
1944
    AS $_$
1945
SELECT util.schema_rm(schema)
1946
FROM util.schema_bundle_get_schemas($1) f (schema);
1947
SELECT NULL::void; -- don't fold away functions called in previous query
1948
$_$;
1949

  
1950

  
1951
--
1901 1952
-- Name: schema_ident(anyelement); Type: FUNCTION; Schema: util; Owner: -
1902 1953
--
1903 1954

  

Also available in: Unified diff