2011-10-05 23:49:54 +08:00
--
-- sql-api test database
2015-12-07 16:40:51 +08:00
--
2011-10-05 23:49:54 +08:00
-- To use:
2015-12-07 16:40:51 +08:00
--
2011-10-05 23:49:54 +08:00
-- > dropdb -Upostgres -hlocalhost cartodb_test_user_1_db
-- > createdb -Upostgres -hlocalhost -Ttemplate_postgis -Opostgres -EUTF8 cartodb_test_user_1_db
-- > psql -Upostgres -hlocalhost cartodb_test_user_1_db < test.sql
--
2012-05-08 22:25:19 +08:00
-- NOTE: requires a postgis template called template_postgis with CDB functions included
2011-10-05 23:49:54 +08:00
--
SET statement_timeout = 0 ;
SET client_encoding = ' UTF8 ' ;
SET standard_conforming_strings = off ;
SET check_function_bodies = false ;
SET client_min_messages = warning ;
SET escape_string_warning = off ;
SET search_path = public , pg_catalog ;
SET default_tablespace = ' ' ;
SET default_with_oids = false ;
-- first table
2012-05-08 22:25:19 +08:00
DROP TABLE IF EXISTS untitle_table_4 ;
2011-10-05 23:49:54 +08:00
CREATE TABLE untitle_table_4 (
updated_at timestamp without time zone DEFAULT now ( ) ,
created_at timestamp without time zone DEFAULT now ( ) ,
cartodb_id integer NOT NULL ,
name character varying ,
address character varying ,
2013-11-05 23:56:07 +08:00
-- NOTE: the_geom_webmercator is intentionally listed _before_ the_geom
-- see https://github.com/CartoDB/CartoDB-SQL-API/issues/116
2011-10-05 23:49:54 +08:00
the_geom_webmercator geometry ,
2013-11-05 23:56:07 +08:00
the_geom geometry ,
2011-10-05 23:49:54 +08:00
CONSTRAINT enforce_dims_the_geom CHECK ( ( st_ndims ( the_geom ) = 2 ) ) ,
CONSTRAINT enforce_dims_the_geom_webmercator CHECK ( ( st_ndims ( the_geom_webmercator ) = 2 ) ) ,
CONSTRAINT enforce_geotype_the_geom CHECK ( ( ( geometrytype ( the_geom ) = ' POINT ' : : text ) OR ( the_geom IS NULL ) ) ) ,
CONSTRAINT enforce_geotype_the_geom_webmercator CHECK ( ( ( geometrytype ( the_geom_webmercator ) = ' POINT ' : : text ) OR ( the_geom_webmercator IS NULL ) ) ) ,
CONSTRAINT enforce_srid_the_geom CHECK ( ( st_srid ( the_geom ) = 4326 ) ) ,
CONSTRAINT enforce_srid_the_geom_webmercator CHECK ( ( st_srid ( the_geom_webmercator ) = 3857 ) )
) ;
2016-12-09 17:28:51 +08:00
CREATE SEQUENCE untitle_table_4_cartodb_id_seq
2011-10-05 23:49:54 +08:00
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1 ;
2016-12-09 17:28:51 +08:00
ALTER SEQUENCE untitle_table_4_cartodb_id_seq OWNED BY untitle_table_4 . cartodb_id ;
2011-10-05 23:49:54 +08:00
2016-12-09 17:28:51 +08:00
SELECT pg_catalog . setval ( ' untitle_table_4_cartodb_id_seq ' , 60 , true ) ;
2011-10-05 23:49:54 +08:00
2016-12-09 17:28:51 +08:00
ALTER TABLE untitle_table_4 ALTER COLUMN cartodb_id SET DEFAULT nextval ( ' untitle_table_4_cartodb_id_seq ' : : regclass ) ;
2011-10-05 23:49:54 +08:00
2013-11-05 23:56:07 +08:00
INSERT INTO untitle_table_4
( updated_at , created_at , cartodb_id , name , address , the_geom , the_geom_webmercator )
VALUES
2013-04-11 23:08:26 +08:00
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.314252 ' , 1 , ' Hawai ' , ' Calle de Pérez Galdós 9, Madrid, Spain ' , ' 0101000020E6100000A6B73F170D990DC064E8D84125364440 ' , ' 0101000020110F000076491621312319C122D4663F1DCC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.319101 ' , 2 , ' El Estocolmo ' , ' Calle de la Palma 72, Madrid, Spain ' , ' 0101000020E6100000C90567F0F7AB0DC0AB07CC43A6364440 ' , ' 0101000020110F0000C4356B29423319C15DD1092DADCC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.324 ' , 3 , ' El Rey del Tallarín ' , ' Plaza Conde de Toreno 2, Madrid, Spain ' , ' 0101000020E610000021C8410933AD0DC0CB0EF10F5B364440 ' , ' 0101000020110F000053E71AC64D3419C10F664E4659CC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.329509 ' , 4 , ' El Lacón ' , ' Manuel Fernández y González 8, Madrid, Spain ' , ' 0101000020E6100000BC5983F755990DC07D923B6C22354440 ' , ' 0101000020110F00005DACDB056F2319C1EC41A980FCCA5241 ' ) ,
2013-11-05 23:56:07 +08:00
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.334931 ' , 5 , ' El Pico ' , ' Calle Divino Pastor 12, Madrid, Spain ' , ' 0101000020E61000003B6D8D08C6A10DC0371B2B31CF364440 ' , ' 0101000020110F00005F716E91992A19C17DAAA4D6DACC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21 ' , - 1 , ' Test ' , ' Fake for testing ' , ' SRID=4326;POINT(33 16) ' , ' SRID=3857;POINT(3673543.19617803 1804722.76625729) ' ) ;
2011-10-05 23:49:54 +08:00
2016-12-09 17:28:51 +08:00
ALTER TABLE ONLY untitle_table_4 ADD CONSTRAINT untitle_table_4_pkey PRIMARY KEY ( cartodb_id ) ;
2011-10-05 23:49:54 +08:00
2016-12-09 17:28:51 +08:00
CREATE INDEX untitle_table_4_the_geom_idx ON untitle_table_4 USING gist ( the_geom ) ;
CREATE INDEX untitle_table_4_the_geom_webmercator_idx ON untitle_table_4 USING gist ( the_geom_webmercator ) ;
2011-10-05 23:49:54 +08:00
2018-02-14 00:53:27 +08:00
-- second table
DROP TABLE IF EXISTS scoped_table_1 ;
CREATE TABLE scoped_table_1 (
updated_at timestamp without time zone DEFAULT now ( ) ,
created_at timestamp without time zone DEFAULT now ( ) ,
cartodb_id integer NOT NULL ,
name character varying ,
address character varying ,
the_geom_webmercator geometry ,
the_geom geometry ,
CONSTRAINT enforce_dims_the_geom CHECK ( ( st_ndims ( the_geom ) = 2 ) ) ,
CONSTRAINT enforce_dims_the_geom_webmercator CHECK ( ( st_ndims ( the_geom_webmercator ) = 2 ) ) ,
CONSTRAINT enforce_geotype_the_geom CHECK ( ( ( geometrytype ( the_geom ) = ' POINT ' : : text ) OR ( the_geom IS NULL ) ) ) ,
CONSTRAINT enforce_geotype_the_geom_webmercator CHECK ( ( ( geometrytype ( the_geom_webmercator ) = ' POINT ' : : text ) OR ( the_geom_webmercator IS NULL ) ) ) ,
CONSTRAINT enforce_srid_the_geom CHECK ( ( st_srid ( the_geom ) = 4326 ) ) ,
CONSTRAINT enforce_srid_the_geom_webmercator CHECK ( ( st_srid ( the_geom_webmercator ) = 3857 ) )
) ;
CREATE SEQUENCE scoped_table_1_cartodb_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1 ;
ALTER SEQUENCE scoped_table_1_cartodb_id_seq OWNED BY scoped_table_1 . cartodb_id ;
SELECT pg_catalog . setval ( ' scoped_table_1_cartodb_id_seq ' , 60 , true ) ;
ALTER TABLE scoped_table_1 ALTER COLUMN cartodb_id SET DEFAULT nextval ( ' scoped_table_1_cartodb_id_seq ' : : regclass ) ;
INSERT INTO scoped_table_1
( updated_at , created_at , cartodb_id , name , address , the_geom , the_geom_webmercator )
VALUES
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.314252 ' , 1 , ' Hawai ' , ' Calle de Pérez Galdós 9, Madrid, Spain ' , ' 0101000020E6100000A6B73F170D990DC064E8D84125364440 ' , ' 0101000020110F000076491621312319C122D4663F1DCC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.319101 ' , 2 , ' El Estocolmo ' , ' Calle de la Palma 72, Madrid, Spain ' , ' 0101000020E6100000C90567F0F7AB0DC0AB07CC43A6364440 ' , ' 0101000020110F0000C4356B29423319C15DD1092DADCC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.324 ' , 3 , ' El Rey del Tallarín ' , ' Plaza Conde de Toreno 2, Madrid, Spain ' , ' 0101000020E610000021C8410933AD0DC0CB0EF10F5B364440 ' , ' 0101000020110F000053E71AC64D3419C10F664E4659CC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.329509 ' , 4 , ' El Lacón ' , ' Manuel Fernández y González 8, Madrid, Spain ' , ' 0101000020E6100000BC5983F755990DC07D923B6C22354440 ' , ' 0101000020110F00005DACDB056F2319C1EC41A980FCCA5241 ' ) ;
ALTER TABLE ONLY scoped_table_1 ADD CONSTRAINT scoped_table_1_pkey PRIMARY KEY ( cartodb_id ) ;
CREATE INDEX scoped_table_1_the_geom_idx ON scoped_table_1 USING gist ( the_geom ) ;
CREATE INDEX scoped_table_1_the_geom_webmercator_idx ON scoped_table_1 USING gist ( the_geom_webmercator ) ;
-- private table
2012-05-08 22:25:19 +08:00
DROP TABLE IF EXISTS private_table ;
2011-12-27 02:16:41 +08:00
CREATE TABLE private_table (
updated_at timestamp without time zone DEFAULT now ( ) ,
created_at timestamp without time zone DEFAULT now ( ) ,
cartodb_id integer NOT NULL ,
name character varying ,
address character varying ,
the_geom geometry ,
the_geom_webmercator geometry ,
CONSTRAINT enforce_dims_the_geom CHECK ( ( st_ndims ( the_geom ) = 2 ) ) ,
CONSTRAINT enforce_dims_the_geom_webmercator CHECK ( ( st_ndims ( the_geom_webmercator ) = 2 ) ) ,
CONSTRAINT enforce_geotype_the_geom CHECK ( ( ( geometrytype ( the_geom ) = ' POINT ' : : text ) OR ( the_geom IS NULL ) ) ) ,
CONSTRAINT enforce_geotype_the_geom_webmercator CHECK ( ( ( geometrytype ( the_geom_webmercator ) = ' POINT ' : : text ) OR ( the_geom_webmercator IS NULL ) ) ) ,
CONSTRAINT enforce_srid_the_geom CHECK ( ( st_srid ( the_geom ) = 4326 ) ) ,
CONSTRAINT enforce_srid_the_geom_webmercator CHECK ( ( st_srid ( the_geom_webmercator ) = 3857 ) )
) ;
2016-12-09 17:28:51 +08:00
CREATE SEQUENCE untitle_table_4_cartodb_id_seq_p
2011-12-27 02:16:41 +08:00
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1 ;
2016-12-09 17:28:51 +08:00
ALTER SEQUENCE untitle_table_4_cartodb_id_seq_p OWNED BY private_table . cartodb_id ;
2011-12-27 02:16:41 +08:00
2016-12-09 17:28:51 +08:00
SELECT pg_catalog . setval ( ' untitle_table_4_cartodb_id_seq_p ' , 60 , true ) ;
2011-12-27 02:16:41 +08:00
2016-12-09 17:28:51 +08:00
ALTER TABLE private_table ALTER COLUMN cartodb_id SET DEFAULT nextval ( ' untitle_table_4_cartodb_id_seq_p ' : : regclass ) ;
2011-12-27 02:16:41 +08:00
2013-04-11 23:08:26 +08:00
INSERT INTO private_table VALUES
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.314252 ' , 1 , ' Hawai ' , ' Calle de Pérez Galdós 9, Madrid, Spain ' , ' 0101000020E6100000A6B73F170D990DC064E8D84125364440 ' , ' 0101000020110F000076491621312319C122D4663F1DCC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.319101 ' , 2 , ' El Estocolmo ' , ' Calle de la Palma 72, Madrid, Spain ' , ' 0101000020E6100000C90567F0F7AB0DC0AB07CC43A6364440 ' , ' 0101000020110F0000C4356B29423319C15DD1092DADCC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.324 ' , 3 , ' El Rey del Tallarín ' , ' Plaza Conde de Toreno 2, Madrid, Spain ' , ' 0101000020E610000021C8410933AD0DC0CB0EF10F5B364440 ' , ' 0101000020110F000053E71AC64D3419C10F664E4659CC5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.329509 ' , 4 , ' El Lacón ' , ' Manuel Fernández y González 8, Madrid, Spain ' , ' 0101000020E6100000BC5983F755990DC07D923B6C22354440 ' , ' 0101000020110F00005DACDB056F2319C1EC41A980FCCA5241 ' ) ,
( ' 2011-09-21 14:02:21.358706 ' , ' 2011-09-21 14:02:21.334931 ' , 5 , ' El Pico ' , ' Calle Divino Pastor 12, Madrid, Spain ' , ' 0101000020E61000003B6D8D08C6A10DC0371B2B31CF364440 ' , ' 0101000020110F00005F716E91992A19C17DAAA4D6DACC5241 ' ) ;
2011-12-27 02:16:41 +08:00
2016-12-09 17:28:51 +08:00
ALTER TABLE ONLY private_table ADD CONSTRAINT untitle_table_4_pkey_p PRIMARY KEY ( cartodb_id ) ;
2011-12-27 02:16:41 +08:00
2016-12-09 17:28:51 +08:00
CREATE INDEX untitle_table_4_the_geom_idx_p ON private_table USING gist ( the_geom ) ;
CREATE INDEX untitle_table_4_the_geom_webmercator_idx_p ON private_table USING gist ( the_geom_webmercator ) ;
2011-12-27 02:16:41 +08:00
2014-03-20 18:58:05 +08:00
-- public user role
DROP USER IF EXISTS : PUBLICUSER ;
2013-11-18 20:31:11 +08:00
CREATE USER : PUBLICUSER WITH PASSWORD ' :PUBLICPASS ' ;
2014-11-11 20:57:15 +08:00
ALTER ROLE : PUBLICUSER SET statement_timeout = 2000 ;
2018-02-14 00:53:27 +08:00
GRANT SELECT ON TABLE scoped_table_1 TO : PUBLICUSER ;
-- regular user role 1
DROP USER IF EXISTS regular_1 ;
CREATE USER regular_1 WITH PASSWORD ' regular1 ' ;
ALTER ROLE regular_1 SET statement_timeout = 2000 ;
GRANT ALL ON TABLE scoped_table_1 TO regular_1 ;
GRANT ALL ON SEQUENCE scoped_table_1_cartodb_id_seq TO regular_1 ;
-- regular user role 2
DROP USER IF EXISTS regular_2 ;
CREATE USER regular_2 WITH PASSWORD ' regular2 ' ;
ALTER ROLE regular_2 SET statement_timeout = 2000 ;
2014-03-20 18:58:05 +08:00
2018-02-14 23:22:36 +08:00
-- fallback user role
DROP USER IF EXISTS test_cartodb_user_2 ;
CREATE USER test_cartodb_user_2 WITH PASSWORD ' test_cartodb_user_2_pass ' ;
GRANT ALL ON TABLE scoped_table_1 TO test_cartodb_user_2 ;
2018-02-27 01:13:49 +08:00
GRANT ALL ON SEQUENCE scoped_table_1_cartodb_id_seq TO test_cartodb_user_2 ;
2018-02-14 23:22:36 +08:00
2014-03-20 18:58:05 +08:00
-- db owner role
DROP USER IF EXISTS : TESTUSER ;
2013-11-18 20:31:11 +08:00
CREATE USER : TESTUSER WITH PASSWORD ' :TESTPASS ' ;
2011-10-05 23:49:54 +08:00
2013-11-18 20:31:11 +08:00
GRANT ALL ON TABLE untitle_table_4 TO : TESTUSER ;
2013-11-06 00:49:10 +08:00
GRANT SELECT ON TABLE untitle_table_4 TO : PUBLICUSER ;
2013-11-18 20:31:11 +08:00
GRANT ALL ON TABLE private_table TO : TESTUSER ;
2018-02-14 00:53:27 +08:00
GRANT ALL ON TABLE scoped_table_1 TO : TESTUSER ;
2016-12-09 17:28:51 +08:00
GRANT ALL ON SEQUENCE untitle_table_4_cartodb_id_seq_p TO : TESTUSER ;
2013-10-01 23:19:44 +08:00
2013-11-18 20:31:11 +08:00
GRANT ALL ON TABLE spatial_ref_sys TO : TESTUSER , : PUBLICUSER ;
2013-11-05 23:56:07 +08:00
REVOKE ALL ON geometry_columns FROM public ;
2013-11-18 20:31:11 +08:00
GRANT ALL ON geometry_columns TO : TESTUSER ;
2014-09-22 19:23:30 +08:00
GRANT ALL ON geography_columns TO : TESTUSER ;
2014-09-22 23:20:49 +08:00
GRANT SELECT ON geometry_columns TO : PUBLICUSER ;
GRANT SELECT ON geography_columns TO : PUBLICUSER ;
2013-11-07 17:16:58 +08:00
-- For https://github.com/CartoDB/CartoDB-SQL-API/issues/118
DROP TABLE IF EXISTS cpg_test ;
CREATE TABLE cpg_test ( a int ) ;
2013-11-18 20:31:11 +08:00
GRANT ALL ON TABLE cpg_test TO : TESTUSER ;
2013-11-07 17:16:58 +08:00
GRANT SELECT ON TABLE cpg_test TO : PUBLICUSER ;
2015-09-02 22:25:56 +08:00
CREATE TABLE IF NOT EXISTS
CDB_TableMetadata (
tabname regclass not null primary key ,
updated_at timestamp with time zone not null default now ( )
) ;
INSERT INTO CDB_TableMetadata ( tabname , updated_at ) VALUES ( ' untitle_table_4 ' : : regclass , ' 2014-01-01T23:31:30.123Z ' ) ;
INSERT INTO CDB_TableMetadata ( tabname , updated_at ) VALUES ( ' private_table ' : : regclass , ' 2015-01-01T23:31:30.123Z ' ) ;
2018-02-14 00:53:27 +08:00
INSERT INTO CDB_TableMetadata ( tabname , updated_at ) VALUES ( ' scoped_table_1 ' : : regclass , ' 2015-01-01T23:31:30.123Z ' ) ;
2015-09-02 22:25:56 +08:00
GRANT SELECT ON CDB_TableMetadata TO : TESTUSER ;
2018-02-14 23:22:36 +08:00
GRANT SELECT ON CDB_TableMetadata TO test_cartodb_user_2 ;
2018-05-04 00:32:39 +08:00
DROP TABLE IF EXISTS copy_test ;
CREATE TABLE copy_test (
id integer ,
name text ,
age integer default 10
) ;
GRANT ALL ON TABLE copy_test TO : TESTUSER ;
GRANT ALL ON TABLE copy_test TO : PUBLICUSER ;