@tricoteuses/senat 3.1.20 → 3.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/LICENSE.md +32 -32
  2. package/README.md +326 -326
  3. package/lib/src/other_types/collaborateurs.d.ts +5 -0
  4. package/lib/src/other_types/manifest.d.ts +11 -0
  5. package/lib/src/parsers/collaborateurs.d.ts +44 -0
  6. package/lib/src/parsers/collaborateurs.js +157 -0
  7. package/lib/src/scripts/retrieve_agenda.js +38 -4
  8. package/lib/src/scripts/retrieve_collaborateurs.js +166 -0
  9. package/lib/src/scripts/shared/incremental_import_sql.js +859 -859
  10. package/lib/src/scripts/shared/schema_version.js +84 -84
  11. package/lib/src/scripts/shared/staging_metadata_sql.js +214 -214
  12. package/lib/src/scripts/validate_prefixed_tables.js +12 -12
  13. package/lib/src/server/ameli.js +11 -11
  14. package/lib/src/server/conversion_textes.js +106 -106
  15. package/lib/src/server/debats.js +10 -10
  16. package/lib/src/server/documents.js +22 -22
  17. package/lib/src/server/dosleg.js +33 -33
  18. package/lib/src/server/questions.js +10 -10
  19. package/lib/src/server/scrutins.js +3 -3
  20. package/lib/src/server/sens.js +19 -19
  21. package/lib/src/utils/manifest.d.ts +6 -0
  22. package/lib/src/utils/manifest.js +37 -0
  23. package/lib/src/utils/reunion_deletion.d.ts +2 -0
  24. package/lib/src/utils/reunion_deletion.js +27 -0
  25. package/lib/src/videos/match.js +4 -4
  26. package/lib/tests/collaborateurs.test.js +115 -0
  27. package/package.json +117 -117
  28. package/lib/src/config.d.ts +0 -21
  29. package/lib/src/config.js +0 -27
  30. package/lib/src/conversion_textes.d.ts +0 -11
  31. package/lib/src/conversion_textes.js +0 -316
  32. package/lib/src/databases.d.ts +0 -2
  33. package/lib/src/databases.js +0 -26
  34. package/lib/src/datasets.d.ts +0 -34
  35. package/lib/src/datasets.js +0 -233
  36. package/lib/src/git.d.ts +0 -26
  37. package/lib/src/git.js +0 -217
  38. package/lib/src/loaders.d.ts +0 -52
  39. package/lib/src/loaders.js +0 -254
  40. package/lib/src/model/agenda.d.ts +0 -6
  41. package/lib/src/model/agenda.js +0 -148
  42. package/lib/src/model/ameli.d.ts +0 -55
  43. package/lib/src/model/ameli.js +0 -148
  44. package/lib/src/model/commission.d.ts +0 -18
  45. package/lib/src/model/commission.js +0 -269
  46. package/lib/src/model/debats.d.ts +0 -67
  47. package/lib/src/model/debats.js +0 -95
  48. package/lib/src/model/documents.d.ts +0 -12
  49. package/lib/src/model/documents.js +0 -141
  50. package/lib/src/model/dosleg.d.ts +0 -7
  51. package/lib/src/model/dosleg.js +0 -326
  52. package/lib/src/model/index.d.ts +0 -7
  53. package/lib/src/model/index.js +0 -7
  54. package/lib/src/model/questions.d.ts +0 -45
  55. package/lib/src/model/questions.js +0 -89
  56. package/lib/src/model/scrutins.d.ts +0 -13
  57. package/lib/src/model/scrutins.js +0 -114
  58. package/lib/src/model/seance.d.ts +0 -3
  59. package/lib/src/model/seance.js +0 -267
  60. package/lib/src/model/sens.d.ts +0 -182
  61. package/lib/src/model/sens.js +0 -485
  62. package/lib/src/model/util.d.ts +0 -9
  63. package/lib/src/model/util.js +0 -38
  64. package/lib/src/raw_types/ameli.d.ts +0 -914
  65. package/lib/src/raw_types/ameli.js +0 -5
  66. package/lib/src/raw_types/debats.d.ts +0 -207
  67. package/lib/src/raw_types/debats.js +0 -5
  68. package/lib/src/raw_types/dosleg.d.ts +0 -1619
  69. package/lib/src/raw_types/dosleg.js +0 -5
  70. package/lib/src/raw_types/questions.d.ts +0 -423
  71. package/lib/src/raw_types/questions.js +0 -5
  72. package/lib/src/raw_types/senat.d.ts +0 -11372
  73. package/lib/src/raw_types/senat.js +0 -5
  74. package/lib/src/raw_types/sens.d.ts +0 -8248
  75. package/lib/src/raw_types/sens.js +0 -5
  76. package/lib/src/raw_types_schemats/ameli.d.ts +0 -539
  77. package/lib/src/raw_types_schemats/ameli.js +0 -2
  78. package/lib/src/raw_types_schemats/debats.d.ts +0 -127
  79. package/lib/src/raw_types_schemats/debats.js +0 -2
  80. package/lib/src/raw_types_schemats/dosleg.d.ts +0 -977
  81. package/lib/src/raw_types_schemats/dosleg.js +0 -2
  82. package/lib/src/raw_types_schemats/questions.d.ts +0 -237
  83. package/lib/src/raw_types_schemats/questions.js +0 -2
  84. package/lib/src/raw_types_schemats/sens.d.ts +0 -6915
  85. package/lib/src/raw_types_schemats/sens.js +0 -2
  86. package/lib/src/scripts/test_iter_load.js +0 -12
  87. package/lib/src/types/agenda.d.ts +0 -45
  88. package/lib/src/types/ameli.d.ts +0 -5
  89. package/lib/src/types/compte_rendu.d.ts +0 -83
  90. package/lib/src/types/debats.d.ts +0 -2
  91. package/lib/src/types/debats.js +0 -1
  92. package/lib/src/types/dosleg.d.ts +0 -70
  93. package/lib/src/types/dosleg.js +0 -1
  94. package/lib/src/types/questions.d.ts +0 -2
  95. package/lib/src/types/questions.js +0 -1
  96. package/lib/src/types/sens.d.ts +0 -10
  97. package/lib/src/types/sens.js +0 -1
  98. package/lib/src/types/sessions.d.ts +0 -6
  99. package/lib/src/types/sessions.js +0 -19
  100. package/lib/src/types/texte.d.ts +0 -72
  101. package/lib/src/types/texte.js +0 -15
  102. package/lib/src/validators/config.d.ts +0 -9
  103. package/lib/src/validators/config.js +0 -10
  104. /package/lib/src/{scripts/test_iter_load.d.ts → other_types/collaborateurs.js} +0 -0
  105. /package/lib/src/{types/agenda.js → other_types/manifest.js} +0 -0
  106. /package/lib/src/{types/ameli.js → scripts/retrieve_collaborateurs.d.ts} +0 -0
  107. /package/lib/{src/types/compte_rendu.js → tests/collaborateurs.test.d.ts} +0 -0
package/README.md CHANGED
@@ -1,326 +1,326 @@
1
- # Tricoteuses-Senat
2
-
3
- ## _Retrieve, clean up & handle French Sénat's open data_
4
-
5
- ## Requirements
6
-
7
- - Node >= 22
8
-
9
- ## Installation
10
-
11
- ```bash
12
- git clone https://git.tricoteuses.fr/logiciels/tricoteuses-senat
13
- cd tricoteuses-senat/
14
- ```
15
-
16
- Create a `.env` file to set PostgreSQL database informations and other configuration variables (you can use `example.env` as a template). Then
17
-
18
- ```bash
19
- npm install
20
- ```
21
-
22
- ### Database creation (not needed if downloading with Docker image)
23
-
24
- #### Using Docker
25
-
26
- ```bash
27
- docker run --name local-postgres -d -p 5432:5432 -e POSTGRES_PASSWORD=$YOUR_CUSTOM_DB_PASSWORD postgres
28
- ```
29
-
30
- ## Download data
31
-
32
- ### Basic usage
33
-
34
- Create a folder where the data will be downloaded and run the following command to download the data and convert it into JSON files.
35
-
36
- ```bash
37
- mkdir ../senat-data/
38
-
39
- npm run data:download ../senat-data
40
- ```
41
-
42
- ### Available Commands
43
-
44
- - `npm run data:download <dir>`: Download, convert data to JSON
45
- - `npm run data:retrieve_documents <dir>`: Retrieval of textes and rapports from Sénat's website
46
- - `npm run data:retrieve_agenda <dir>`: Retrieval of agenda from Sénat's website
47
- - `npm run data:retrieve_cr_seance <dir>`: Retrieval of comptes-rendus de séance from Sénat's data
48
- - `npm run data:retrieve_cr_commission <dir>`: Retrieval of comptes-rendus de commissions from Sénat's website
49
- - `npm run data:retrieve_senateurs_photos <dir>`: Retrieval of sénateurs' pictures from Sénat's website
50
-
51
- ### Filtering Options
52
-
53
- Downloading all the data is long and takes up a lot of disk space. It is possible to choose the type of data that you want to retrieve to reduce the load.
54
-
55
- Examples:
56
-
57
- ```bash
58
- # Only download amendments
59
- npm run data:download ../senat-data -- -k Ameli
60
-
61
- # Only process data from session 2023 onwards
62
- npm run data:download ../senat-data -- --fromSession 2023
63
- ```
64
-
65
- ### Common Options
66
-
67
- - `--categories` or `-k <name>`: Filter by dataset categories (Available options: `All`, `Ameli`, `Debats`, `DosLeg`, `Questions`, `Sens`)
68
- - `--fromSession <year>`: Specify the session year to retrieve data from (default: 2022)
69
- - `--dataDir <path>` (Mandatory): Path to the working directory where all data is stored (required)
70
- - `--silent` or `-s`: Disable logging
71
- - `--verbose` or `-v`: Enable verbose logging
72
- - `--commit` or `-c`: Automatically commit converted data
73
- - `--pull` or `-p`: Pull repositories before starting
74
- - `--clone` or `-C <url>`: Clone Git repositories from a remote group or organization
75
- - `--remote` or `-r <name>`: Push commits to specified Git remote(s)
76
- - `--keepDir`: Keep directories when cleaning data
77
- - `--only-recent <days>`: Retrieve only documents created within the last N days
78
-
79
- ### Options for Retrieving Documents
80
-
81
- - `--formats <format>`: Specify document formats to retrieve (options: `xml`, `html`, `pdf`)
82
- - `--types <type>`: Specify document types to retrieve (options: `textes`, `rapports`)
83
- - `--parseDocuments`: Parse documents after retrieval
84
- - `--parseAgenda`: Parse agenda after retrieval
85
- - `--parseDebats`: Parse comptes-rendus after retrieval
86
-
87
- #### Examples
88
-
89
- ```bash
90
- # Retrieval of textes and rapports in specific formats
91
- npm run data:retrieve_documents ../senat-data -- --fromSession 2022 --formats xml pdf --types textes
92
-
93
- # Retrieval & parsing (textes in xml format only for now)
94
- npm run data:retrieve_documents ../senat-data -- --fromSession 2022 --parseDocuments
95
-
96
- # Retrieval & parsing of agenda
97
- npm run data:retrieve_agenda ../senat-data -- --fromSession 2022 --parseAgenda
98
-
99
- # Retrieval & parsing of comptes-rendus de séance
100
- npm run data:retrieve_cr_seance ../senat-data -- --parseDebats --keepDir
101
-
102
- # Retrieval & parsing of comptes-rendus de commissions
103
- npm run data:retrieve_cr_commission ../senat-data -- --parseDebats --keepDir
104
- ```
105
-
106
- ## Data download using Docker
107
-
108
- A Docker image that downloads and converts the data all at once is available. Build it locally or run it from the container registry.
109
- Use the environment variables `FROM_SESSION` and `CATEGORIES` if needed.
110
-
111
- ```bash
112
- docker run --pull always --name tricoteuses-senat -v ../senat-data:/app/senat-data -d git.tricoteuses.fr/logiciels/tricoteuses-senat:latest
113
- ```
114
-
115
- Use the environment variable `CATEGORIES` and `FROM_SESSION` if needed.
116
-
117
- ## Using the data
118
-
119
- Once the data is downloaded, you can use loaders to retrieve it.
120
- To use loaders in your project, you can install the _@tricoteuses/senat_ package, and import the iterator functions that you need.
121
-
122
- ```bash
123
- npm install @tricoteuses/senat
124
- ```
125
-
126
- ```js
127
- import { iterLoadSenatQuestions } from "@tricoteuses/senat/loaders"
128
-
129
- // Pass data directory and legislature as arguments
130
- for (const { item: question } of iterLoadSenatQuestions("../senat-data", 17)) {
131
- console.log(question.id)
132
- }
133
- ```
134
-
135
- ## Generation of raw types from SQL schema (for contributors only)
136
-
137
- ```bash
138
- npm run data:generate_schemas ../senat-data
139
- ```
140
-
141
- ## PostgreSQL import modes
142
-
143
- `retrieve_open_data.ts` supports two import modes:
144
-
145
- - default mode: direct import in a single database
146
- - `--incremental`: separate staging database plus `postgres_fdw` bridge into the target database
147
-
148
- The default mode is the simplest one and is the one used by the Docker image. The incremental mode is intended for replicated environments where heavy transient work should stay outside the target database.
149
-
150
- ## Incremental PostgreSQL import architecture
151
-
152
- When `--incremental` is enabled, the open-data SQL import is designed to keep heavy transient work out of the replicated target database.
153
-
154
- ```text
155
- +-----------------------------------+
156
- | Source Open Data Senat |
157
- | ZIP -> SQL dumps |
158
- +----------------+------------------+
159
- |
160
- v
161
- +-----------------------------------+
162
- | PostgreSQL staging instance |
163
- | non-replicated |
164
- | database: senat_staging |
165
- | |
166
- | schemas: |
167
- | - ameli_staging |
168
- | - debats_staging |
169
- | - dosleg_staging |
170
- | - questions_staging |
171
- | - sens_staging |
172
- | |
173
- | heavy operations: |
174
- | - raw dump import |
175
- | - table renaming/prefixing |
176
- | - staging indexes |
177
- +----------------+------------------+
178
- |
179
- postgres_fdw (read-only bridge)
180
- |
181
- v
182
- +----------------------------------------------------------------------------+
183
- | PostgreSQL target instance, replicated |
184
- | database: canutes |
185
- | |
186
- | preserved schemas: assemblee, legifrance, ... |
187
- | updated schema: senat |
188
- | |
189
- | lightweight temporary FDW schemas: |
190
- | - ameli_staging |
191
- | - debats_staging |
192
- | - dosleg_staging |
193
- | - questions_staging |
194
- | - sens_staging |
195
- | |
196
- | final operations only: |
197
- | - read staging data through postgres_fdw |
198
- | - incremental merge into canutes.senat |
199
- | - optional schema alignment when source structure changes |
200
- +----------------------------------------------------------------------------+
201
- ```
202
-
203
- At the end of an incremental import:
204
-
205
- - the target database is `canutes`
206
- - the target schema is `senat`
207
- - other schemas in `canutes` are left untouched
208
- - bulk transient data stays in the staging database
209
-
210
- ## Direct single-database mode
211
-
212
- Without `--incremental`, the script works directly in the configured target database:
213
-
214
- - dumps are imported into temporary `*_staging` schemas in that same database
215
- - the final tables are merged into schema `senat`
216
- - the temporary staging schemas are dropped at the end
217
-
218
- This mode is appropriate for:
219
-
220
- - local development
221
- - disposable databases
222
- - the Docker image workflow
223
- - environments where replication cost is not a concern
224
-
225
- ## Preparing postgres_fdw and database rights
226
-
227
- This section only applies when using `--incremental`.
228
-
229
- The target database must be able to connect to the separate staging database with `postgres_fdw`.
230
-
231
- ### Environment variables
232
-
233
- Set the target connection in `.env`. Add the staging connection only if you use `--incremental`:
234
-
235
- ```bash
236
- # Target database
237
- DB_HOST="localhost"
238
- DB_PORT=5432
239
- DB_USER="postgres"
240
- DB_PASSWORD="PASSWORD"
241
- DB_NAME="canutes"
242
-
243
- # Separate non-replicated staging database or instance, only for --incremental
244
- STAGING_DB_HOST="localhost"
245
- STAGING_DB_PORT=5433
246
- STAGING_DB_USER="postgres"
247
- STAGING_DB_PASSWORD="PASSWORD"
248
- STAGING_DB_NAME="senat_staging"
249
- ```
250
-
251
- ### Typical commands
252
-
253
- Default direct mode:
254
-
255
- ```bash
256
- npm run data:retrieve_open_data -- ../senat-data --all
257
- ```
258
-
259
- Incremental mode with separate staging database:
260
-
261
- ```bash
262
- npm run data:retrieve_open_data -- ../senat-data --all --incremental
263
- ```
264
-
265
- ### Target database prerequisites
266
-
267
- On `canutes`, the import role must be able to:
268
-
269
- - connect to the database
270
- - create the `postgres_fdw` extension, or reuse it if already installed
271
- - create and drop FDW servers and user mappings
272
- - create and drop temporary `*_staging` schemas used for foreign tables
273
- - create, alter and drop objects inside schema `senat`
274
-
275
- Typical one-time setup on the target database:
276
-
277
- ```sql
278
- CREATE EXTENSION IF NOT EXISTS postgres_fdw;
279
- ```
280
-
281
- ### Staging database prerequisites
282
-
283
- The staging PostgreSQL instance should ideally be outside the replicated cluster.
284
-
285
- The staging role must be able to:
286
-
287
- - recreate the `senat_staging` database
288
- - create schemas and import dumps there
289
- - create the technical staging indexes
290
-
291
- The target instance must also be allowed to connect to the staging instance over the network. In practice:
292
-
293
- - open the staging host and port from the target server
294
- - allow the staging user in `pg_hba.conf`
295
- - ensure the staging credentials used in `.env` are valid
296
-
297
- ### Operational note
298
-
299
- The replicated target still sees a small amount of temporary DDL for FDW objects, but the large dump imports and staging tables remain outside the replicated database. Most replicated volume should therefore come from the real incremental changes applied to `canutes.senat`.
300
-
301
- ## Validation of prefixed SQL imports
302
-
303
- After importing datasets with prefixed tables in schema `senat`, you can verify that the expected renamed tables exist and still match the generated definitions:
304
-
305
- ```bash
306
- npm run data:validate_prefixed_tables -- --categories All
307
- ```
308
-
309
- ## Publishing
310
-
311
- To publish a new version of this package onto npm, bump the package version and publish.
312
-
313
- ```bash
314
- # Increment version and create a new Git tag automatically
315
- npm version patch # +0.0.1 → small fixes
316
- npm version minor # +0.1.0 → new features
317
- npm version major # +1.0.0 → breaking changes
318
- npx tsc
319
- npm publish
320
- ```
321
-
322
- The Docker image will be automatically built during a CI Workflow if you push the tag to the remote repository.
323
-
324
- ```bash
325
- git push --tags
326
- ```
1
+ # Tricoteuses-Senat
2
+
3
+ ## _Retrieve, clean up & handle French Sénat's open data_
4
+
5
+ ## Requirements
6
+
7
+ - Node >= 22
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ git clone https://git.tricoteuses.fr/logiciels/tricoteuses-senat
13
+ cd tricoteuses-senat/
14
+ ```
15
+
16
+ Create a `.env` file to set PostgreSQL database informations and other configuration variables (you can use `example.env` as a template). Then
17
+
18
+ ```bash
19
+ npm install
20
+ ```
21
+
22
+ ### Database creation (not needed if downloading with Docker image)
23
+
24
+ #### Using Docker
25
+
26
+ ```bash
27
+ docker run --name local-postgres -d -p 5432:5432 -e POSTGRES_PASSWORD=$YOUR_CUSTOM_DB_PASSWORD postgres
28
+ ```
29
+
30
+ ## Download data
31
+
32
+ ### Basic usage
33
+
34
+ Create a folder where the data will be downloaded and run the following command to download the data and convert it into JSON files.
35
+
36
+ ```bash
37
+ mkdir ../senat-data/
38
+
39
+ npm run data:download ../senat-data
40
+ ```
41
+
42
+ ### Available Commands
43
+
44
+ - `npm run data:download <dir>`: Download, convert data to JSON
45
+ - `npm run data:retrieve_documents <dir>`: Retrieval of textes and rapports from Sénat's website
46
+ - `npm run data:retrieve_agenda <dir>`: Retrieval of agenda from Sénat's website
47
+ - `npm run data:retrieve_cr_seance <dir>`: Retrieval of comptes-rendus de séance from Sénat's data
48
+ - `npm run data:retrieve_cr_commission <dir>`: Retrieval of comptes-rendus de commissions from Sénat's website
49
+ - `npm run data:retrieve_senateurs_photos <dir>`: Retrieval of sénateurs' pictures from Sénat's website
50
+
51
+ ### Filtering Options
52
+
53
+ Downloading all the data is long and takes up a lot of disk space. It is possible to choose the type of data that you want to retrieve to reduce the load.
54
+
55
+ Examples:
56
+
57
+ ```bash
58
+ # Only download amendments
59
+ npm run data:download ../senat-data -- -k Ameli
60
+
61
+ # Only process data from session 2023 onwards
62
+ npm run data:download ../senat-data -- --fromSession 2023
63
+ ```
64
+
65
+ ### Common Options
66
+
67
+ - `--categories` or `-k <name>`: Filter by dataset categories (Available options: `All`, `Ameli`, `Debats`, `DosLeg`, `Questions`, `Sens`)
68
+ - `--fromSession <year>`: Specify the session year to retrieve data from (default: 2022)
69
+ - `--dataDir <path>` (Mandatory): Path to the working directory where all data is stored (required)
70
+ - `--silent` or `-s`: Disable logging
71
+ - `--verbose` or `-v`: Enable verbose logging
72
+ - `--commit` or `-c`: Automatically commit converted data
73
+ - `--pull` or `-p`: Pull repositories before starting
74
+ - `--clone` or `-C <url>`: Clone Git repositories from a remote group or organization
75
+ - `--remote` or `-r <name>`: Push commits to specified Git remote(s)
76
+ - `--keepDir`: Keep directories when cleaning data
77
+ - `--only-recent <days>`: Retrieve only documents created within the last N days
78
+
79
+ ### Options for Retrieving Documents
80
+
81
+ - `--formats <format>`: Specify document formats to retrieve (options: `xml`, `html`, `pdf`)
82
+ - `--types <type>`: Specify document types to retrieve (options: `textes`, `rapports`)
83
+ - `--parseDocuments`: Parse documents after retrieval
84
+ - `--parseAgenda`: Parse agenda after retrieval
85
+ - `--parseDebats`: Parse comptes-rendus after retrieval
86
+
87
+ #### Examples
88
+
89
+ ```bash
90
+ # Retrieval of textes and rapports in specific formats
91
+ npm run data:retrieve_documents ../senat-data -- --fromSession 2022 --formats xml pdf --types textes
92
+
93
+ # Retrieval & parsing (textes in xml format only for now)
94
+ npm run data:retrieve_documents ../senat-data -- --fromSession 2022 --parseDocuments
95
+
96
+ # Retrieval & parsing of agenda
97
+ npm run data:retrieve_agenda ../senat-data -- --fromSession 2022 --parseAgenda
98
+
99
+ # Retrieval & parsing of comptes-rendus de séance
100
+ npm run data:retrieve_cr_seance ../senat-data -- --parseDebats --keepDir
101
+
102
+ # Retrieval & parsing of comptes-rendus de commissions
103
+ npm run data:retrieve_cr_commission ../senat-data -- --parseDebats --keepDir
104
+ ```
105
+
106
+ ## Data download using Docker
107
+
108
+ A Docker image that downloads and converts the data all at once is available. Build it locally or run it from the container registry.
109
+ Use the environment variables `FROM_SESSION` and `CATEGORIES` if needed.
110
+
111
+ ```bash
112
+ docker run --pull always --name tricoteuses-senat -v ../senat-data:/app/senat-data -d git.tricoteuses.fr/logiciels/tricoteuses-senat:latest
113
+ ```
114
+
115
+ Use the environment variable `CATEGORIES` and `FROM_SESSION` if needed.
116
+
117
+ ## Using the data
118
+
119
+ Once the data is downloaded, you can use loaders to retrieve it.
120
+ To use loaders in your project, you can install the _@tricoteuses/senat_ package, and import the iterator functions that you need.
121
+
122
+ ```bash
123
+ npm install @tricoteuses/senat
124
+ ```
125
+
126
+ ```js
127
+ import { iterLoadSenatQuestions } from "@tricoteuses/senat/loaders"
128
+
129
+ // Pass data directory and legislature as arguments
130
+ for (const { item: question } of iterLoadSenatQuestions("../senat-data", 17)) {
131
+ console.log(question.id)
132
+ }
133
+ ```
134
+
135
+ ## Generation of raw types from SQL schema (for contributors only)
136
+
137
+ ```bash
138
+ npm run data:generate_schemas ../senat-data
139
+ ```
140
+
141
+ ## PostgreSQL import modes
142
+
143
+ `retrieve_open_data.ts` supports two import modes:
144
+
145
+ - default mode: direct import in a single database
146
+ - `--incremental`: separate staging database plus `postgres_fdw` bridge into the target database
147
+
148
+ The default mode is the simplest one and is the one used by the Docker image. The incremental mode is intended for replicated environments where heavy transient work should stay outside the target database.
149
+
150
+ ## Incremental PostgreSQL import architecture
151
+
152
+ When `--incremental` is enabled, the open-data SQL import is designed to keep heavy transient work out of the replicated target database.
153
+
154
+ ```text
155
+ +-----------------------------------+
156
+ | Source Open Data Senat |
157
+ | ZIP -> SQL dumps |
158
+ +----------------+------------------+
159
+ |
160
+ v
161
+ +-----------------------------------+
162
+ | PostgreSQL staging instance |
163
+ | non-replicated |
164
+ | database: senat_staging |
165
+ | |
166
+ | schemas: |
167
+ | - ameli_staging |
168
+ | - debats_staging |
169
+ | - dosleg_staging |
170
+ | - questions_staging |
171
+ | - sens_staging |
172
+ | |
173
+ | heavy operations: |
174
+ | - raw dump import |
175
+ | - table renaming/prefixing |
176
+ | - staging indexes |
177
+ +----------------+------------------+
178
+ |
179
+ postgres_fdw (read-only bridge)
180
+ |
181
+ v
182
+ +----------------------------------------------------------------------------+
183
+ | PostgreSQL target instance, replicated |
184
+ | database: canutes |
185
+ | |
186
+ | preserved schemas: assemblee, legifrance, ... |
187
+ | updated schema: senat |
188
+ | |
189
+ | lightweight temporary FDW schemas: |
190
+ | - ameli_staging |
191
+ | - debats_staging |
192
+ | - dosleg_staging |
193
+ | - questions_staging |
194
+ | - sens_staging |
195
+ | |
196
+ | final operations only: |
197
+ | - read staging data through postgres_fdw |
198
+ | - incremental merge into canutes.senat |
199
+ | - optional schema alignment when source structure changes |
200
+ +----------------------------------------------------------------------------+
201
+ ```
202
+
203
+ At the end of an incremental import:
204
+
205
+ - the target database is `canutes`
206
+ - the target schema is `senat`
207
+ - other schemas in `canutes` are left untouched
208
+ - bulk transient data stays in the staging database
209
+
210
+ ## Direct single-database mode
211
+
212
+ Without `--incremental`, the script works directly in the configured target database:
213
+
214
+ - dumps are imported into temporary `*_staging` schemas in that same database
215
+ - the final tables are merged into schema `senat`
216
+ - the temporary staging schemas are dropped at the end
217
+
218
+ This mode is appropriate for:
219
+
220
+ - local development
221
+ - disposable databases
222
+ - the Docker image workflow
223
+ - environments where replication cost is not a concern
224
+
225
+ ## Preparing postgres_fdw and database rights
226
+
227
+ This section only applies when using `--incremental`.
228
+
229
+ The target database must be able to connect to the separate staging database with `postgres_fdw`.
230
+
231
+ ### Environment variables
232
+
233
+ Set the target connection in `.env`. Add the staging connection only if you use `--incremental`:
234
+
235
+ ```bash
236
+ # Target database
237
+ DB_HOST="localhost"
238
+ DB_PORT=5432
239
+ DB_USER="postgres"
240
+ DB_PASSWORD="PASSWORD"
241
+ DB_NAME="canutes"
242
+
243
+ # Separate non-replicated staging database or instance, only for --incremental
244
+ STAGING_DB_HOST="localhost"
245
+ STAGING_DB_PORT=5433
246
+ STAGING_DB_USER="postgres"
247
+ STAGING_DB_PASSWORD="PASSWORD"
248
+ STAGING_DB_NAME="senat_staging"
249
+ ```
250
+
251
+ ### Typical commands
252
+
253
+ Default direct mode:
254
+
255
+ ```bash
256
+ npm run data:retrieve_open_data -- ../senat-data --all
257
+ ```
258
+
259
+ Incremental mode with separate staging database:
260
+
261
+ ```bash
262
+ npm run data:retrieve_open_data -- ../senat-data --all --incremental
263
+ ```
264
+
265
+ ### Target database prerequisites
266
+
267
+ On `canutes`, the import role must be able to:
268
+
269
+ - connect to the database
270
+ - create the `postgres_fdw` extension, or reuse it if already installed
271
+ - create and drop FDW servers and user mappings
272
+ - create and drop temporary `*_staging` schemas used for foreign tables
273
+ - create, alter and drop objects inside schema `senat`
274
+
275
+ Typical one-time setup on the target database:
276
+
277
+ ```sql
278
+ CREATE EXTENSION IF NOT EXISTS postgres_fdw;
279
+ ```
280
+
281
+ ### Staging database prerequisites
282
+
283
+ The staging PostgreSQL instance should ideally be outside the replicated cluster.
284
+
285
+ The staging role must be able to:
286
+
287
+ - recreate the `senat_staging` database
288
+ - create schemas and import dumps there
289
+ - create the technical staging indexes
290
+
291
+ The target instance must also be allowed to connect to the staging instance over the network. In practice:
292
+
293
+ - open the staging host and port from the target server
294
+ - allow the staging user in `pg_hba.conf`
295
+ - ensure the staging credentials used in `.env` are valid
296
+
297
+ ### Operational note
298
+
299
+ The replicated target still sees a small amount of temporary DDL for FDW objects, but the large dump imports and staging tables remain outside the replicated database. Most replicated volume should therefore come from the real incremental changes applied to `canutes.senat`.
300
+
301
+ ## Validation of prefixed SQL imports
302
+
303
+ After importing datasets with prefixed tables in schema `senat`, you can verify that the expected renamed tables exist and still match the generated definitions:
304
+
305
+ ```bash
306
+ npm run data:validate_prefixed_tables -- --categories All
307
+ ```
308
+
309
+ ## Publishing
310
+
311
+ To publish a new version of this package onto npm, bump the package version and publish.
312
+
313
+ ```bash
314
+ # Increment version and create a new Git tag automatically
315
+ npm version patch # +0.0.1 → small fixes
316
+ npm version minor # +0.1.0 → new features
317
+ npm version major # +1.0.0 → breaking changes
318
+ npx tsc
319
+ npm publish
320
+ ```
321
+
322
+ The Docker image will be automatically built during a CI Workflow if you push the tag to the remote repository.
323
+
324
+ ```bash
325
+ git push --tags
326
+ ```
@@ -0,0 +1,5 @@
1
+ export type CollaborateurSenat = {
2
+ civilite: string;
3
+ nom: string;
4
+ prenom: string;
5
+ };
@@ -0,0 +1,11 @@
1
+ export interface AgendaManifest {
2
+ date: string;
3
+ timestamp: string;
4
+ reunionUids: string[];
5
+ session: number;
6
+ }
7
+ export interface ManifestChanges {
8
+ new: string[];
9
+ deleted: string[];
10
+ kept: string[];
11
+ }