diff --git a/common-data/cdb_common_data_catalog.sql b/common-data/cdb_common_data_catalog.sql new file mode 100644 index 0000000..2c0777a --- /dev/null +++ b/common-data/cdb_common_data_catalog.sql @@ -0,0 +1,42 @@ +CREATE FUNCTION public.CDB_CommonDataCatalog() + RETURNS TABLE( + name text, + tabname text, + description text, + source text, + license text, + geometry_types text, + rows real, + size bigint, + created_at timestamp with time zone, + updated_at timestamp with time zone, + category text, + image_url text) + AS $$ + SELECT + meta_dataset.name, + meta_dataset.tabname, + meta_dataset.description, + meta_dataset.source, + meta_dataset.license, + meta_dataset.geometry_types, + ( + SELECT reltuples + FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) + WHERE + nspname NOT IN ('pg_catalog', 'information_schema') + AND relkind='r' + AND relname = meta_dataset.tabname + ) as rows, + pg_relation_size(meta_dataset.tabname) size, + meta_dataset.created_at, + meta_dataset.updated_at, + meta_category.name category, + meta_category.image_url category_image_url + FROM meta_dataset, meta_category + WHERE meta_dataset.meta_category_id = meta_category.cartodb_id; +$$ LANGUAGE SQL; + +GRANT SELECT ON TABLE meta_dataset TO publicuser; +GRANT SELECT ON TABLE meta_category TO publicuser; +GRANT EXECUTE ON FUNCTION CDB_CommonDataCatalog() TO publicuser; diff --git a/common-data/meta_category.sql b/common-data/meta_category.sql new file mode 100644 index 0000000..8f9622f --- /dev/null +++ b/common-data/meta_category.sql @@ -0,0 +1,13 @@ +-- +-- Name: meta_category; Type: TABLE; Schema: public +-- + +CREATE TABLE meta_category ( + cartodb_id integer NOT NULL, + name text, + created_at timestamp with time zone DEFAULT now() NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + the_geom geometry(Geometry,4326), + the_geom_webmercator geometry(Geometry,3857), + image_url text +); diff --git a/common-data/meta_dataset.sql b/common-data/meta_dataset.sql new file mode 100644 index 0000000..d8becf0 --- /dev/null +++ b/common-data/meta_dataset.sql @@ -0,0 +1,21 @@ +-- +-- Name: meta_dataset; Type: TABLE; Schema: public +-- + +CREATE TABLE meta_dataset ( + cartodb_id integer NOT NULL, + name text, + description text, + created_at timestamp with time zone DEFAULT now() NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + the_geom geometry(Geometry,4326), + the_geom_webmercator geometry(Geometry,3857), + source text, + license text, + meta_category_id integer, + tabname text, + geometry_types text +); + +ALTER TABLE ONLY meta_dataset + ADD CONSTRAINT meta_dataset_meta_category_id_fkey FOREIGN KEY (meta_category_id) REFERENCES meta_category(cartodb_id);