-
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.
- moves sequelize DB stuff and express routes to /lib commonJS modules - adds env use to docker-compose and node.js - node server will now connect to the DB, create the .env database if it doesn't exist, then populate it with the appropriate tables etc if not already set up - node server will also (wipe and) populate the markers found in /public/markers into the DB for api return to frontend - implements PostGIS (spatially-aware PostgresDB) in docker compose w persistent volume la3map_pg_data - docker compose file has been updated to support healthchecks for both services & app dependency on DB running - docker compose will send env variable IS_DOCKER if running via docker to adjust for service hostname rather than assuming the service is running on localhost, or whatever is provided as POSTGRES_HOST in .env - saves marker geo data as geometry columns instead of raw json
- Loading branch information
Showing
9 changed files
with
480 additions
and
359 deletions.
There are no files selected for viewing
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,7 @@ | ||
APP_PORT=3192 | ||
POSTGRES_HOST=localhost | ||
POSTGRES_PORT=5432 | ||
POSTGRES_EXT_PORT=3193 | ||
POSTGRES_USER=postgres | ||
POSTGRES_PASSWORD=postgres | ||
POSTGRES_DB=la3map |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
package-lock.json | ||
app.db | ||
app.db | ||
.env |
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,50 @@ | ||
version: "3" | ||
|
||
name: la3map | ||
services: | ||
node: | ||
build: ./ | ||
working_dir: /usr/app | ||
environment: | ||
- NODE_ENV=production | ||
- IS_DOCKER=true | ||
ports: | ||
- ${APP_PORT}:3000 | ||
depends_on: | ||
postgres: | ||
condition: service_healthy | ||
healthcheck: | ||
test: | ||
[ | ||
"CMD", | ||
"curl", | ||
"-f", | ||
"http://localhost:3000/healthcheck" | ||
] | ||
interval: 30s | ||
timeout: 10s | ||
retries: 5 | ||
command: "npm start" | ||
restart: unless-stopped | ||
volumes: | ||
- ./:/usr/app | ||
- /usr/app/node_modules | ||
postgres: | ||
env_file: .env | ||
image: postgis/postgis:12-3.3 | ||
healthcheck: | ||
test: [ "CMD", "pg_isready", "-U", "${POSTGRES_USER}" ] | ||
interval: 5s | ||
timeout: 5s | ||
retries: 5 | ||
environment: | ||
- POSTGRES_USER=${POSTGRES_USER} | ||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
- POSTGRES_DB=${POSTGRES_DB} | ||
ports: | ||
- ${POSTGRES_EXT_PORT}:5432 | ||
volumes: | ||
- pg_data:/var/lib/postgresql/data | ||
|
||
volumes: | ||
pg_data: {} |
This file was deleted.
Oops, something went wrong.
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,98 @@ | ||
// database connection and model definitions | ||
|
||
const Sequelize = require('sequelize'); | ||
|
||
// create/connect database (SQLite) | ||
// const sequelize = new Sequelize({ | ||
// dialect: 'sqlite', | ||
// storage: dbFile, | ||
// // logging: false, | ||
// // transactionType: 'IMMEDIATE', | ||
// retry: { | ||
// max: 10 | ||
// } | ||
// }); | ||
|
||
|
||
// create/connect database (PostgreSQL) | ||
const sequelize = new Sequelize(`postgres://${process.env.POSTGRES_USER}:${process.env.POSTGRES_PASSWORD}@${process.env.POSTGRES_HOST}:${process.env.POSTGRES_PORT}/${process.env.POSTGRES_DB}`, { | ||
dialect: 'postgres', | ||
application_name: 'la3map', | ||
keepAlive: true, | ||
logging: false | ||
}); | ||
|
||
// define models | ||
const Drawing = sequelize.define('Drawing', { | ||
id: { | ||
type: Sequelize.UUID, | ||
defaultValue: Sequelize.UUIDV4, | ||
primaryKey: true, | ||
}, | ||
// data is json | ||
data: Sequelize.DataTypes.GEOMETRY, | ||
description: Sequelize.TEXT, | ||
color: Sequelize.TEXT, | ||
imageUrl: Sequelize.TEXT, | ||
}); | ||
|
||
const Session = sequelize.define('Session', { | ||
id: { | ||
type: Sequelize.UUID, | ||
defaultValue: Sequelize.UUIDV4, | ||
primaryKey: true, | ||
}, | ||
worldname: Sequelize.TEXT, | ||
}); | ||
|
||
const User = sequelize.define('User', { | ||
username: { | ||
type: Sequelize.TEXT, | ||
unique: true, | ||
}, | ||
password: Sequelize.TEXT, | ||
role: Sequelize.TEXT, | ||
}); | ||
|
||
|
||
const Marker = sequelize.define('Marker', { | ||
id: { | ||
type: Sequelize.UUID, | ||
defaultValue: Sequelize.UUIDV4, | ||
primaryKey: true, | ||
}, | ||
addon: { | ||
type: Sequelize.TEXT, | ||
}, | ||
marker_name: { | ||
type: Sequelize.TEXT, | ||
}, | ||
url: Sequelize.TEXT | ||
}, | ||
{ | ||
indexes: [ | ||
{ | ||
unique: true, | ||
fields: ['addon', 'marker_name'] | ||
} | ||
] | ||
} | ||
); | ||
|
||
// define relationships | ||
Drawing.Session = Drawing.belongsTo(Session, { | ||
foreignKey: 'session_id', | ||
onDelete: 'CASCADE', | ||
}); | ||
Session.Drawings = Session.hasMany(Drawing, { | ||
foreignKey: 'session_id', | ||
onDelete: 'CASCADE', | ||
}) | ||
|
||
module.exports = { | ||
sequelize, | ||
Drawing, | ||
Session, | ||
User, | ||
Marker, | ||
}; |
Oops, something went wrong.