Skip to content

Commit

Permalink
Use comment on view to generate TileJson (#1507)
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkAndshark authored Oct 20, 2024
1 parent 398ca85 commit 48cce66
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 2 additions & 1 deletion martin/src/pg/scripts/query_available_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ WITH
SELECT
pg_namespace.nspname AS schema_name,
relname AS table_name,
CAST(obj_description(relfilenode, 'pg_class') AS VARCHAR) AS description
pg_description.description AS description
FROM pg_class
JOIN pg_namespace ON pg_class.relnamespace = pg_namespace.oid
LEFT JOIN pg_description ON pg_class.oid = pg_description.objoid
WHERE relkind = 'r' OR relkind = 'v'
)
SELECT schema,
Expand Down
7 changes: 4 additions & 3 deletions martin/tests/pg_server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ postgres:
let response = assert_response(response).await;
let body = read_body(response).await;
let body: serde_json::Value = serde_json::from_slice(&body).unwrap();
assert_yaml_snapshot!(body, @r###"
assert_yaml_snapshot!(body, @r#"
---
fonts: {}
sprites: {}
Expand Down Expand Up @@ -111,8 +111,9 @@ postgres:
content_type: application/x-protobuf
description: public.points1.geom
points1_vw:
attribution: some attribution from SQL comment
content_type: application/x-protobuf
description: public.points1_vw.geom
description: description from SQL comment
points2:
content_type: application/x-protobuf
description: public.points2.geom
Expand All @@ -127,7 +128,7 @@ postgres:
table_source_multiple_geom.1:
content_type: application/x-protobuf
description: public.table_source_multiple_geom.geom2
"###);
"#);
}

#[actix_rt::test]
Expand Down
7 changes: 4 additions & 3 deletions martin/tests/pg_table_source_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn init() {
#[actix_rt::test]
async fn table_source() {
let mock = mock_sources(mock_pgcfg("connection_string: $DATABASE_URL")).await;
assert_yaml_snapshot!(mock.0.tiles.get_catalog(), @r###"
assert_yaml_snapshot!(mock.0.tiles.get_catalog(), @r#"
---
"-function.withweired---_-characters":
content_type: application/x-protobuf
Expand Down Expand Up @@ -72,7 +72,8 @@ async fn table_source() {
description: public.points1.geom
points1_vw:
content_type: application/x-protobuf
description: public.points1_vw.geom
description: description from SQL comment
attribution: some attribution from SQL comment
points2:
content_type: application/x-protobuf
description: public.points2.geom
Expand All @@ -87,7 +88,7 @@ async fn table_source() {
table_source_multiple_geom.1:
content_type: application/x-protobuf
description: public.table_source_multiple_geom.geom2
"###);
"#);

let source = table(&mock, "table_source");
assert_yaml_snapshot!(source, @r###"
Expand Down
3 changes: 2 additions & 1 deletion tests/expected/auto/catalog_auto.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@
},
"points1_vw": {
"content_type": "application/x-protobuf",
"description": "public.points1_vw.geom"
"description": "description from SQL comment",
"attribution": "some attribution from SQL comment"
},
"points2": {
"content_type": "application/x-protobuf",
Expand Down
9 changes: 9 additions & 0 deletions tests/fixtures/tables/points1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ values (1, '0101000020E6100000EC3A2806EDDA61401C2041E87DDA2740'),

CREATE INDEX ON points1 USING GIST (geom);
CLUSTER points1_geom_idx ON points1;

DO $do$ BEGIN
EXECUTE 'COMMENT ON VIEW points1_vw IS $tj$' || $$
{
"description": "description from SQL comment",
"attribution": "some attribution from SQL comment"
}
$$::json || '$tj$';
END $do$;

0 comments on commit 48cce66

Please sign in to comment.