poad 2.31.1 → 2.32.0
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.
- package/global/start.js +8 -3
- package/package.json +2 -2
- package/project/migrate.js +2 -0
- package/utils/reference.js +63 -0
package/global/start.js
CHANGED
|
@@ -130,8 +130,9 @@ module.exports = async (args = {}) => {
|
|
|
130
130
|
...gelf.bindings,
|
|
131
131
|
},
|
|
132
132
|
// poad/migrations monté : la console y écrit les migrations qu'elle crée.
|
|
133
|
-
// poad/auth et poad/storage : manifestes versionnés des réglages d'auth et des buckets
|
|
134
|
-
|
|
133
|
+
// poad/auth et poad/storage : manifestes versionnés des réglages d'auth et des buckets.
|
|
134
|
+
// poad/reference : contenu des tables de référence, un fichier par table
|
|
135
|
+
Binds: [path.dirname(root) + '/data:/data', `${ensureDir(path.join(path.dirname(root), 'migrations'))}:/project/migrations`, `${ensureDir(path.join(path.dirname(root), 'credentials'))}:/project/credentials`, `${ensureDir(path.join(path.dirname(root), 'functions'))}:/project/functions`, `${ensureDir(path.join(path.dirname(root), 'variables'))}:/project/variables`, `${ensureDir(path.join(path.dirname(root), 'types'))}:/project/types`, `${ensureDir(path.join(path.dirname(root), 'flows'))}:/project/flows`, `${ensureDir(path.join(path.dirname(root), 'auth'))}:/project/auth`, `${ensureDir(path.join(path.dirname(root), 'storage'))}:/project/storage`, `${ensureDir(path.join(path.dirname(root), 'reference'))}:/project/reference`],
|
|
135
136
|
// Services lancés sur la machine : joignables depuis l'engine, y
|
|
136
137
|
// compris sous Linux
|
|
137
138
|
ExtraHosts: ['host.docker.internal:host-gateway'],
|
|
@@ -162,7 +163,10 @@ module.exports = async (args = {}) => {
|
|
|
162
163
|
const migrate = hasMigrations && (migrations.autoMigrate(config) || args.forceMigrate);
|
|
163
164
|
const seed = fresh && fsSync.existsSync(seedFile(root));
|
|
164
165
|
if (hasMigrations && !migrate) console.log(chalk.grey(' auto_migrate is off: run "poad migrate" to apply pending migrations.'));
|
|
165
|
-
|
|
166
|
+
// Tables de référence (poad/reference) : synchronisées après les migrations, avant le seed
|
|
167
|
+
const reference = require('../utils/reference');
|
|
168
|
+
const hasReference = reference.files(root).length > 0;
|
|
169
|
+
if (migrate || seed || hasReference) {
|
|
166
170
|
const waiting = ora(fresh ? 'Waiting for the new database' : 'Waiting for the database to apply migrations').start();
|
|
167
171
|
const ready = (await migrations.waitForDb(config)) && (await migrations.waitForServices(config));
|
|
168
172
|
if (!ready) {
|
|
@@ -173,6 +177,7 @@ module.exports = async (args = {}) => {
|
|
|
173
177
|
const migrated = migrate ? await require('../utils/migrate-run')(root, config, { quietWhenNone: false }) : true;
|
|
174
178
|
// Code de sortie 1 si une migration ou le seed échoue (scripts, CI)
|
|
175
179
|
if (!migrated) process.exitCode = 1;
|
|
180
|
+
if (hasReference && migrated && !(await reference.sync(root, config))) process.exitCode = 1;
|
|
176
181
|
if (seed && !migrated) console.log(chalk.yellowBright(' Seed skipped: a migration failed. Fix it, "poad migrate", then "poad db seed".'));
|
|
177
182
|
else if (seed && !migrations.autoMigrate(config) && !args.forceMigrate && hasMigrations) console.log(chalk.grey(' Seed skipped: migrations are manual here ("poad migrate" then "poad db seed").'));
|
|
178
183
|
else if (seed && !(await runSeed(root, config))) process.exitCode = 1;
|
package/package.json
CHANGED
package/project/migrate.js
CHANGED
|
@@ -13,4 +13,6 @@ module.exports = async () => {
|
|
|
13
13
|
}
|
|
14
14
|
const ok = await require('../utils/migrate-run')(root, config);
|
|
15
15
|
if (!ok) process.exitCode = 1;
|
|
16
|
+
// Tables de référence : après les migrations, quand leur structure est à jour
|
|
17
|
+
else if (!(await require('../utils/reference').sync(root, config))) process.exitCode = 1;
|
|
16
18
|
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Tables de référence : leur contenu fait partie du projet, un fichier par
|
|
2
|
+
// table dans poad/reference (<schéma>.<table>.jsonl). Le service meta de
|
|
3
|
+
// l'engine (0.24.0+) applique ces fichiers à la base ; le CLI le lui demande
|
|
4
|
+
// après les migrations, quand les tables existent.
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const path = require('path');
|
|
7
|
+
|
|
8
|
+
const dir = (root) => path.join(path.dirname(root), 'reference');
|
|
9
|
+
|
|
10
|
+
/** Fichiers de tables de référence du projet */
|
|
11
|
+
const files = (root) => {
|
|
12
|
+
try {
|
|
13
|
+
return fs.readdirSync(dir(root)).filter((f) => /^[^.]+\.[^.]+\.jsonl$/.test(f));
|
|
14
|
+
} catch {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Demande la synchronisation et l'affiche. Renvoie false si une table n'a pas
|
|
21
|
+
* pu être synchronisée ; true sinon (y compris sans table, ou avec un engine
|
|
22
|
+
* qui ne connaît pas encore les tables de référence).
|
|
23
|
+
*/
|
|
24
|
+
const sync = async (root, config) => {
|
|
25
|
+
const chalk = require('chalk-v2');
|
|
26
|
+
if (!files(root).length) return true;
|
|
27
|
+
let res;
|
|
28
|
+
try {
|
|
29
|
+
res = await fetch(`http://localhost:${config.web.port}/meta/v1/reference/sync`, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
headers: { apikey: config.auth.service, authorization: `Bearer ${config.auth.service}` },
|
|
32
|
+
signal: AbortSignal.timeout(120000),
|
|
33
|
+
});
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.log(chalk.redBright(`Reference tables not synchronized: ${err.message}`));
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
if (res.status === 404) {
|
|
39
|
+
console.log(chalk.yellowBright(` ${path.relative(process.cwd(), dir(root))} holds reference tables, but this engine (${config.engine}) does not know them yet: "poad upgrade".`));
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (!res.ok) {
|
|
43
|
+
console.log(chalk.redBright(`Reference tables not synchronized: the engine answered ${res.status}.`));
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const { tables = [] } = await res.json();
|
|
47
|
+
let ok = true;
|
|
48
|
+
for (const t of tables) {
|
|
49
|
+
const name = `${t.schema}.${t.name}`;
|
|
50
|
+
const changed = t.upserted || t.deleted;
|
|
51
|
+
if (t.problems.length) {
|
|
52
|
+
ok = false;
|
|
53
|
+
console.log(`${chalk.yellowBright('⚠')} ${chalk.bold(name)}`);
|
|
54
|
+
for (const p of t.problems) console.log(chalk.yellowBright(` ${p}`));
|
|
55
|
+
} else if (changed) {
|
|
56
|
+
console.log(`${chalk.greenBright('✔')} ${chalk.bold(name)} ${chalk.grey(`: ${t.rows} row(s), ${t.upserted} written, ${t.deleted} removed`)}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (ok && !tables.some((t) => t.upserted || t.deleted)) console.log(chalk.grey(` Reference tables up to date (${tables.length}).`));
|
|
60
|
+
return ok;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
module.exports = { dir, files, sync };
|