-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add sha256sum helper * fmt dataset files * add sha256 to all existing datasets * check file signature upon download * fix asserts and async functions * [wip] wrap dataset downloads with cache * archive banatic sources and configure datasets * switch IGN to https * checksum local download if exists * define 7z path in flake.nix * add tests * rename MIRROR_URL to ETL_MIRROR_URL * pass ETL_MIRROL_URL to e2e docker image * configure e2e to use mirror * pass env in workflow file * fix IGN 2019-2020 SQL schemas * fix datasets * fix CEREMA datasets * fix CEREMA and BANATIC * fix INSEE MvtCom 2024 * flash geo migrations. broken sql migrations ;( * refresh all migrations * split data flashing * split seed/migrate/source commands * rm ETL skipped integration tests * hide logging with verbose arg * fix test * fix Migrator test * fix providers * move stuff around * fix test * remove postgresjs unused dependency * doc * doc * track flash migrations in db
- Loading branch information
1 parent
3b1dbd1
commit 8131bbf
Showing
246 changed files
with
9,714 additions
and
7,835 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
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,22 +1,62 @@ | ||
# Installation | ||
# Migrations | ||
|
||
``` | ||
npm install -g db-migrate db-migrate-pg | ||
``` | ||
## Requirements | ||
|
||
### Geo | ||
- `pg_dump` | ||
- `pg_restore` | ||
- `7z` | ||
- `sha256sum` | ||
- Access to the S3 bucket (Scaleway: geo-datasets-archives) (public read) | ||
|
||
7zip doit être installé afin de créer la table du référentiel géographique | ||
## Available commands | ||
|
||
``` | ||
npm run geo:import | ||
- `just migrate`: run all migrations and flash data from the cache | ||
- `just seed`: run all migrations and seed test data from `providers/migration/seeds` | ||
- `just source`: import datasets from `db/geo` to `geo.perimeters` | ||
- `just external_data_migrate`: import external datasets | ||
|
||
## Migrations | ||
|
||
Migrations are ordered by name in the `src/db/migrations` folder. | ||
|
||
- `000`: initial migrations (manual), e.g. `extensions.sql` | ||
- `050`: geo schema | ||
- `100`: application | ||
- `200`: fraud | ||
- `400`: observatory | ||
- `500`: cee | ||
- `600`: stats | ||
|
||
## Dump all schemas | ||
|
||
```shell | ||
pg_dump --no-owner --no-acl --no-comments -s -n geo > geo.sql | ||
pg_dump --no-owner --no-acl --no-comments -s -n cee > cee.sql | ||
pg_dump --no-owner --no-acl --no-comments -s \ | ||
-n dashboard_stats -n geo_stats -n observatoire_stats -n observatory \ | ||
> observatory.sql | ||
|
||
pg_dump --no-owner --no-acl --no-comments -s -n anomaly -n fraud -n fraudcheck > fraud.sql | ||
|
||
pg_dump --no-owner --no-acl --no-comments -s \ | ||
-n application -n auth -n carpool_v2 -n certificate -n common -n company \ | ||
-n export -n honor -n operator -n policy -n territory \ | ||
> application.sql | ||
``` | ||
|
||
# Usage | ||
## Dump data for flashing | ||
|
||
The `geo.perimeters` table can be sourced (see below) or flashed from a data dump. | ||
|
||
```shell | ||
# dump geo data for flashing | ||
DUMP_FILE=$(date +%F)_data.sql.7z | ||
pg_dump -Fc -xO -a -n geo | 7z a -si $DUMP_FILE | ||
sha256sum $DUMP_FILE | tee $DUMP_FILE.sha | ||
``` | ||
|
||
- basic | ||
`DATABASE_URL=postgres://postgres:postgres@postgres:5432/local db-migrate up` | ||
- with migrations dir | ||
`DATABASE_URL=postgres://test:test@localhost:5432/test db-migrate up -m /path/to/migrations` | ||
- verbose | ||
`DATABASE_URL=postgres://test:test@localhost:5432/test db-migrate up -v` | ||
1. Upload the archive alongside the sha256sum file to the cache bucket | ||
(geo-datasets-archives) using the web interface | ||
2. Set the visilibity of both files to public | ||
3. Update the cache configuration in the `api/src/db/cmd-migrate.ts` file | ||
with the public URL and the SHA256 checksum. |
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,20 @@ | ||
import { env_or_fail, env_or_false } from "@/lib/env/index.ts"; | ||
import { Migrator } from "@/pdc/providers/migration/Migrator.ts"; | ||
|
||
/** | ||
* Migrate command. | ||
* | ||
* Run SQL migrations from the migrations folder. | ||
* Flash data from remote cache. | ||
*/ | ||
const migrator = new Migrator(env_or_fail("APP_POSTGRES_URL"), false); | ||
await migrator.up(); | ||
await migrator.migrate({ | ||
skip: env_or_false("MIGRATIONS_SKIP_ALL"), | ||
flash: !env_or_false("MIGRATIONS_SKIP_FLASH"), | ||
cache: { | ||
url: "https://geo-datasets-archives.s3.fr-par.scw.cloud/20250120_data.pgsql.7z", | ||
sha: "9fbbd21fe84b77bac0536c270a2365c9a721ab067f8c9ccc1103e4b51a0432bf", | ||
}, | ||
}); | ||
await migrator.down(); |
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,14 @@ | ||
import { env_or_fail } from "@/lib/env/index.ts"; | ||
import { Migrator } from "@/pdc/providers/migration/Migrator.ts"; | ||
|
||
/** | ||
* Seed command. | ||
* | ||
* Run all SQL migrations from the `migrations` directory. | ||
* Seed test data from `providers/migration/seeds` directory. | ||
*/ | ||
const migrator = new Migrator(env_or_fail("APP_POSTGRES_URL"), false); | ||
await migrator.up(); | ||
await migrator.migrate({ skip: false, flash: false }); | ||
await migrator.seed(); | ||
await migrator.down(); |
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,18 @@ | ||
import { buildMigrator } from "@/db/geo/buildMigrator.ts"; | ||
import { env_or_fail } from "@/lib/env/index.ts"; | ||
|
||
/** | ||
* Source geo perimeters command | ||
* | ||
* Download and import geo perimeters from external datasets defined | ||
* in the ./geo directory. | ||
*/ | ||
const connectionString = env_or_fail("APP_POSTGRES_URL"); | ||
const migrator = buildMigrator({ | ||
pool: { connectionString }, | ||
app: { targetSchema: "geo", datasets: new Set() }, | ||
}); | ||
|
||
await migrator.prepare(); | ||
await migrator.run(); | ||
await migrator.cleanup(); |
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
7 changes: 1 addition & 6 deletions
7
...xternal_data/datasets/AiresCovoiturage.ts → ...xternal_data/datasets/AiresCovoiturage.ts
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
7 changes: 1 addition & 6 deletions
7
...ernal_data/datasets/IncentiveCampaigns.ts → ...ernal_data/datasets/IncentiveCampaigns.ts
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
2 changes: 1 addition & 1 deletion
2
...structures/CreateAiresCovoiturageTable.ts → ...structures/CreateAiresCovoiturageTable.ts
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
2 changes: 1 addition & 1 deletion
2
...ructures/CreateIncentiveCampaignsTable.ts → ...ructures/CreateIncentiveCampaignsTable.ts
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
File renamed without changes.
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
Oops, something went wrong.