poad 2.56.0 → 2.58.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/package.json +1 -1
- package/project/deploy.js +11 -7
- package/test/reference-store.test.js +38 -25
- package/utils/cloud/bundle.js +10 -2
- package/utils/help-details.js +1 -2
package/package.json
CHANGED
package/project/deploy.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
// poad deploy [--env <branche>] [--dry-run] [--
|
|
1
|
+
// poad deploy [--env <branche>] [--dry-run] [--yes] [--json]
|
|
2
2
|
//
|
|
3
3
|
// Envoie le dossier poad/ (liste blanche, sans aucun secret : utils/cloud/bundle.js)
|
|
4
4
|
// à l'environnement du projet poad.io lié :
|
|
5
5
|
// POST v1/projects/:id/branches/:branch/deploy (application/gzip)
|
|
6
6
|
// x-poad-sha commit git courant, si poad/ n'a aucun changement non commité
|
|
7
7
|
// x-poad-dry-run 1 avec --dry-run : le serveur dit ce qu'il ferait, rien ne change
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
// réponse : { deploy_id?, status?, migrations: { applied, pending, errors } }
|
|
8
|
+
// réponse : { deploy_id?, status?, migrations: { applied, pending, errors }, warnings }
|
|
9
|
+
// warnings : migrations qui perdent des données (drop table, truncate…), signalées, jamais refusées
|
|
11
10
|
// asynchrone (deploy_id et état non terminé) : GET …/deploys/:deploy_id jusqu'à la fin
|
|
12
11
|
//
|
|
13
12
|
// Production (main) : résumé puis confirmation, sauf --yes (obligatoire hors
|
|
@@ -34,6 +33,8 @@ function summarize(d = {}) {
|
|
|
34
33
|
dry_run: Boolean(d.dry_run),
|
|
35
34
|
migrations: { applied: names(m.applied), pending: names(m.pending), errors },
|
|
36
35
|
message: typeof d.message === 'string' ? d.message : null,
|
|
36
|
+
// Signalé, jamais bloquant : migrations qui perdent des données (drop table, truncate…)
|
|
37
|
+
warnings: (Array.isArray(d.warnings) ? d.warnings : []).map((w) => ({ message: String((w && w.message) || ''), files: Array.isArray(w && w.files) ? w.files.map(String) : [] })),
|
|
37
38
|
failed: errors.length > 0 || FAILED.includes(status),
|
|
38
39
|
};
|
|
39
40
|
}
|
|
@@ -70,7 +71,7 @@ module.exports = (args, raw) =>
|
|
|
70
71
|
// Tables de référence trop lourdes pour git : hors de l'archive, envoyées au magasin de références
|
|
71
72
|
const large = refStore.largeFiles(poadDir);
|
|
72
73
|
const ignored = refStore.ensureGitignore(poadDir, large);
|
|
73
|
-
|
|
74
|
+
// --allow-destructive : accepté, sans effet (poad.io signale les migrations qui perdent des données, sans refuser)
|
|
74
75
|
|
|
75
76
|
const env = await branches.resolve(id, { wanted: opts.env, root });
|
|
76
77
|
let b;
|
|
@@ -96,7 +97,7 @@ module.exports = (args, raw) =>
|
|
|
96
97
|
else if (git.empty) out.log(chalk.grey(' git repository without any commit yet: no commit id'));
|
|
97
98
|
else out.log(chalk.grey(' not in a git repository: no commit id'));
|
|
98
99
|
for (const s of b.skipped) if (!large.some((f) => f.rel === s.path)) out.log(chalk.grey(` skipped ${s.path}: ${s.reason}`));
|
|
99
|
-
for (const f of large) out.log(chalk.grey(` ${f.rel} (${kb(f.size)}): too large for git,
|
|
100
|
+
for (const f of large) out.log(chalk.grey(` ${f.rel} (${kb(f.size)}): too large for git: reference store, sent and loaded only if it changed (sha256)`));
|
|
100
101
|
for (const f of ignored.tracked) out.log(chalk.yellowBright(` ⚠ poad/${f.rel} is tracked by git although it is too large: git rm --cached poad/${f.rel}`));
|
|
101
102
|
|
|
102
103
|
if (env.production && !dryRun) {
|
|
@@ -107,7 +108,6 @@ module.exports = (args, raw) =>
|
|
|
107
108
|
const headers = {};
|
|
108
109
|
if (sha) headers['x-poad-sha'] = sha;
|
|
109
110
|
if (dryRun) headers['x-poad-dry-run'] = '1';
|
|
110
|
-
if (allowDestructive) headers['x-poad-allow-destructive'] = '1';
|
|
111
111
|
let result = summarize(await api.call('POST', `${route}/deploy`, { body: b.tgz, contentType: 'application/gzip', headers, what: 'deploy', timeout: 300000 }));
|
|
112
112
|
|
|
113
113
|
// Déploiement asynchrone : suivi jusqu'à son terme
|
|
@@ -133,6 +133,10 @@ module.exports = (args, raw) =>
|
|
|
133
133
|
// Refus pour migrations destructives : lesquelles, et comment confirmer
|
|
134
134
|
for (const f of e.files || []) out.log(` ${chalk.yellow(f)}`);
|
|
135
135
|
}
|
|
136
|
+
for (const w of result.warnings || []) {
|
|
137
|
+
out.log(` ${chalk.yellowBright('⚠')} ${w.message}`);
|
|
138
|
+
for (const f of w.files) out.log(` ${chalk.yellow(f)}`);
|
|
139
|
+
}
|
|
136
140
|
if (!m.applied.length && !m.pending.length && !m.errors.length) out.log(chalk.grey(' No migration to apply.'));
|
|
137
141
|
// Grosses références : après les migrations (les tables existent), envoi puis chargement
|
|
138
142
|
let references = null;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Grosses tables de référence : lecture JSON Lines, .gitignore, archive de deploy
|
|
2
|
+
const { describe, test } = require('node:test');
|
|
3
|
+
const assert = require('node:assert');
|
|
2
4
|
const fs = require('fs');
|
|
3
5
|
const os = require('os');
|
|
4
6
|
const path = require('path');
|
|
@@ -8,16 +10,19 @@ const bundle = require('../utils/cloud/bundle');
|
|
|
8
10
|
|
|
9
11
|
describe('JSON Lines (format de poad/reference)', () => {
|
|
10
12
|
test('valeurs : null, texte, nombre, booléen, GeoJSON, tableau PostgreSQL, JSON', () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
assert.strictEqual(jsonlValue(null), null);
|
|
14
|
+
assert.strictEqual(jsonlValue('a'), 'a');
|
|
15
|
+
assert.strictEqual(jsonlValue(1.5), '1.5');
|
|
16
|
+
assert.strictEqual(jsonlValue(true), 'true');
|
|
17
|
+
assert.strictEqual(jsonlValue({ type: 'Point', coordinates: [1, 2] }), 'SRID=4326;POINT(1 2)');
|
|
18
|
+
assert.strictEqual(
|
|
19
|
+
jsonlValue({ type: 'MultiPolygon', crs: { type: 'name', properties: { name: 'EPSG:2154' } }, coordinates: [[[[0, 0], [1, 0], [1, 1], [0, 0]]]] }),
|
|
20
|
+
'SRID=2154;MULTIPOLYGON(((0 0, 1 0, 1 1, 0 0)))',
|
|
21
|
+
);
|
|
22
|
+
assert.strictEqual(jsonlValue({ type: 'Feature', a: 1 }), '{"type":"Feature","a":1}');
|
|
23
|
+
assert.strictEqual(jsonlValue(['a', 'b"c', null]), '{"a","b\\"c",NULL}');
|
|
24
|
+
assert.strictEqual(jsonlValue([[1, 2], [3, 4]]), '{{"1","2"},{"3","4"}}');
|
|
25
|
+
assert.strictEqual(jsonlValue([{ a: 1 }]), '[{"a":1}]');
|
|
21
26
|
});
|
|
22
27
|
test('lignes coupées entre deux morceaux, colonnes de la première ligne', () => {
|
|
23
28
|
const rows = [];
|
|
@@ -25,13 +30,13 @@ describe('JSON Lines (format de poad/reference)', () => {
|
|
|
25
30
|
s.push('{"id":1,"nom":"Bourg"}\n{"id":2,');
|
|
26
31
|
s.push('"nom":null}\n{"id":3}');
|
|
27
32
|
s.end();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
assert.deepStrictEqual(rows.map((r) => r[2]), [['1', 'Bourg'], ['2', null], ['3', null]]);
|
|
34
|
+
assert.deepStrictEqual(rows[0][1], ['id', 'nom']);
|
|
35
|
+
assert.deepStrictEqual(rows.map((r) => r[2].map(copyEscape).join('\t')), ['1\tBourg', '2\t\\N', '3\t\\N']);
|
|
31
36
|
});
|
|
32
37
|
test('une colonne absente de la première ligne est refusée, avec sa ligne', () => {
|
|
33
38
|
const s = new JsonlSource({ target: 'public.t', onRow: () => {} });
|
|
34
|
-
|
|
39
|
+
assert.throws(() => s.push('{"id":1}\n{"id":2,"x":3}\n'), /column "x".*line 2/);
|
|
35
40
|
});
|
|
36
41
|
});
|
|
37
42
|
|
|
@@ -46,26 +51,34 @@ describe('grosses références : hors de git et de l’archive de deploy', () =>
|
|
|
46
51
|
};
|
|
47
52
|
test('repérées au-delà du seuil, .gitignore écrit (même texte que le service meta), puis retiré', () => {
|
|
48
53
|
const dir = project();
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
expect(large).toEqual([]);
|
|
54
|
+
assert.deepStrictEqual(store.largeFiles(dir, 5).map((f) => f.target), ['public.commune', 'public.petite']);
|
|
55
|
+
assert.deepStrictEqual(store.largeFiles(dir), []);
|
|
52
56
|
fs.truncateSync(path.join(dir, 'reference', 'public.commune.jsonl'), store.LARGE + 1);
|
|
53
57
|
const big = store.largeFiles(dir);
|
|
54
|
-
|
|
58
|
+
assert.deepStrictEqual(big.map((f) => f.rel), ['reference/public.commune.jsonl']);
|
|
55
59
|
store.ensureGitignore(dir, big);
|
|
56
|
-
|
|
60
|
+
assert.strictEqual(
|
|
61
|
+
fs.readFileSync(path.join(dir, 'reference', '.gitignore'), 'utf8'),
|
|
57
62
|
'# Écrit par poad : tables de référence trop lourdes pour git (plus de 20 Mo).\n# Elles restent sur ce poste ; poad deploy les envoie au magasin de références de poad.io.\n/public.commune.jsonl\n',
|
|
58
63
|
);
|
|
59
64
|
store.ensureGitignore(dir, []);
|
|
60
|
-
|
|
65
|
+
assert.strictEqual(fs.existsSync(path.join(dir, 'reference', '.gitignore')), false);
|
|
61
66
|
});
|
|
62
|
-
test('l’archive de deploy les laisse de côté au lieu d’échouer', () => {
|
|
67
|
+
test('l’archive de deploy les laisse de côté au lieu d’échouer, mais garde leur marquage', () => {
|
|
63
68
|
const dir = project();
|
|
64
69
|
fs.truncateSync(path.join(dir, 'reference', 'public.commune.jsonl'), store.LARGE + 1);
|
|
65
|
-
|
|
70
|
+
assert.throws(() => bundle.build(dir), /public\.commune\.jsonl is larger than 20 MB/);
|
|
66
71
|
const b = bundle.build(dir, { exclude: ['reference/public.commune.jsonl'] });
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
const paths = b.files.map((f) => f.path);
|
|
73
|
+
assert.ok(paths.includes('reference/public.petite.jsonl'));
|
|
74
|
+
assert.ok(!paths.includes('reference/public.commune.jsonl'));
|
|
75
|
+
assert.deepStrictEqual(
|
|
76
|
+
b.skipped.find((s) => s.path === 'reference/public.commune.jsonl'),
|
|
77
|
+
{ path: 'reference/public.commune.jsonl', reason: 'large reference table: sent to the reference store' },
|
|
78
|
+
);
|
|
79
|
+
// Le marquage voyage : un témoin léger, pour que l'engine déployé la sache référence
|
|
80
|
+
const witness = b.files.find((f) => f.path === 'reference/public.commune.store');
|
|
81
|
+
assert.ok(witness && witness.size < 100);
|
|
82
|
+
assert.deepStrictEqual(paths, [...paths].sort());
|
|
70
83
|
});
|
|
71
84
|
});
|
package/utils/cloud/bundle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Archive de déploiement : le dossier poad/ en tar.gz, par liste blanche.
|
|
2
2
|
//
|
|
3
3
|
// Entrent (chemins relatifs à poad/, sans préfixe) :
|
|
4
|
-
// dossiers migrations auth storage functions flows api reference variables types
|
|
4
|
+
// dossiers migrations queries auth storage functions flows api reference variables types
|
|
5
5
|
// credentials/manifest.json noms, types et usages des credentials, sans valeur
|
|
6
6
|
// (les valeurs restent dans le coffre de chaque engine)
|
|
7
7
|
// fichiers seed.sql, config.toml (sans aucune clé secrète : stripSecrets)
|
|
@@ -19,7 +19,7 @@ const fs = require('fs');
|
|
|
19
19
|
const path = require('path');
|
|
20
20
|
const zlib = require('zlib');
|
|
21
21
|
|
|
22
|
-
const DIRS = ['migrations', 'auth', 'storage', 'functions', 'flows', 'api', 'reference', 'variables', 'types'];
|
|
22
|
+
const DIRS = ['migrations', 'queries', 'auth', 'storage', 'functions', 'flows', 'api', 'reference', 'variables', 'types'];
|
|
23
23
|
const FILES = ['seed.sql', 'config.toml'];
|
|
24
24
|
const NEVER = [/^secrets\.toml$/i, /^\.env$/i, /^\.env\..*/i, /^\.DS_Store$/, /^Thumbs\.db$/i, /^desktop\.ini$/i, /~$/, /\.swp$/];
|
|
25
25
|
const SKIP_DIRS = new Set(['node_modules', '.git', 'data', 'backups', '.cache']);
|
|
@@ -204,6 +204,13 @@ function build(poadDir, { limits = LIMITS, exclude = [] } = {}) {
|
|
|
204
204
|
for (const rel of rels.sort()) {
|
|
205
205
|
if (left.has(rel)) {
|
|
206
206
|
skipped.push({ path: rel, reason: 'large reference table: sent to the reference store' });
|
|
207
|
+
// Le marquage voyage quand même : l'engine déployé sait que la table est une référence,
|
|
208
|
+
// dont le contenu vient du magasin (jamais d'une synchronisation depuis un fichier)
|
|
209
|
+
if (/^reference\/[^/]+\.jsonl$/.test(rel)) {
|
|
210
|
+
const data = Buffer.from(JSON.stringify({ store: true, bytes: fs.statSync(path.join(poadDir, ...rel.split('/'))).size }) + '\n');
|
|
211
|
+
total += data.length;
|
|
212
|
+
files.push({ path: rel.replace(/\.jsonl$/, '.store'), data, mode: 0o644 });
|
|
213
|
+
}
|
|
207
214
|
continue;
|
|
208
215
|
}
|
|
209
216
|
const abs = path.join(poadDir, ...rel.split('/'));
|
|
@@ -225,6 +232,7 @@ function build(poadDir, { limits = LIMITS, exclude = [] } = {}) {
|
|
|
225
232
|
if (total > limits.maxBytes) throw new BundleError(`the poad/ folder to send is larger than ${limits.maxBytes} bytes`);
|
|
226
233
|
files.push({ path: rel, data, mode: st.mode & 0o111 ? 0o755 : 0o644 });
|
|
227
234
|
}
|
|
235
|
+
files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
228
236
|
const tgz = zlib.gzipSync(tar(files), { level: 9 });
|
|
229
237
|
return { tgz, files: files.map((f) => ({ path: f.path, size: f.data.length })), skipped, bytes: total };
|
|
230
238
|
}
|
package/utils/help-details.js
CHANGED
|
@@ -255,7 +255,7 @@ Object.assign(sheets, {
|
|
|
255
255
|
notes: [EXIT_NOTE],
|
|
256
256
|
},
|
|
257
257
|
deploy: {
|
|
258
|
-
usage: ['poad deploy [--env <name>] [--dry-run] [--
|
|
258
|
+
usage: ['poad deploy [--env <name>] [--dry-run] [--yes] [--json]'],
|
|
259
259
|
text: [
|
|
260
260
|
'Send the poad/ folder to an environment of the linked poad.io project, which applies its pending migrations and loads its functions, flows, API, auth and storage settings.',
|
|
261
261
|
'Sent: migrations, auth, storage, functions, flows, api, reference, variables (defaults, no secret), types, credentials/manifest.json (names and types only, never values), seed.sql, config.toml (without any secret key). Never sent: poad/secrets.toml, .env files, data/, backups/, node_modules, symbolic links. If a value of poad/secrets.toml appears in a file to send, nothing is sent.',
|
|
@@ -263,7 +263,6 @@ Object.assign(sheets, {
|
|
|
263
263
|
options: [
|
|
264
264
|
['--env <name>', 'the environment (default: the current git branch if it exists on poad.io, else main)'],
|
|
265
265
|
['--dry-run', 'poad.io says what it would do (migrations to apply), nothing changes'],
|
|
266
|
-
['--allow-destructive', 'allow pending migrations that drop, truncate, delete or rename (refused otherwise, with the files named)'],
|
|
267
266
|
['--yes', 'no question for production (required outside a terminal)'],
|
|
268
267
|
PROJECT_OPT,
|
|
269
268
|
JSON_OPT,
|