-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
6,171 additions
and
5 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
db-management/migrations/20240712072852-osw-entity-column-alter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use strict'; | ||
|
||
var dbm; | ||
var type; | ||
var seed; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var Promise; | ||
|
||
/** | ||
* We receive the dbmigrate dependency from dbmigrate initially. | ||
* This enables us to not have to rely on NODE_PATH. | ||
*/ | ||
exports.setup = function(options, seedLink) { | ||
dbm = options.dbmigrate; | ||
type = dbm.dataType; | ||
seed = seedLink; | ||
Promise = options.Promise; | ||
}; | ||
|
||
exports.up = function(db) { | ||
var filePath = path.join(__dirname, 'sqls', '20240712072852-osw-entity-column-alter-up.sql'); | ||
return new Promise( function( resolve, reject ) { | ||
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ | ||
if (err) return reject(err); | ||
console.log('received data: ' + data); | ||
|
||
resolve(data); | ||
}); | ||
}) | ||
.then(function(data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports.down = function(db) { | ||
var filePath = path.join(__dirname, 'sqls', '20240712072852-osw-entity-column-alter-down.sql'); | ||
return new Promise( function( resolve, reject ) { | ||
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){ | ||
if (err) return reject(err); | ||
console.log('received data: ' + data); | ||
|
||
resolve(data); | ||
}); | ||
}) | ||
.then(function(data) { | ||
return db.runSql(data); | ||
}); | ||
}; | ||
|
||
exports._meta = { | ||
"version": 1 | ||
}; |
5 changes: 5 additions & 0 deletions
5
db-management/migrations/sqls/20240712072852-osw-entity-column-alter-down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE content.edge | ||
DROP COLUMN IF EXISTS "crossing:markings"; | ||
|
||
ALTER TABLE content.edge | ||
ADD COLUMN IF NOT EXISTS "crossing_markings" character varying GENERATED ALWAYS AS ((feature->'properties'->>'crossing:markings')::text) STORED; |
5 changes: 5 additions & 0 deletions
5
db-management/migrations/sqls/20240712072852-osw-entity-column-alter-up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ALTER TABLE content.edge | ||
DROP COLUMN IF EXISTS "crossing_markings"; | ||
|
||
ALTER TABLE content.edge | ||
ADD COLUMN IF NOT EXISTS "crossing:markings" character varying GENERATED ALWAYS AS ((feature->'properties'->>'crossing:markings')::text) STORED; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
const fs = require('fs'); | ||
|
||
// Read the JSON file | ||
fs.readFile('src/assets/opensidewalks_0.2.schema.json', 'utf8', (err, data) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
const ignore_keys = ["BuildingField", "BuildingFields", "BareNodeFields"]; | ||
const entity_types = { | ||
"RolledCurb": { | ||
"entity_type": "node" | ||
}, | ||
"RaisedCurb": { | ||
"entity_type": "node" | ||
}, | ||
"CurbRamp": { | ||
"entity_type": "node" | ||
}, | ||
"FlushCurb": { | ||
"entity_type": "node" | ||
}, | ||
"GenericCurb": { | ||
"entity_type": "node" | ||
}, | ||
"Footway": { | ||
"entity_type": "edge" | ||
}, | ||
"Sidewalk": { | ||
"entity_type": "edge" | ||
}, | ||
"Crossing": { | ||
"entity_type": "edge" | ||
}, | ||
"TrafficIsland": { | ||
"entity_type": "edge" | ||
}, | ||
"Pedestrian": { | ||
"entity_type": "edge" | ||
}, | ||
"Steps": { | ||
"entity_type": "edge" | ||
}, | ||
"LivingStreet": { | ||
"entity_type": "edge" | ||
}, | ||
"PrimaryStreet": { | ||
"entity_type": "edge" | ||
}, | ||
"SecondaryStreet": { | ||
"entity_type": "edge" | ||
}, | ||
"TertiaryStreet": { | ||
"entity_type": "edge" | ||
}, | ||
"ResidentialStreet": { | ||
"entity_type": "edge" | ||
}, | ||
"ServiceRoad": { | ||
"entity_type": "edge" | ||
}, | ||
"Alley": { | ||
"entity_type": "edge" | ||
}, | ||
"Driveway": { | ||
"entity_type": "edge" | ||
}, | ||
"ParkingAisle": { | ||
"entity_type": "edge" | ||
}, | ||
"TrunkRoad": { | ||
"entity_type": "edge" | ||
}, | ||
"UnclassifiedRoad": { | ||
"entity_type": "edge" | ||
}, | ||
"PedestrianZone": { | ||
"entity_type": "zone" | ||
}, | ||
"PowerPole": { | ||
"entity_type": "point" | ||
}, | ||
"FireHydrant": { | ||
"entity_type": "point" | ||
}, | ||
"Bench": { | ||
"entity_type": "point" | ||
}, | ||
"WasteBasket": { | ||
"entity_type": "point" | ||
}, | ||
"Bollard": { | ||
"entity_type": "point" | ||
}, | ||
"Manhole": { | ||
"entity_type": "point" | ||
}, | ||
"StreetLamp": { | ||
"entity_type": "point" | ||
}, | ||
"Fence": { | ||
"entity_type": "edge" | ||
} | ||
}; | ||
// Parse the JSON data | ||
const schema = JSON.parse(data); | ||
|
||
// Initialize an empty object to store the results | ||
let result = {}; | ||
|
||
// Iterate over each key in the definitions | ||
for (let key in schema.definitions) { | ||
// Check if the key starts with an underscore | ||
if (key.includes('Fields') && !ignore_keys.includes(key)) { | ||
// if (!key.startsWith('_')) { | ||
// Get the required properties | ||
let required = schema.definitions[key].required; | ||
|
||
// Initialize an empty object for the identifying_key_val | ||
let identifying_key_val = {}; | ||
|
||
// Iterate over each required property | ||
for (let prop of required) { | ||
// Check if the property starts with an underscore | ||
if (!prop.startsWith('_')) { | ||
// Get the first enum value for the property | ||
let enumVal = schema.definitions[key].properties[prop].enum[0]; | ||
// Add the property and its first enum value to the identifying_key_val object | ||
identifying_key_val[prop] = enumVal; | ||
} | ||
} | ||
|
||
let prop_key = key.replace("Fields", ""); | ||
// Add the identifying_key_val object to the result object | ||
result[prop_key] = { entity_type: entity_types[prop_key].entity_type, identifying_key_val }; | ||
} | ||
} | ||
let resultJson = JSON.stringify(result, null, 2); | ||
|
||
// Write the JSON string to a file | ||
fs.writeFile('src/assets/opensidewalks_0.2.identifying.fields.json', resultJson, 'utf8', (err) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
console.log('File has been saved.'); | ||
}); | ||
}); |
Oops, something went wrong.