Skip to content

migration: postgres #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 109 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
109 commits
Select commit Hold shift + click to select a range
53e3bcd
start migration
fufeck May 8, 2024
abe816d
test
fufeck May 13, 2024
1753415
add varchar
fufeck May 13, 2024
9ce63aa
delete export
fufeck Jul 9, 2024
b8a02fc
delete dead package.json
fufeck Jul 9, 2024
c2de515
dead code
fufeck Jul 9, 2024
98abed7
link postgres to var env
fufeck Jul 15, 2024
1d2fe68
update voie service
fufeck Jul 15, 2024
152ef3f
update numero service
fufeck Jul 15, 2024
247873a
add findCentroid
fufeck Jul 15, 2024
159557b
stash
fufeck Jul 15, 2024
b53561e
change to uuid
fufeck Jul 15, 2024
6e1d790
refacto voie service
fufeck Jul 15, 2024
9a7bf66
avance on numero.service
fufeck Jul 15, 2024
ce06436
finish numeros and voie
fufeck Jul 15, 2024
80116d5
fix DTO
fufeck Jul 16, 2024
12a1fdc
migration toponyme service
fufeck Jul 16, 2024
7b8f219
base locales progress
fufeck Jul 16, 2024
87e30f5
finish service baseLocale
fufeck Jul 16, 2024
5d96301
correct import voie
fufeck Jul 16, 2024
d07f939
import toponyme
fufeck Jul 16, 2024
5c08215
import many numero
fufeck Jul 16, 2024
c178264
progress
fufeck Jul 16, 2024
d96b5b0
finish voie service
fufeck Jul 16, 2024
36e00d6
migration export csv
fufeck Jul 16, 2024
8713cf1
migration module habilitation
fufeck Jul 16, 2024
e429c97
finish without stat
fufeck Jul 16, 2024
7f3d06c
change geom srid postgis
fufeck Jul 16, 2024
be725d3
finish stats modules
fufeck Jul 16, 2024
6b73ced
correct find distinct parcelles
fufeck Jul 17, 2024
6692360
change numeros
fufeck Jul 17, 2024
614a1e1
change entities api property
fufeck Jul 17, 2024
79a3994
object id
fufeck Jul 17, 2024
7f749a9
Merge branch 'master' into fufeck_migration_postgres
fufeck Jul 17, 2024
3840f7d
correct
fufeck Jul 17, 2024
12d08e1
c
fufeck Jul 17, 2024
b4c2580
add banId
fufeck Jul 17, 2024
8b854f1
correct server tiles
fufeck Jul 17, 2024
e141d0b
correct extend
fufeck Jul 17, 2024
678a5b8
replace uuid to objectId
fufeck Jul 22, 2024
7308e3b
correct insert/update positions
fufeck Jul 22, 2024
65dd3e9
correct import many
fufeck Jul 22, 2024
c5afcfd
add import positions
fufeck Jul 22, 2024
8ab7d67
create/update voie
fufeck Jul 22, 2024
b91d5f8
create/update toponyme
fufeck Jul 22, 2024
e6a7a29
optional function in entities
fufeck Jul 22, 2024
601d305
correct batch numeros toponyme
fufeck Jul 22, 2024
c717cd6
correct create update numero
fufeck Jul 22, 2024
fc787c8
correct delete numero
fufeck Jul 22, 2024
8f7f072
soft delete toponyme
fufeck Jul 22, 2024
7385247
correct soft delete voie
fufeck Jul 22, 2024
8fa298d
correct route find all bal deleted
fufeck Jul 22, 2024
af84e55
correct trash voie
fufeck Jul 22, 2024
23b285d
delete batch
fufeck Jul 22, 2024
503b100
correct batch
fufeck Jul 23, 2024
2525137
correct import many toponyme
fufeck Jul 23, 2024
de43699
Merge branch 'master' into fufeck_migration_postgres
fufeck Jul 23, 2024
eee6e64
start test
fufeck Jul 23, 2024
a7996f9
correct test bases_locales
fufeck Jul 23, 2024
d4d0deb
correct test toponyme
fufeck Jul 23, 2024
c14c736
correct test voie
fufeck Jul 23, 2024
8382678
correct test numeros
fufeck Jul 23, 2024
1bb96cb
correct test habilitation
fufeck Jul 23, 2024
c788b2d
correct test publication
fufeck Jul 23, 2024
b387017
add test stats
fufeck Jul 24, 2024
685390a
correct test ci
fufeck Jul 24, 2024
716a870
Merge branch 'master' into fufeck_migration_postgres
fufeck Jul 24, 2024
1246e6c
correct build node 22
fufeck Jul 24, 2024
ac5c245
correct await
fufeck Jul 24, 2024
e0e6db9
correct connection and migration typeorm
fufeck Jul 24, 2024
4eb4ebd
start cron
fufeck Jul 24, 2024
9773684
add cache to cron
fufeck Jul 29, 2024
234af2f
correct test
fufeck Jul 29, 2024
dcf3bae
finish cron
fufeck Jul 29, 2024
3cd22f0
finish test cron
fufeck Jul 29, 2024
1d28947
test cron
fufeck Jul 29, 2024
61669b0
correct build cron
fufeck Jul 29, 2024
cf6846c
correct cache string redis
fufeck Jul 29, 2024
a120b43
index and rank
fufeck Jul 30, 2024
7d1da03
add migration to module
fufeck Jul 30, 2024
4a355c2
test email to
fufeck Jul 30, 2024
3eb3a8d
correct rank
fufeck Jul 30, 2024
cf9c4c1
correct mail
fufeck Jul 30, 2024
a99e8f3
correct return bug jules
fufeck Jul 30, 2024
d2a8ee1
delete schemas
fufeck Jul 31, 2024
cf84b24
add migration in code
fufeck Jul 31, 2024
8404d50
delete bal_id to numero entity
fufeck Aug 19, 2024
873bd4d
correct test
fufeck Aug 21, 2024
c55afad
correct lint
fufeck Aug 21, 2024
39e0183
order numeros
fufeck Aug 26, 2024
b7f1cf4
correct batch numero -> toponyme null
fufeck Aug 26, 2024
f6111ec
correct order csv liste voies
fufeck Aug 26, 2024
64c2808
Merge branch 'master' into fufeck_migration_postgres
fufeck Aug 26, 2024
445f92f
correct bug date updatedAt and sync.currentUpdated
fufeck Aug 26, 2024
c4798cd
correct test
fufeck Aug 26, 2024
f126acd
correct bases_locales updateOne
fufeck Aug 27, 2024
e5ca0c0
correct test
fufeck Aug 27, 2024
3568ee4
refacto migration initialization
fufeck Aug 27, 2024
c6e1cb0
update README
fufeck Aug 27, 2024
9ce7a8a
ci: correct coverage soundcloud
fufeck Aug 28, 2024
ccea6e6
correct alert souncloud
fufeck Aug 28, 2024
0e35609
correct alert souncloud part 2
fufeck Aug 28, 2024
0701a9a
correct object id mongo length in postgres
fufeck Sep 2, 2024
718ffb8
delete mongoose
fufeck Sep 2, 2024
8e65883
email case insencitive
fufeck Sep 2, 2024
0c8cb5a
change migration
fufeck Sep 2, 2024
d86e777
change index
fufeck Sep 3, 2024
ee085f3
correct mail balId
fufeck Sep 4, 2024
a5b8f7c
add space in numero and suffixe in numeroComplet
fufeck Sep 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
MONGODB_URL=mongodb://localhost:27017
MONGODB_DBNAME=api-bal

POSTGRES_URL=
REDIS_URL=

PORT=5000

SMTP_HOST=
SMTP_PORT=587
SMTP_USER=
SMTP_PASS=
SMTP_SECURE=
SMTP_FROM=
SMTP_BCC=
SHOW_EMAILS=YES

EDITOR_URL_PATTERN=https://mes-adresses.data.gouv.fr/bal/<id>/<token>

API_URL=http://localhost:5000
API_DEPOT_URL=https://plateforme-bal.adresse.data.gouv.fr/api-depot
API_DEPOT_CLIENT_ID=
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x, 22.x]
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -50,8 +50,8 @@ jobs:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install dependencies
run: yarn
- name: Test and coverage
run: yarn jest --coverage
# - name: Test and coverage
# run: yarn jest --coverage
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
Expand Down
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
clock: yarn start:cron
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ https://adresse-data-gouv-fr.gitbook.io/bal/mes-adresses

## Pré-requis

- [Node.js](https://nodejs.org) 16+
- [Node.js](https://nodejs.org) 18+
- [yarn](https://www.yarnpkg.com)
- [MongoDB](https://www.mongodb.com) 4+
- [PostgresSQL](https://www.postgresql.org/)
- [Redis](https://redis.io/fr/)

### Postgres

Le base de donnée postgres doit avoir l'extension postgis d'installé

```
CREATE EXTENSION postgis
```

## Utilisation

Expand Down Expand Up @@ -47,7 +56,6 @@ Lancer le cron de développement :
$ yarn dev:cron
```


### Production

Créer une version de production :
Expand Down Expand Up @@ -98,17 +106,17 @@ Cette application utilise des variables d'environnement pour sa configuration.
Elles peuvent être définies classiquement ou en créant un fichier `.env` sur la base du modèle `.env.sample`.

| Nom de la variable | Description |
| --------------------------| --------------------------------------------------------------------------- |
| `MONGODB_URL` | Paramètre de connexion à MongoDB |
| `MONGODB_DBNAME` | Nom de la base de données à utiliser |
| ------------------------- | --------------------------------------------------------------------------- |
| `POSTGRES_URL` | Url de connection a la db postgres |
| `REDIS_URL` | Url de connection a la db redis |
| `PORT` | Port à utiliser pour l'API |
| `SHOW_EMAILS` | Indique si les courriels doivent être affichés dans les logs (`YES`) |
| `API_URL` | URL de base de l’API |
| `API_DEPOT_URL` | URL de l'api-depot |
| `API_DEPOT_CLIENT_ID` | Id du client de l'api-depot |
| `API_DEPOT_CLIENT_SECRET` | Token du client de l'api-depot |
| `EDITOR_URL_PATTERN` | Pattern permettant de construire l'URL vers l'édition d'une BAL |
|---|---|
| `BAN_API_URL` | URL de ban-plateform |
| --- | --- |
| `SMTP_HOST` | Nom d'hôte du serveur SMTP |
| `SMTP_PORT` | Port du serveur SMTP |
| `SMTP_USER` | Nom d'utilisateur pour se connecter au serveur SMTP |
Expand Down
27 changes: 17 additions & 10 deletions apps/api/src/api.module.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ServeStaticModule } from '@nestjs/serve-static';
import { join } from 'path';

import { Initialization1725371358514 } from 'migrations/1725371358514-initialization';
import { BaseLocale } from '@/shared/entities/base_locale.entity';
import { Voie } from '@/shared/entities/voie.entity';
import { Numero } from '@/shared/entities/numero.entity';
import { Toponyme } from '@/shared/entities/toponyme.entity';
import { Position } from '@/shared/entities/position.entity';

import { NumeroModule } from './modules/numeros/numero.module';
import { BaseLocaleModule } from './modules/base_locale/base_locale.module';
import { VoieModule } from './modules/voie/voie.module';
import { ToponymeModule } from './modules/toponyme/toponyme.module';
import { StatsModule } from './modules/stats/stats.module';
import { AdminModule } from './modules/admin/admin.module';
import { CronModule } from 'apps/cron/src/cron.module';
import { MailerModule } from '@nestjs-modules/mailer';
import { MailerParams } from '@/shared/params/mailer.params';

@Module({
imports: [
ConfigModule.forRoot(),
ServeStaticModule.forRoot({
rootPath: join(__dirname, '../../../'),
renderPath: 'public/',
}),
ConfigModule.forRoot(),
MongooseModule.forRootAsync({
TypeOrmModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (config: ConfigService) => ({
uri: config.get('MONGODB_URL'),
dbName: config.get('MONGODB_DBNAME'),
type: 'postgres',
url: config.get('POSTGRES_URL'),
keepConnectionAlive: true,
schema: 'public',
migrationsRun: true,
migrations: [Initialization1725371358514],
entities: [BaseLocale, Voie, Numero, Toponyme, Position],
}),
inject: [ConfigService],
}),
Expand All @@ -35,9 +45,6 @@ import { MailerParams } from '@/shared/params/mailer.params';
VoieModule,
ToponymeModule,
StatsModule,
AdminModule,
// We run the cron module in the api module when deployed on Scalingo
...(process.env.RUN_CRON_IN_API === 'true' ? [CronModule] : []),
],
controllers: [],
providers: [],
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/lib/types/request.type.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Request } from 'express';

import { Numero } from '@/shared/schemas/numero/numero.schema';
import { Voie } from '@/shared/schemas/voie/voie.schema';
import { Toponyme } from '@/shared/schemas/toponyme/toponyme.schema';
import { BaseLocale } from '@/shared/schemas/base_locale/base_locale.schema';
import { Numero } from '@/shared/entities/numero.entity';
import { Voie } from '@/shared/entities/voie.entity';
import { Toponyme } from '@/shared/entities/toponyme.entity';
import { BaseLocale } from '@/shared/entities/base_locale.entity';

export interface CustomRequest extends Request {
token?: string;
Expand Down
72 changes: 72 additions & 0 deletions apps/api/src/lib/types/validator.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
export enum LevelEnum {
INFO = 'I',
WARNING = 'W',
ERROR = 'E',
}

export interface Field {
name: string;
schemaName: string;
}

export interface FieldNotFound {
schemaVersion: string;
schemaName: string;
level: LevelEnum;
}

export interface Row {
rawValues: any;
parsedValues: any;
additionalValues: any;
localizedValues: any;
errors: any[];
line: number;
isValid: boolean;
}

export interface FieldFileValidation {
value: string;
isValid: boolean;
}

export interface FileValidation {
encoding: FieldFileValidation;
delimiter: FieldFileValidation;
linebreak: FieldFileValidation;
}
export interface ProfileValidation {
code: string;
name: string;
isValid: boolean;
}

export interface ProfileError {
code: string;
level: LevelEnum;
}

export interface ParseError {
type: string;
code: string;
message: string;
row: number;
}

export interface ValidationBal {
encoding: string;
linebreak: string;
delimiter: string;
originalFields: string[];
parseOk: boolean;
parseErrors: ParseError[];
fields: Field[];
notFoundFields: FieldNotFound[];
rows: Row[];
fileValidation: FileValidation;
profilesValidation: Record<string, ProfileValidation>;
globalErrors: string[];
rowsErrors: string[];
uniqueErrors: string[];
profilErrors: ProfileError[];
}
Loading
Loading