Skip to content

Commit 8d858f1

Browse files
authored
Improve the basemap schema and workflow (#910)
- Split the schema and the refresh scripts in the basemap - Prefix all the openstreetmap tables and views with osm_ - Use singular name everywhere in the database - Add the option to truncate the existing osm tables - Use CREATE OR REPLACE for views - Use IF NOT EXISTS for materialized views - Configure the spotless dbeaver sql formatter - Format the sql code - Add cache directory to ignored files - Improve the coherence between layers - Fix minor style issues - Improve the README of the basemap
1 parent 51b638a commit 8d858f1

File tree

152 files changed

+9071
-5992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+9071
-5992
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ basemap/cache_*/
2626
basemap/local.*
2727
basemap/tiles.mbtiles
2828
basemap/tiles/
29+
basemap/cache/
2930

3031
# Examples
3132
examples/ip-to-location/archives/

.run/basemap-serve.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<configuration default="false" name="basemap-serve" type="Application" factoryName="Application">
33
<option name="MAIN_CLASS_NAME" value="org.apache.baremaps.cli.Baremaps" />
44
<module name="baremaps-cli" />
5-
<option name="PROGRAM_PARAMETERS" value="map serve --tileset tileset.js --style style.js" />
5+
<option name="PROGRAM_PARAMETERS" value="map serve --tileset tileset.js --style style.js --log-level DEBUG" />
66
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/basemap" />
77
<method v="2">
88
<option name="Make" enabled="true" />

baremaps-cli/src/main/java/org/apache/baremaps/cli/database/ImportOsm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.baremaps.cli.database;
1919

2020

21-
2221
import java.nio.file.Path;
2322
import java.util.concurrent.Callable;
2423
import org.apache.baremaps.cli.Options;
@@ -55,6 +54,7 @@ public Integer call() throws Exception {
5554
file.toAbsolutePath(),
5655
database,
5756
srid,
57+
true,
5858
true).execute(new WorkflowContext());
5959
return 0;
6060
}

baremaps-core/src/main/java/org/apache/baremaps/tasks/ImportOsmPbf.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class ImportOsmPbf implements Task {
4444
private Object database;
4545
private Integer databaseSrid;
4646
private Boolean replaceExisting;
47+
private Boolean truncateTables;
4748

4849
/**
4950
* Constructs a {@code ImportOsmPbf}.
@@ -61,11 +62,12 @@ public ImportOsmPbf() {
6162
* @param replaceExisting whether to replace the existing tables
6263
*/
6364
public ImportOsmPbf(Path file, Object database,
64-
Integer databaseSrid, Boolean replaceExisting) {
65+
Integer databaseSrid, Boolean replaceExisting, Boolean truncateTables) {
6566
this.file = file;
6667
this.database = database;
6768
this.databaseSrid = databaseSrid;
6869
this.replaceExisting = replaceExisting;
70+
this.truncateTables = truncateTables;
6971
}
7072

7173
/**
@@ -82,8 +84,8 @@ public void execute(WorkflowContext context) throws Exception {
8284
var wayRepository = new WayRepository(datasource);
8385
var relationRepository = new RelationRepository(datasource);
8486

87+
// Drop the existing tables
8588
if (TRUE.equals(replaceExisting)) {
86-
// Drop the existing tables
8789
headerRepository.drop();
8890
nodeRepository.drop();
8991
wayRepository.drop();
@@ -96,6 +98,14 @@ public void execute(WorkflowContext context) throws Exception {
9698
relationRepository.create();
9799
}
98100

101+
// Truncate the existing tables
102+
if (TRUE.equals(truncateTables)) {
103+
headerRepository.truncate();
104+
nodeRepository.truncate();
105+
wayRepository.truncate();
106+
relationRepository.truncate();
107+
}
108+
99109
var coordinateMap = context.getCoordinateMap();
100110
var referenceMap = context.getReferenceMap();
101111

baremaps-core/src/test/java/org/apache/baremaps/workflow/ObjectMapperTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void test() throws IOException {
4343
new Step("import", List.of("download"),
4444
List.of(new ImportOsmPbf(Paths.get("liechtenstein-latest.osm.pbf"),
4545
"jdbc:postgresql://localhost:5432/baremaps?&user=baremaps&password=baremaps",
46-
3857, true)))));
46+
3857, true, true)))));
4747
var json = mapper.writeValueAsString(workflow1);
4848
assertTrue(json.contains(DownloadUrl.class.getSimpleName()));
4949
assertTrue(json.contains(ImportOsmPbf.class.getSimpleName()));

baremaps-core/src/test/java/org/apache/baremaps/workflow/WorkflowTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void execute() {
103103
new Step("import-osmpbf", List.of("fetch-osmpbf"),
104104
List.of(new ImportOsmPbf(Paths.get("downloads/liechtenstein.osm.pbf"),
105105
jdbcUrl(),
106-
3857, true))),
106+
3857, true, true))),
107107
new Step("fetch-shapefile", List.of(), List.of(new DownloadUrl(
108108
"https://osmdata.openstreetmap.de/download/simplified-water-polygons-split-3857.zip",
109109
Paths.get("downloads/simplified-water-polygons-split-3857.zip"), false))),

baremaps-postgres/src/main/java/org/apache/baremaps/postgres/openstreetmap/CoordinateMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class CoordinateMap extends PostgresMap<Long, Coordinate> {
5353
* Constructs a {@link CoordinateMap}.
5454
*/
5555
public CoordinateMap(DataSource dataSource) {
56-
this(dataSource, "public", "osm_nodes");
56+
this(dataSource, "public", "osm_node");
5757
}
5858

5959
/**

baremaps-postgres/src/main/java/org/apache/baremaps/postgres/openstreetmap/HeaderRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public HeaderRepository(DataSource dataSource) {
6767
this(
6868
dataSource,
6969
"public",
70-
"osm_headers",
70+
"osm_header",
7171
"replication_sequence_number",
7272
"replication_timestamp",
7373
"replication_url",

baremaps-postgres/src/main/java/org/apache/baremaps/postgres/openstreetmap/NodeRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public NodeRepository(DataSource dataSource) {
7474
this(
7575
dataSource,
7676
"public",
77-
"osm_nodes",
77+
"osm_node",
7878
"id",
7979
"version",
8080
"uid",

baremaps-postgres/src/main/java/org/apache/baremaps/postgres/openstreetmap/ReferenceMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class ReferenceMap extends PostgresMap<Long, List<Long>> {
5555
* Constructs a {@code PostgresReferenceMap}.
5656
*/
5757
public ReferenceMap(DataSource dataSource) {
58-
this(dataSource, "public", "osm_ways");
58+
this(dataSource, "public", "osm_way");
5959
}
6060

6161
/**

0 commit comments

Comments
 (0)