CDB_RegenerateTable: Add tests
This commit is contained in:
parent
fa765a68ea
commit
9bbf622bc4
@ -0,0 +1,165 @@
|
|||||||
|
-- Setup
|
||||||
|
\set QUIET on
|
||||||
|
SET client_min_messages TO error;
|
||||||
|
\set VERBOSITY terse
|
||||||
|
SET SESSION AUTHORIZATION postgres;
|
||||||
|
\set QUIET off
|
||||||
|
|
||||||
|
\echo '## Setup'
|
||||||
|
CREATE TABLE testtable (stable integer, c1 integer, c2 integer, c3 integer, c4 integer);
|
||||||
|
INSERT INTO testtable(stable,c1,c2,c3,c4) VALUES (1,2,3,4,5), (2,3,4,5,6), (3,4,5,6,7);
|
||||||
|
\d+ testtable
|
||||||
|
SELECT * FROM testtable ORDER BY stable ASC;
|
||||||
|
SELECT 'testtable'::regclass::oid as id INTO temp table original_oid;
|
||||||
|
|
||||||
|
\echo '## Run cartodb.CDB_RegenerateTable and confirm the data and columns are the same'
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
\d+ testtable
|
||||||
|
SELECT * FROM testtable ORDER BY stable ASC;
|
||||||
|
|
||||||
|
\echo '## The table oid must have changed since the table itself changed'
|
||||||
|
SELECT 'testtable'::regclass::oid as id INTO temp table new_oid;
|
||||||
|
SELECT original_oid.id = new_oid.id FROM original_oid, new_oid;
|
||||||
|
|
||||||
|
\echo '## Check adding an index'
|
||||||
|
CREATE INDEX testtable_stable_idx ON testtable (stable NULLS FIRST) WITH (fillfactor = 80, vacuum_cleanup_index_scale_factor = 0.11);
|
||||||
|
SELECT tablename, indexname, indexdef FROM pg_indexes WHERE tablename = 'testtable' ORDER BY tablename, indexname;
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
SELECT tablename, indexname, indexdef FROM pg_indexes WHERE tablename = 'testtable' ORDER BY tablename, indexname;
|
||||||
|
|
||||||
|
|
||||||
|
\echo '## Check column properties'
|
||||||
|
ALTER TABLE testtable ADD UNIQUE (c2);
|
||||||
|
ALTER TABLE testtable ALTER COLUMN c3 SET NOT NULL;
|
||||||
|
\d+ testtable
|
||||||
|
SELECT tablename, indexname, indexdef FROM pg_indexes WHERE tablename = 'testtable' ORDER BY tablename, indexname;
|
||||||
|
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
\d+ testtable
|
||||||
|
SELECT tablename, indexname, indexdef FROM pg_indexes WHERE tablename = 'testtable' ORDER BY tablename, indexname;
|
||||||
|
|
||||||
|
\echo '## Check triggers'
|
||||||
|
CREATE OR REPLACE FUNCTION trigger_example_fn()
|
||||||
|
RETURNS TRIGGER
|
||||||
|
LANGUAGE PLPGSQL
|
||||||
|
AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$;
|
||||||
|
|
||||||
|
CREATE TRIGGER testtable_trigger_example
|
||||||
|
BEFORE UPDATE
|
||||||
|
ON testtable
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE PROCEDURE trigger_example_fn();
|
||||||
|
|
||||||
|
SELECT event_object_schema as table_schema,
|
||||||
|
event_object_table as table_name,
|
||||||
|
trigger_schema,
|
||||||
|
trigger_name,
|
||||||
|
string_agg(event_manipulation, ',') as event,
|
||||||
|
action_timing as activation,
|
||||||
|
action_condition as condition,
|
||||||
|
action_statement as definition
|
||||||
|
FROM information_schema.triggers
|
||||||
|
WHERE event_object_table = 'testtable'
|
||||||
|
GROUP BY 1,2,3,4,6,7,8
|
||||||
|
ORDER BY table_schema,
|
||||||
|
table_name;
|
||||||
|
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
|
||||||
|
SELECT event_object_schema as table_schema,
|
||||||
|
event_object_table as table_name,
|
||||||
|
trigger_schema,
|
||||||
|
trigger_name,
|
||||||
|
string_agg(event_manipulation, ',') as event,
|
||||||
|
action_timing as activation,
|
||||||
|
action_condition as condition,
|
||||||
|
action_statement as definition
|
||||||
|
FROM information_schema.triggers
|
||||||
|
WHERE event_object_table = 'testtable'
|
||||||
|
GROUP BY 1,2,3,4,6,7,8
|
||||||
|
ORDER BY table_schema,
|
||||||
|
table_name;
|
||||||
|
|
||||||
|
\echo '## Check Cartodbfycation'
|
||||||
|
SELECT CDB_SetUserQuotaInBytes(0);
|
||||||
|
SELECT CDB_CartodbfyTable('testtable'::regclass);
|
||||||
|
\d+ testtable
|
||||||
|
SELECT tablename, indexname, indexdef FROM pg_indexes WHERE tablename = 'testtable' ORDER BY tablename, indexname;
|
||||||
|
SELECT event_object_schema as table_schema,
|
||||||
|
event_object_table as table_name,
|
||||||
|
trigger_schema,
|
||||||
|
trigger_name,
|
||||||
|
string_agg(event_manipulation, ',') as event,
|
||||||
|
action_timing as activation,
|
||||||
|
action_condition as condition,
|
||||||
|
action_statement as definition
|
||||||
|
FROM information_schema.triggers
|
||||||
|
WHERE event_object_table = 'testtable'
|
||||||
|
GROUP BY 1,2,3,4,6,7,8
|
||||||
|
ORDER BY table_schema,
|
||||||
|
table_name;
|
||||||
|
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
|
||||||
|
\d+ testtable
|
||||||
|
SELECT tablename, indexname, indexdef FROM pg_indexes WHERE tablename = 'testtable' ORDER BY tablename, indexname;
|
||||||
|
SELECT event_object_schema as table_schema,
|
||||||
|
event_object_table as table_name,
|
||||||
|
trigger_schema,
|
||||||
|
trigger_name,
|
||||||
|
string_agg(event_manipulation, ',') as event,
|
||||||
|
action_timing as activation,
|
||||||
|
action_condition as condition,
|
||||||
|
action_statement as definition
|
||||||
|
FROM information_schema.triggers
|
||||||
|
WHERE event_object_table = 'testtable'
|
||||||
|
GROUP BY 1,2,3,4,6,7,8
|
||||||
|
ORDER BY table_schema,
|
||||||
|
table_name;
|
||||||
|
|
||||||
|
\echo '## Test view / matview dependencies: It will not work but data will be the same'
|
||||||
|
CREATE VIEW testview AS SELECT * FROM testtable WHERE stable < 20;
|
||||||
|
SELECT * FROM testview ORDER BY stable ASC;
|
||||||
|
\d testtable
|
||||||
|
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
DROP VIEW testview;
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
|
||||||
|
CREATE MATERIALIZED VIEW testmatview AS SELECT * FROM testtable WHERE stable < 20;
|
||||||
|
SELECT * FROM testmatview ORDER BY stable ASC;
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
DROP MATERIALIZED VIEW testmatview;
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
|
||||||
|
\d testtable
|
||||||
|
|
||||||
|
\echo '## Test role access'
|
||||||
|
CREATE ROLE cdb_regenerate_tester LOGIN PASSWORD 'cdb_regenerate_pass';
|
||||||
|
GRANT CONNECT ON DATABASE contrib_regression TO cdb_regenerate_tester;
|
||||||
|
GRANT SELECT ON testtable TO cdb_regenerate_tester;
|
||||||
|
\c contrib_regression cdb_regenerate_tester
|
||||||
|
SELECT * FROM testtable ORDER BY cartodb_id DESC;
|
||||||
|
\c contrib_regression postgres
|
||||||
|
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
|
||||||
|
\c contrib_regression cdb_regenerate_tester
|
||||||
|
SELECT * FROM testtable ORDER BY cartodb_id DESC;
|
||||||
|
\c contrib_regression postgres
|
||||||
|
|
||||||
|
\echo '## Test calling with read only access (should fail)'
|
||||||
|
\c contrib_regression cdb_regenerate_tester
|
||||||
|
SELECT cartodb.CDB_RegenerateTable('testtable'::regclass::oid);
|
||||||
|
\c contrib_regression postgres
|
||||||
|
|
||||||
|
\echo '## teardown'
|
||||||
|
|
||||||
|
DROP TABLE testtable CASCADE;
|
||||||
|
REVOKE CONNECT ON DATABASE contrib_regression FROM cdb_regenerate_tester;
|
||||||
|
DROP ROLE cdb_regenerate_tester;
|
@ -0,0 +1,142 @@
|
|||||||
|
## Setup
|
||||||
|
CREATE TABLE
|
||||||
|
INSERT 0 3
|
||||||
|
stable|integer||||plain||
|
||||||
|
c1|integer||||plain||
|
||||||
|
c2|integer||||plain||
|
||||||
|
c3|integer||||plain||
|
||||||
|
c4|integer||||plain||
|
||||||
|
1|2|3|4|5
|
||||||
|
2|3|4|5|6
|
||||||
|
3|4|5|6|7
|
||||||
|
SELECT 1
|
||||||
|
## Run cartodb.CDB_RegenerateTable and confirm the data and columns are the same
|
||||||
|
|
||||||
|
stable|integer||||plain||
|
||||||
|
c1|integer||||plain||
|
||||||
|
c2|integer||||plain||
|
||||||
|
c3|integer||||plain||
|
||||||
|
c4|integer||||plain||
|
||||||
|
1|2|3|4|5
|
||||||
|
2|3|4|5|6
|
||||||
|
3|4|5|6|7
|
||||||
|
## The table oid must have changed since the table itself changed
|
||||||
|
SELECT 1
|
||||||
|
f
|
||||||
|
## Check adding an index
|
||||||
|
CREATE INDEX
|
||||||
|
testtable|testtable_stable_idx|CREATE INDEX testtable_stable_idx ON public.testtable USING btree (stable NULLS FIRST) WITH (fillfactor='80', vacuum_cleanup_index_scale_factor='0.11')
|
||||||
|
|
||||||
|
testtable|testtable_stable_idx|CREATE INDEX testtable_stable_idx ON public.testtable USING btree (stable NULLS FIRST) WITH (fillfactor='80', vacuum_cleanup_index_scale_factor='0.11')
|
||||||
|
## Check column properties
|
||||||
|
ALTER TABLE
|
||||||
|
ALTER TABLE
|
||||||
|
stable|integer||||plain||
|
||||||
|
c1|integer||||plain||
|
||||||
|
c2|integer||||plain||
|
||||||
|
c3|integer||not null||plain||
|
||||||
|
c4|integer||||plain||
|
||||||
|
testtable|testtable_c2_key|CREATE UNIQUE INDEX testtable_c2_key ON public.testtable USING btree (c2)
|
||||||
|
testtable|testtable_stable_idx|CREATE INDEX testtable_stable_idx ON public.testtable USING btree (stable NULLS FIRST) WITH (fillfactor='80', vacuum_cleanup_index_scale_factor='0.11')
|
||||||
|
|
||||||
|
stable|integer||||plain||
|
||||||
|
c1|integer||||plain||
|
||||||
|
c2|integer||||plain||
|
||||||
|
c3|integer||not null||plain||
|
||||||
|
c4|integer||||plain||
|
||||||
|
testtable|testtable_c2_key|CREATE UNIQUE INDEX testtable_c2_key ON public.testtable USING btree (c2)
|
||||||
|
testtable|testtable_stable_idx|CREATE INDEX testtable_stable_idx ON public.testtable USING btree (stable NULLS FIRST) WITH (fillfactor='80', vacuum_cleanup_index_scale_factor='0.11')
|
||||||
|
## Check triggers
|
||||||
|
CREATE FUNCTION
|
||||||
|
CREATE TRIGGER
|
||||||
|
public|testtable|public|testtable_trigger_example|UPDATE|BEFORE||EXECUTE FUNCTION trigger_example_fn()
|
||||||
|
|
||||||
|
public|testtable|public|testtable_trigger_example|UPDATE|BEFORE||EXECUTE FUNCTION trigger_example_fn()
|
||||||
|
## Check Cartodbfycation
|
||||||
|
0
|
||||||
|
testtable
|
||||||
|
cartodb_id|bigint||not null|nextval('testtable_cartodb_id_seq'::regclass)|plain||
|
||||||
|
the_geom|geometry(Geometry,4326)||||main||
|
||||||
|
the_geom_webmercator|geometry(Geometry,3857)||||main||
|
||||||
|
stable|integer||||plain||
|
||||||
|
c1|integer||||plain||
|
||||||
|
c2|integer||||plain||
|
||||||
|
c3|integer||||plain||
|
||||||
|
c4|integer||||plain||
|
||||||
|
testtable|testtable_pkey|CREATE UNIQUE INDEX testtable_pkey ON public.testtable USING btree (cartodb_id)
|
||||||
|
testtable|testtable_the_geom_idx|CREATE INDEX testtable_the_geom_idx ON public.testtable USING gist (the_geom)
|
||||||
|
testtable|testtable_the_geom_webmercator_idx|CREATE INDEX testtable_the_geom_webmercator_idx ON public.testtable USING gist (the_geom_webmercator)
|
||||||
|
public|testtable|public|test_quota|INSERT,UPDATE|BEFORE||EXECUTE FUNCTION cdb_checkquota('0.1', '-1', 'public')
|
||||||
|
public|testtable|public|test_quota_per_row|INSERT,UPDATE|BEFORE||EXECUTE FUNCTION cdb_checkquota('0.001', '-1', 'public')
|
||||||
|
public|testtable|public|track_updates|INSERT,DELETE,UPDATE|AFTER||EXECUTE FUNCTION cdb_tablemetadata_trigger()
|
||||||
|
public|testtable|public|update_the_geom_webmercator_trigger|UPDATE,INSERT|BEFORE||EXECUTE FUNCTION _cdb_update_the_geom_webmercator()
|
||||||
|
|
||||||
|
cartodb_id|bigint||not null|nextval('testtable_cartodb_id_seq'::regclass)|plain||
|
||||||
|
the_geom|geometry(Geometry,4326)||||main||
|
||||||
|
the_geom_webmercator|geometry(Geometry,3857)||||main||
|
||||||
|
stable|integer||||plain||
|
||||||
|
c1|integer||||plain||
|
||||||
|
c2|integer||||plain||
|
||||||
|
c3|integer||||plain||
|
||||||
|
c4|integer||||plain||
|
||||||
|
testtable|testtable_pkey|CREATE UNIQUE INDEX testtable_pkey ON public.testtable USING btree (cartodb_id)
|
||||||
|
testtable|testtable_the_geom_idx|CREATE INDEX testtable_the_geom_idx ON public.testtable USING gist (the_geom)
|
||||||
|
testtable|testtable_the_geom_webmercator_idx|CREATE INDEX testtable_the_geom_webmercator_idx ON public.testtable USING gist (the_geom_webmercator)
|
||||||
|
public|testtable|public|test_quota|INSERT,UPDATE|BEFORE||EXECUTE FUNCTION cdb_checkquota('0.1', '-1', 'public')
|
||||||
|
public|testtable|public|test_quota_per_row|INSERT,UPDATE|BEFORE||EXECUTE FUNCTION cdb_checkquota('0.001', '-1', 'public')
|
||||||
|
public|testtable|public|track_updates|INSERT,DELETE,UPDATE|AFTER||EXECUTE FUNCTION cdb_tablemetadata_trigger()
|
||||||
|
public|testtable|public|update_the_geom_webmercator_trigger|INSERT,UPDATE|BEFORE||EXECUTE FUNCTION _cdb_update_the_geom_webmercator()
|
||||||
|
## Test view / matview dependencies: It will not work but data will be the same
|
||||||
|
CREATE VIEW
|
||||||
|
1|||1|2|3|4|5
|
||||||
|
2|||2|3|4|5|6
|
||||||
|
3|||3|4|5|6|7
|
||||||
|
cartodb_id|bigint||not null|nextval('testtable_cartodb_id_seq'::regclass)
|
||||||
|
the_geom|geometry(Geometry,4326)|||
|
||||||
|
the_geom_webmercator|geometry(Geometry,3857)|||
|
||||||
|
stable|integer|||
|
||||||
|
c1|integer|||
|
||||||
|
c2|integer|||
|
||||||
|
c3|integer|||
|
||||||
|
c4|integer|||
|
||||||
|
ERROR: cannot drop table testtable because other objects depend on it
|
||||||
|
DROP VIEW
|
||||||
|
|
||||||
|
SELECT 3
|
||||||
|
1|||1|2|3|4|5
|
||||||
|
2|||2|3|4|5|6
|
||||||
|
3|||3|4|5|6|7
|
||||||
|
ERROR: cannot drop table testtable because other objects depend on it
|
||||||
|
DROP MATERIALIZED VIEW
|
||||||
|
|
||||||
|
cartodb_id|bigint||not null|nextval('testtable_cartodb_id_seq'::regclass)
|
||||||
|
the_geom|geometry(Geometry,4326)|||
|
||||||
|
the_geom_webmercator|geometry(Geometry,3857)|||
|
||||||
|
stable|integer|||
|
||||||
|
c1|integer|||
|
||||||
|
c2|integer|||
|
||||||
|
c3|integer|||
|
||||||
|
c4|integer|||
|
||||||
|
## Test role access
|
||||||
|
CREATE ROLE
|
||||||
|
GRANT
|
||||||
|
GRANT
|
||||||
|
You are now connected to database "contrib_regression" as user "cdb_regenerate_tester".
|
||||||
|
3|||3|4|5|6|7
|
||||||
|
2|||2|3|4|5|6
|
||||||
|
1|||1|2|3|4|5
|
||||||
|
You are now connected to database "contrib_regression" as user "postgres".
|
||||||
|
|
||||||
|
You are now connected to database "contrib_regression" as user "cdb_regenerate_tester".
|
||||||
|
3|||3|4|5|6|7
|
||||||
|
2|||2|3|4|5|6
|
||||||
|
1|||1|2|3|4|5
|
||||||
|
You are now connected to database "contrib_regression" as user "postgres".
|
||||||
|
## Test calling with read only access (should fail)
|
||||||
|
You are now connected to database "contrib_regression" as user "cdb_regenerate_tester".
|
||||||
|
ERROR: must be owner of table testtable
|
||||||
|
You are now connected to database "contrib_regression" as user "postgres".
|
||||||
|
## teardown
|
||||||
|
DROP TABLE
|
||||||
|
REVOKE
|
||||||
|
DROP ROLE
|
Loading…
Reference in New Issue
Block a user