Skip to content

Commit

Permalink
Fix the scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Jan 11, 2025
1 parent 4ce7704 commit d4f3f93
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 1,321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,20 @@ public void add(String name, DataTable table) {

var schema = new DataSchemaImpl(name, properties);

// Drop the table if it exists
var dropQuery = dropTable(schema);
logger.debug(dropQuery);
try (var dropStatement = connection.prepareStatement(dropQuery)) {
dropStatement.execute();
}

// Create the table
var createQuery = createTable(schema);
logger.debug(createQuery);
try (var createStatement = connection.prepareStatement(createQuery)) {
createStatement.execute();
}

// Truncate the table
var truncateQuery = truncateTable(schema);
logger.debug(truncateQuery);
try (var truncateStatement = connection.prepareStatement(truncateQuery)) {
truncateStatement.execute();
}

// Copy the data
var pgConnection = connection.unwrap(PGConnection.class);
var copyQuery = copy(schema);
Expand Down Expand Up @@ -206,6 +206,16 @@ protected String dropTable(DataSchema schema) {
return String.format("DROP TABLE IF EXISTS \"%s\" CASCADE", schema.name());
}

/**
* Generate a truncate table query.
*
* @param schema the schema
* @return the query
*/
protected String truncateTable(DataSchema schema) {
return String.format("TRUNCATE TABLE \"%s\" CASCADE", schema.name());
}

/**
* Generate a create table query.
*
Expand All @@ -214,7 +224,7 @@ protected String dropTable(DataSchema schema) {
*/
protected String createTable(DataSchema schema) {
StringBuilder builder = new StringBuilder();
builder.append("CREATE TABLE \"");
builder.append("CREATE TABLE IF NOT EXISTS \"");
builder.append(schema.name());
builder.append("\" (");
builder.append(schema.columns().stream()
Expand Down
9 changes: 7 additions & 2 deletions basemap/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export default {
"id": "openstreetmap-water-polygons",
"needs": [],
"tasks": [
// Initialization
"queries/initialize.sql",
"queries/functions.sql",

// OpenStreetMap
"layers/header/create.sql",
"layers/node/create.sql",
"layers/way/create.sql",
Expand All @@ -41,16 +46,16 @@ export default {
"layers/leisure/create.sql",
"layers/man_made/create.sql",
"layers/natural/create.sql",
//"layers/ocean/create.sql",
"layers/point/create.sql",
"layers/power/create.sql",
"layers/railway/create.sql",
"layers/route/create.sql",
"layers/tourism/create.sql",
"layers/waterway/create.sql",
"layers/ocean/create.sql",
].map(file => {
return {
"type": "ExecuteSql",
"type": "ExecuteSqlScript",
"file": file,
"database": config.database,
}
Expand Down
Loading

0 comments on commit d4f3f93

Please sign in to comment.