Adds CDB_TableMetadataTouch function to be able to upsert updated_at
value in cdb_tablemetadata
This commit is contained in:
parent
38fe98d983
commit
da7b3b7080
@ -118,3 +118,21 @@ CREATE TRIGGER table_modified AFTER INSERT OR UPDATE
|
|||||||
ON CDB_TableMetadata FOR EACH ROW EXECUTE PROCEDURE
|
ON CDB_TableMetadata FOR EACH ROW EXECUTE PROCEDURE
|
||||||
_CDB_TableMetadata_Updated();
|
_CDB_TableMetadata_Updated();
|
||||||
|
|
||||||
|
|
||||||
|
-- similar to TOUCH(1) in unix filesystems but for table in cdb_tablemetadata
|
||||||
|
CREATE OR REPLACE FUNCTION public.CDB_TableMetadataTouch(tablename regclass)
|
||||||
|
RETURNS void AS
|
||||||
|
$$
|
||||||
|
BEGIN
|
||||||
|
WITH upsert AS (
|
||||||
|
UPDATE public.cdb_tablemetadata
|
||||||
|
SET updated_at = NOW()
|
||||||
|
WHERE tabname = tablename
|
||||||
|
RETURNING *
|
||||||
|
)
|
||||||
|
INSERT INTO public.cdb_tablemetadata (tabname, updated_at)
|
||||||
|
SELECT tablename, NOW()
|
||||||
|
WHERE NOT EXISTS (SELECT * FROM upsert);
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE 'plpgsql' VOLATILE STRICT;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
SET SCHEMA 'cartodb';
|
SET SCHEMA 'cartodb';
|
||||||
\i scripts-available/CDB_Quota.sql
|
\i scripts-available/CDB_Quota.sql
|
||||||
|
\i scripts-available/CDB_TableMetadata.sql
|
||||||
SET SCHEMA 'public';
|
SET SCHEMA 'public';
|
29
test/extension/test.sh
Normal file → Executable file
29
test/extension/test.sh
Normal file → Executable file
@ -75,6 +75,15 @@ function sql() {
|
|||||||
set_failed
|
set_failed
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$3" == "should-not" ]]
|
||||||
|
then
|
||||||
|
if [[ "${RESULT}" == "$4" ]]
|
||||||
|
then
|
||||||
|
log_error "QUERY '${QUERY}' did not expect '${RESULT}'"
|
||||||
|
set_failed
|
||||||
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -277,6 +286,26 @@ function test_quota_for_each_user() {
|
|||||||
sql cdb_testmember_2 "SELECT cartodb.CDB_UserDataSize('cdb_testmember_2'::TEXT);" should 4096
|
sql cdb_testmember_2 "SELECT cartodb.CDB_UserDataSize('cdb_testmember_2'::TEXT);" should 4096
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_cdb_tablemetadatatouch() {
|
||||||
|
sql "CREATE TABLE touch_example (a int)"
|
||||||
|
sql postgres "SELECT updated_at FROM CDB_TableMetadata WHERE tabname = 'touch_example'::regclass;" should ''
|
||||||
|
sql "SELECT CDB_TableMetadataTouch('touch_example');"
|
||||||
|
sql postgres "SELECT updated_at FROM CDB_TableMetadata WHERE tabname = 'touch_example'::regclass;" should-not ''
|
||||||
|
|
||||||
|
# Another call doesn't fail
|
||||||
|
sql "SELECT CDB_TableMetadataTouch('touch_example');"
|
||||||
|
sql postgres "SELECT updated_at FROM CDB_TableMetadata WHERE tabname = 'touch_example'::regclass;" should-not ''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### test tear down
|
||||||
|
sql 'DROP TABLE touch_example;'
|
||||||
|
}
|
||||||
|
|
||||||
|
function test_cdb_tablemetadatatouch_fails_for_unexistent_table() {
|
||||||
|
sql postgres "SELECT CDB_TableMetadataTouch('unexistent_example');" fails
|
||||||
|
}
|
||||||
|
|
||||||
#################################################### TESTS END HERE ####################################################
|
#################################################### TESTS END HERE ####################################################
|
||||||
|
|
||||||
run_tests $@
|
run_tests $@
|
||||||
|
Loading…
Reference in New Issue
Block a user