Skip to main content

Database

Migrations

Generate migration:

npm run typeorm migration:generate -- -d ./src/planning/infrastructure/config/typeorm.config-migrations.ts migrations/migration-name

For unblocking purposes, the command can be run with:

cross-env NODE_ENV=development node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate -d ./src/planning/infrastructure/config/typeorm.config-migrations.ts migrations/initial-migration

Run migration:

npm run migration:run

Manual Migration

Copy SQL file to server:

scp -P [port] .\file.sql user@serverhost:~/migrations

On server, where database container is hosted:

  1. Do a database backup:
docker exec simops-db pg_dump -U postgres simops > dump.sql
  1. Copy SQL file and execute it:
docker cp ./localfile.sql containername:/container/path/file.sql
docker exec -u postgresuser containername psql dbname postgresuser -f /container/path/file.sql

Other details

For database synchronisation, specify NODE_ENV:

$ export NODE_ENV=development // Bash
$env:NODE_ENV = 'development' // PS

Third-party sources

Airport table is feeded from another source. Default source is Navigraph with Little NavMap database. It is based on AIRAC cycles.

To migrate data, open the SQLite datasource and export to CSV. With a SELECT, columns can be customized to the export.

SELECT airport_id, ident, name, country, tower_frequency, atis_frequency, altitude, lonx, laty
FROM airport;

Import from the CSV into the Simops airport table.

Update of cities, source database is GADB.

docker cp ./04-update_airport_cities.sql simops-db-local:/docker-entrypoint-initdb.d/
docker exec -u postgres simops-db-local psql simops postgres -f /docker-entrypoint-initdb.d/04-update_airport_cities.sql
  • pgAdmin, Open-source application for PostgreSQL.
  • DataGrip