poad 2.74.1 → 2.75.1
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/cli.js +1 -1
- package/project/deploy.js +5 -4
- package/project/logs.js +3 -1
- package/project/migrate-cloud.js +86 -43
- package/project/migration.js +1 -1
- package/project/ref/push.js +16 -2
- package/project/transform.js +22 -2
- package/test/cloud.test.js +51 -2
- package/test/reference-reload.test.js +113 -0
- package/test/transform.test.js +15 -0
- package/utils/cloud/api.js +4 -2
- package/utils/help-details.js +2 -1
- package/utils/reference-store.js +7 -0
package/package.json
CHANGED
package/project/cli.js
CHANGED
|
@@ -71,7 +71,7 @@ module.exports = {
|
|
|
71
71
|
types: 'TypeScript types of the database for createClient<Database>() (out=src/types/database.ts, role=authenticated|anon|service_role)',
|
|
72
72
|
env: 'TypeScript types of the public variables (PUBLIC_*) for poad.env (out=src/types/poad-env.ts)',
|
|
73
73
|
},
|
|
74
|
-
migrate: 'Apply pending migrations of poad/migrations and named queries of poad/queries (poad start does it too); migrate list | pull | renumber <version> [--env <name>]: the folder against poad.io',
|
|
74
|
+
migrate: 'Apply pending migrations of poad/migrations and named queries of poad/queries (poad start does it too); migrate list | pull | renumber <version> | --pending [--env <name>]: the folder against poad.io',
|
|
75
75
|
migration: 'Database migrations: migration new <name>, migration list [--env <name>], migration pull [--env <name>] (the migrations of poad.io missing from the folder)',
|
|
76
76
|
functions: 'Functions of the project (JS/TS, served on /functions/v1/<name>): new, list, types',
|
|
77
77
|
function: 'Alias of poad functions',
|
package/project/deploy.js
CHANGED
|
@@ -46,8 +46,9 @@ function refusalLines(e, { env, where, chalk }) {
|
|
|
46
46
|
out.push(` ${chalk.grey('Bring them back, commit them, then deploy again:')} ${chalk.cyanBright(`poad migration pull${where}`)}`);
|
|
47
47
|
}
|
|
48
48
|
if (e.code === 'migrations_out_of_order') {
|
|
49
|
-
out.push(` ${chalk.grey(`Pending here, but older than the last migration applied on ${env}: they would run in a different order than locally. Nothing is forced; give
|
|
50
|
-
|
|
49
|
+
out.push(` ${chalk.grey(`Pending here, but older than the last migration applied on ${env}: they would run in a different order than locally. Nothing is forced; give them versions after the last one, in their order, with one command:`)}`);
|
|
50
|
+
out.push(` ${chalk.cyanBright(`poad migrate renumber --pending${where}`)}`);
|
|
51
|
+
if ((e.files || []).length) out.push(` ${chalk.grey(`(${(e.files || []).join(', ')}; one at a time: poad migrate renumber <version>${where})`)}`);
|
|
51
52
|
}
|
|
52
53
|
return out;
|
|
53
54
|
}
|
|
@@ -147,7 +148,7 @@ module.exports = (args, raw) =>
|
|
|
147
148
|
if (b.deps && b.deps.packages.length) out.log(chalk.grey(` npm packages of the functions: ${b.deps.packages.join(', ')} (${b.deps.files} file(s) of poad/functions/node_modules)`));
|
|
148
149
|
for (const m of (b.deps && b.deps.missing) || []) out.log(chalk.yellowBright(` ⚠ ${m.from} imports "${m.spec}", not installed in poad/functions/node_modules: run "npm install ${m.spec}" in poad/functions, or this function will not build on poad.io.`));
|
|
149
150
|
if (b.deps && b.deps.outside.length) out.log(chalk.yellowBright(` ⚠ ${b.deps.outside.join(', ')}: installed above poad/functions, not sent. Install in poad/functions (npm install there).`));
|
|
150
|
-
for (const f of large) out.log(chalk.grey(` ${f.rel} (${kb(f.size)}): too large for git: reference store, sent
|
|
151
|
+
for (const f of large) out.log(chalk.grey(` ${f.rel} (${kb(f.size)}): too large for git: reference store, sent only if it changed (sha256), loaded if not yet loaded in ${env.branch}`));
|
|
151
152
|
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}`));
|
|
152
153
|
|
|
153
154
|
if (env.production && !dryRun) {
|
|
@@ -220,7 +221,7 @@ module.exports = (args, raw) =>
|
|
|
220
221
|
dry_run: dryRun,
|
|
221
222
|
// Ce qui lève un refus de migrations (poad migration pull, poad migrate renumber)
|
|
222
223
|
missing_migrations: result.migrations.errors.filter((e) => e.code === 'migrations_missing').flatMap((e) => (e.missing && e.missing.length ? e.missing : (e.versions || []).map((v) => ({ version: v, name: null, file: null, applied_at: null })))),
|
|
223
|
-
fix: result.migrations.errors.flatMap((e) => (e.code === 'migrations_missing' ? [`poad migration pull${where}`] : e.code === 'migrations_out_of_order' ? (e.files || []).map((f) => `poad migrate renumber ${f.slice(0, 14)}${where}`) : [])),
|
|
224
|
+
fix: result.migrations.errors.flatMap((e) => (e.code === 'migrations_missing' ? [`poad migration pull${where}`] : e.code === 'migrations_out_of_order' ? [`poad migrate renumber --pending${where}`, ...(e.files || []).map((f) => `poad migrate renumber ${f.slice(0, 14)}${where}`)] : [])),
|
|
224
225
|
large_references: large.map((f) => ({ path: `poad/${f.rel}`, bytes: f.size, target: f.target })),
|
|
225
226
|
references,
|
|
226
227
|
});
|
package/project/logs.js
CHANGED
|
@@ -37,7 +37,9 @@
|
|
|
37
37
|
// poad logs data event=sync_pull device=<id> synchronisation d'une table synchronisée (engine 0.70+) :
|
|
38
38
|
// sync_pull, sync_push (data), sync_purge (meta), avec table= et device=
|
|
39
39
|
// poad logs transform model=ventes les transformations (engine 0.72+) : passages, modèles construits ou en
|
|
40
|
-
// échec ; run=<id>, event=model_failed, trigger=deploy ; transform=<nom> = model=<nom>
|
|
40
|
+
// échec ; run=<id>, event=model_failed, trigger=deploy ; transform=<nom> = model=<nom> ;
|
|
41
|
+
// recalcul automatique (engine 0.73+) : trigger=source source=<nom>, trigger=cron,
|
|
42
|
+
// event=run_grouped (demandes réunies), event=schedule_tick
|
|
41
43
|
// poad logs limit=500 nombre de lignes (100 par défaut)
|
|
42
44
|
// poad logs -f | --follow suivi en direct
|
|
43
45
|
// poad logs --json une ligne JSON par entrée (pour jq)
|
package/project/migrate-cloud.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// ici (le prochain poad deploy l'applique), manquante ici (poad migration pull), en attente là-haut (écrite
|
|
4
4
|
// sans être appliquée), conflit de version, modifiée depuis son application, hors d'ordre.
|
|
5
5
|
//
|
|
6
|
-
// poad migrate renumber <version|fichier> [--env <nom>] [--yes] [--json]
|
|
6
|
+
// poad migrate renumber <version|fichier> | --pending [--env <nom>] [--yes] [--json]
|
|
7
|
+
// --pending : toutes les migrations en attente plus anciennes que la dernière appliquée sur l'environnement (et
|
|
8
|
+
// les suivantes en attente), d'un coup, dans leur ordre d'origine.
|
|
7
9
|
// donne à une migration en attente une version après la dernière de poad.io et du dossier (le fichier est
|
|
8
10
|
// renommé, son contenu ne change pas). Jamais une migration appliquée sur un environnement de poad.io ; si elle
|
|
9
11
|
// l'est sur l'engine local seulement, son historique local suit (même transaction que le renommage).
|
|
@@ -85,14 +87,27 @@ const list = (raw) =>
|
|
|
85
87
|
if (!rows.length) out.log(chalk.grey(' None, here or on poad.io.'));
|
|
86
88
|
out.log(' ');
|
|
87
89
|
if (count('missing') || count('remote_pending')) out.log(` ${chalk.cyanBright(`poad migration pull${where}`)} ${chalk.grey('brings the missing ones into the folder.')}`);
|
|
88
|
-
|
|
90
|
+
if (count('out_of_order')) out.log(` ${chalk.cyanBright(`poad migrate renumber --pending${where}`)} ${chalk.grey(`gives the ${count('out_of_order')} out-of-order one(s) versions after the last one, in their order.`)}`);
|
|
91
|
+
if (count('out_of_order') === 1) for (const r of rows.filter((x) => x.state === 'out_of_order')) out.log(` ${chalk.grey('or')} ${chalk.cyanBright(`poad migrate renumber ${r.version}${where}`)} ${chalk.grey(`for ${r.file} alone.`)}`);
|
|
89
92
|
if (count('pending') && !count('missing') && !count('out_of_order') && !count('conflict')) out.log(` ${chalk.cyanBright(`poad deploy${where}`)} ${chalk.grey(`applies the ${count('pending')} pending one(s).`)}`);
|
|
90
93
|
out.result({ project: id, env: env.branch, production: env.production, migrations: rows, counts: Object.fromEntries(Object.keys(LABEL).map((k) => [k, count(k)])) });
|
|
91
94
|
return 0;
|
|
92
95
|
});
|
|
93
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Migrations à renuméroter d'un coup (--pending) : les locales en attente plus anciennes que la dernière appliquée
|
|
99
|
+
* sur l'environnement, et les suivantes en attente, pour que l'ordre d'origine reste celui de poad.io. Pure.
|
|
100
|
+
*/
|
|
101
|
+
function pendingToRenumber(local = [], remote = []) {
|
|
102
|
+
const rows = compare(local, remote);
|
|
103
|
+
const first = rows.find((r) => r.state === 'out_of_order');
|
|
104
|
+
if (!first) return [];
|
|
105
|
+
const keep = new Set(rows.filter((r) => r.state === 'out_of_order' || (r.state === 'pending' && r.version > first.version)).map((r) => r.version));
|
|
106
|
+
return local.filter((l) => keep.has(l.version)).sort((a, b) => a.version.localeCompare(b.version));
|
|
107
|
+
}
|
|
108
|
+
|
|
94
109
|
const renumber = (raw) =>
|
|
95
|
-
require('../utils/cloud/cli').run(raw, { values: ['env', 'project'] }, async ({ opts, positionals, out }) => {
|
|
110
|
+
require('../utils/cloud/cli').run(raw, { values: ['env', 'project'], flags: ['pending'] }, async ({ opts, positionals, out }) => {
|
|
96
111
|
const fs = require('fs');
|
|
97
112
|
const path = require('path');
|
|
98
113
|
const api = require('../utils/cloud/api');
|
|
@@ -100,85 +115,113 @@ const renumber = (raw) =>
|
|
|
100
115
|
const branches = require('../utils/cloud/branches');
|
|
101
116
|
const migrations = require('../utils/migrations');
|
|
102
117
|
const { chalk } = out;
|
|
103
|
-
const usage = 'Usage: poad migrate renumber <version|file> [--env <name>] [--yes] [--json]';
|
|
104
|
-
if (positionals.length !== 1) throw api.usageError(usage);
|
|
118
|
+
const usage = 'Usage: poad migrate renumber <version|file> | --pending [--env <name>] [--yes] [--json]';
|
|
119
|
+
if (opts.pending ? positionals.length !== 0 : positionals.length !== 1) throw api.usageError(usage);
|
|
105
120
|
const root = cli.projectRoot();
|
|
106
121
|
if (!root) throw api.usageError('Not in a poad project folder: cd into one.');
|
|
107
|
-
const wanted = path.basename(positionals[0]);
|
|
108
122
|
const local = migrations.files(root).list;
|
|
109
|
-
|
|
110
|
-
if (!
|
|
123
|
+
let wantedList = null;
|
|
124
|
+
if (!opts.pending) {
|
|
125
|
+
const wanted = path.basename(positionals[0]);
|
|
126
|
+
const m = local.find((l) => l.version === wanted || l.file === wanted);
|
|
127
|
+
if (!m) throw api.usageError(`No migration "${wanted}" in ${cli.rel(migrations.dir(root))} (a version of 14 digits, or a file name).`);
|
|
128
|
+
wantedList = [m];
|
|
129
|
+
}
|
|
111
130
|
const { id } = cli.targetProject(opts);
|
|
112
131
|
const env = await branches.resolve(id, { wanted: opts.env, root });
|
|
132
|
+
const where = env.source === 'option' || !env.production ? ` --env ${env.branch}` : '';
|
|
113
133
|
|
|
114
134
|
// Appliquée nulle part sur poad.io : chaque environnement est lu ; un environnement illisible bloque
|
|
115
135
|
const all = await branches.list(id);
|
|
116
136
|
const taken = new Set(local.map((l) => l.version));
|
|
137
|
+
const remote = new Map();
|
|
117
138
|
for (const b of all) {
|
|
118
|
-
let rows;
|
|
119
139
|
try {
|
|
120
|
-
|
|
140
|
+
remote.set(b.name, await remoteList(api, id, b.name));
|
|
121
141
|
} catch (err) {
|
|
122
142
|
throw new api.CloudError(`Cannot read the migrations of ${b.name} (${err.message}): nothing renamed. A migration is renumbered only once poad.io confirms it is applied nowhere; resume ${b.name} or try again.`, { code: 'environment_unreadable' });
|
|
123
143
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
144
|
+
}
|
|
145
|
+
// Seulement la cible fixe la version : après tout ce qui y est appliqué ou écrit
|
|
146
|
+
for (const r of remote.get(env.branch) || []) taken.add(r.version);
|
|
147
|
+
const ms = wantedList || pendingToRenumber(local, remote.get(env.branch) || []);
|
|
148
|
+
if (!ms.length) {
|
|
149
|
+
out.log(chalk.grey(` No pending migration older than the last one applied on ${env.branch}: nothing to renumber.`));
|
|
150
|
+
out.result({ project: id, env: env.branch, renamed: [] });
|
|
151
|
+
return 0;
|
|
152
|
+
}
|
|
153
|
+
for (const m of ms) {
|
|
154
|
+
for (const [name, rows] of remote) {
|
|
155
|
+
const there = rows.find((r) => r.version === m.version);
|
|
156
|
+
if (there && there.applied !== false) {
|
|
157
|
+
throw new api.CloudError(`${m.file} is already applied on ${name}${there.applied_at ? ` (${when(there.applied_at)})` : ''}: its version stays. Nothing renamed.`, { code: 'already_applied', exit: api.EXIT.failed });
|
|
158
|
+
}
|
|
127
159
|
}
|
|
128
|
-
// Seulement la cible fixe la version : après tout ce qui y est appliqué ou écrit
|
|
129
|
-
if (b.name === env.branch) for (const r of rows) taken.add(r.version);
|
|
130
160
|
}
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
161
|
+
// Versions successives, dans l'ordre d'origine
|
|
162
|
+
const plan = ms.map((m) => {
|
|
163
|
+
const version = nextVersion(taken);
|
|
164
|
+
taken.add(version);
|
|
165
|
+
const file = `${version}_${m.name}.sql`;
|
|
166
|
+
return { m, version, file, target: path.join(migrations.dir(root), file), localApplied: false };
|
|
167
|
+
});
|
|
134
168
|
|
|
135
169
|
// Engine local : appliquée là seulement, son historique suit le fichier
|
|
136
170
|
let client = null;
|
|
137
|
-
let localApplied = false;
|
|
138
171
|
try {
|
|
139
172
|
const { readConfig } = require('../utils/config');
|
|
140
173
|
const { isDockerExist } = require('../utils/docker');
|
|
141
174
|
const config = readConfig(root);
|
|
142
175
|
if (await isDockerExist(config.project_uuid)) {
|
|
143
176
|
client = await migrations.connect(config);
|
|
144
|
-
|
|
145
|
-
|
|
177
|
+
for (const p of plan) {
|
|
178
|
+
const r = await client.query("select 1 from poad_migrations.history where version = $1 and to_regclass('poad_migrations.history') is not null", [p.m.version]).catch(() => ({ rows: [] }));
|
|
179
|
+
p.localApplied = r.rows.length > 0;
|
|
180
|
+
}
|
|
146
181
|
}
|
|
147
182
|
} catch {
|
|
148
183
|
client = null;
|
|
149
184
|
}
|
|
185
|
+
const anyLocal = plan.some((p) => p.localApplied);
|
|
150
186
|
|
|
151
|
-
out.log(` ${chalk.bold('Renumber')}
|
|
152
|
-
out.log(
|
|
187
|
+
out.log(` ${chalk.bold('Renumber')}${plan.length > 1 ? chalk.grey(` ${plan.length} migrations, in their original order`) : ''}`);
|
|
188
|
+
for (const p of plan) out.log(` ${p.m.file} → ${chalk.cyanBright(p.file)}${p.localApplied ? chalk.grey(' (local history follows)') : ''}`);
|
|
189
|
+
out.log(chalk.grey(` after the last migration of ${env.branch} and of the folder; applied on no environment of poad.io${anyLocal ? '; applied on the local engine: the local history follows' : ''}`));
|
|
190
|
+
const done = [];
|
|
153
191
|
try {
|
|
154
|
-
await cli.confirm(`Rename ${m.file} to ${file}?`, { yes: opts.yes, json: out.json });
|
|
155
|
-
if (fs.existsSync(target)) throw new api.CloudError(`${file} already exists: nothing renamed.`, { code: 'exists' });
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
await client.query('update poad_migrations.history set version = $1 where version = $2', [version, m.version]);
|
|
159
|
-
fs.renameSync(m.path, target);
|
|
160
|
-
|
|
161
|
-
fs.renameSync(target, m.path);
|
|
162
|
-
throw err;
|
|
163
|
-
});
|
|
164
|
-
} else {
|
|
165
|
-
fs.renameSync(m.path, target);
|
|
192
|
+
await cli.confirm(plan.length > 1 ? `Rename these ${plan.length} migrations?` : `Rename ${plan[0].m.file} to ${plan[0].file}?`, { yes: opts.yes, json: out.json });
|
|
193
|
+
for (const p of plan) if (fs.existsSync(p.target)) throw new api.CloudError(`${p.file} already exists: nothing renamed.`, { code: 'exists' });
|
|
194
|
+
if (anyLocal) await client.query('begin');
|
|
195
|
+
for (const p of plan) {
|
|
196
|
+
if (p.localApplied) await client.query('update poad_migrations.history set version = $1 where version = $2', [p.version, p.m.version]);
|
|
197
|
+
fs.renameSync(p.m.path, p.target);
|
|
198
|
+
done.push(p);
|
|
166
199
|
}
|
|
200
|
+
if (anyLocal) await client.query('commit');
|
|
167
201
|
if (client) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
202
|
+
for (const p of plan) {
|
|
203
|
+
await client
|
|
204
|
+
.query("insert into _logs.entries (ts, level, service, msg, attrs) values (now(), 'info', 'cli', 'migration renumbered', $1::jsonb)", [JSON.stringify({ event: 'migration_renumbered', from: p.m.version, to: p.version, migration: `poad/migrations/${p.file}`, env: env.branch, local_history: p.localApplied, pending: !!opts.pending })])
|
|
205
|
+
.catch(() => {});
|
|
206
|
+
}
|
|
171
207
|
}
|
|
172
208
|
} catch (err) {
|
|
173
|
-
|
|
209
|
+
for (const p of done.reverse()) {
|
|
210
|
+
try {
|
|
211
|
+
fs.renameSync(p.target, p.m.path);
|
|
212
|
+
} catch {}
|
|
213
|
+
}
|
|
214
|
+
if (client && anyLocal) await client.query('rollback').catch(() => {});
|
|
174
215
|
throw err;
|
|
175
216
|
} finally {
|
|
176
217
|
if (client) await client.end().catch(() => {});
|
|
177
218
|
}
|
|
178
|
-
out.log(`${chalk.greenBright('✔')} ${cli.rel(target)}`);
|
|
179
|
-
out.log(chalk.grey(` Commit
|
|
180
|
-
|
|
219
|
+
for (const p of plan) out.log(`${chalk.greenBright('✔')} ${cli.rel(p.target)}`);
|
|
220
|
+
out.log(chalk.grey(` Commit ${plan.length > 1 ? 'them' : 'it'}, then "poad deploy${where}".`));
|
|
221
|
+
const renamed = plan.map((p) => ({ from: p.m.file, to: p.file, version: p.version, local_history: p.localApplied }));
|
|
222
|
+
if (opts.pending) out.result({ project: id, env: env.branch, renamed });
|
|
223
|
+
else out.result({ project: id, env: env.branch, ...renamed[0] });
|
|
181
224
|
return 0;
|
|
182
225
|
});
|
|
183
226
|
|
|
184
|
-
module.exports = { list, renumber, compare, nextVersion, FILE_RE };
|
|
227
|
+
module.exports = { list, renumber, compare, nextVersion, pendingToRenumber, FILE_RE };
|
package/project/migration.js
CHANGED
|
@@ -63,5 +63,5 @@ module.exports = async (args = {}, raw = []) => {
|
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
console.log(`${chalk.bold(' Usage :')} ${chalk.cyanBright('poad migration new <name>')} | ${chalk.cyanBright('poad migration list [--env <name>]')} | ${chalk.cyanBright('poad migration pull [--env <name>]')} | ${chalk.cyanBright('poad migrate renumber <version>')} | ${chalk.cyanBright('poad migrate')}`);
|
|
66
|
+
console.log(`${chalk.bold(' Usage :')} ${chalk.cyanBright('poad migration new <name>')} | ${chalk.cyanBright('poad migration list [--env <name>]')} | ${chalk.cyanBright('poad migration pull [--env <name>]')} | ${chalk.cyanBright('poad migrate renumber <version> | --pending')} | ${chalk.cyanBright('poad migrate')}`);
|
|
67
67
|
};
|
package/project/ref/push.js
CHANGED
|
@@ -88,9 +88,21 @@ async function startAndWait(id, branch, targets, opts, out) {
|
|
|
88
88
|
try {
|
|
89
89
|
started = await api.call('POST', `v1/projects/${api.enc(id)}/seeds/load`, { body: { branch, targets }, what: 'reference load' });
|
|
90
90
|
} catch (e) {
|
|
91
|
-
|
|
91
|
+
// Place insuffisante, même table par table : rien n'est lancé ; chaque table dite (refusée, en attente)
|
|
92
|
+
if (e.code !== 'seed_no_space') throw e;
|
|
93
|
+
const d = e.details || {};
|
|
94
|
+
const tables = Array.isArray(d.tables) && d.tables.length ? d.tables : targets.map((t) => ({ target: t, status: 'refused' }));
|
|
95
|
+
out.log(`${chalk.redBright('✖')} Reference load refused on ${branch}: ${d.message || e.message}`);
|
|
96
|
+
for (const t of tables) {
|
|
97
|
+
if (t.status === 'refused') out.log(` ${chalk.redBright('✖')} ${t.target}: refused, not enough room${t.need ? ` (about ${S.fmt(t.need)} + 10 %)` : ''}`);
|
|
98
|
+
else out.log(` ${chalk.yellow('○')} ${t.target}: pending, not loaded`);
|
|
99
|
+
}
|
|
100
|
+
out.log(chalk.grey(' Nothing was loaded. The next "poad deploy" loads them once there is room (no need to send them again).'));
|
|
101
|
+
return { status: 'failed', refused: true, error: d.message || e.message, steps: tables.map((t) => ({ target: t.target, status: t.status === 'refused' ? 'failed' : 'skipped', reason: 'space' })), space: { required: d.required, free: d.free, limit: d.limit, margin: d.margin } };
|
|
92
102
|
}
|
|
93
|
-
|
|
103
|
+
const plan = started.plan || {};
|
|
104
|
+
if (plan.mode === 'stepwise') out.log(chalk.grey(` Loading into ${branch} table by table (${plan.order.length} tables, not enough room for all at once): ${plan.order.join(', ')}…`));
|
|
105
|
+
else out.log(chalk.grey(` Loading into ${branch} (${started.targets.length} table(s))…`));
|
|
94
106
|
const done = new Set();
|
|
95
107
|
const l = await S.waitLoad(id, started.load_id, {
|
|
96
108
|
onStep: (st) => {
|
|
@@ -105,6 +117,8 @@ async function startAndWait(id, branch, targets, opts, out) {
|
|
|
105
117
|
}
|
|
106
118
|
},
|
|
107
119
|
});
|
|
120
|
+
// Tables pas chargées (une précédente refusée ou en échec) : le prochain poad deploy les reprend
|
|
121
|
+
for (const s of l.steps || []) if (s.status === 'skipped' || s.status === 'pending') out.log(`${chalk.yellow('○')} ${s.target}: pending, not loaded into ${branch}; the next "poad deploy" loads it`);
|
|
108
122
|
if (l.status === 'failed') out.log(chalk.grey(' Nothing was half-loaded: each table is all or nothing.'));
|
|
109
123
|
return l;
|
|
110
124
|
}
|
package/project/transform.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// poad transform ls modèles (poad/transforms/<nom>.sql), état, dernier passage
|
|
1
|
+
// poad transform ls modèles (poad/transforms/<nom>.sql), état, dernier passage ; horaire
|
|
2
|
+
// (schedule:, fuseau), prochain passage, sources suivies (engine 0.73.0+)
|
|
2
3
|
// poad transform new <nom> [--table|--view] [--from <table>] crée poad/transforms/<nom>.sql avec un en-tête minimal
|
|
3
4
|
// poad transform check relit tous les modèles : en-têtes, requêtes, graphe, cycles ; ne change rien
|
|
4
5
|
// poad transform run [<sélecteur>…] [--changed] [--detach] lance un passage et le suit (tout par défaut) ;
|
|
@@ -52,6 +53,25 @@ const modelLines = (m, chalk) => {
|
|
|
52
53
|
else out.push(` ${chalk.redBright(r.status)} ${r.error ? `${r.error.message}${r.error.line ? chalk.grey(` (${m.file}:${r.error.line})`) : ''}` : ''}`);
|
|
53
54
|
if (m.stale && r && r.status === 'ok') out.push(chalk.yellowBright(' changed since its last build: poad transform run ' + m.name));
|
|
54
55
|
if (m.upstream && m.upstream.length) out.push(chalk.grey(` reads ${m.upstream.join(', ')}`));
|
|
56
|
+
for (const line of autoLines(m, chalk)) out.push(line);
|
|
57
|
+
return out;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/** Quand dire une échéance : « in 4 min », « in 3 h », « in 2 d ». Pure. */
|
|
61
|
+
const until = (iso, now = Date.now()) => {
|
|
62
|
+
const s = Math.max(0, Math.round((new Date(iso).getTime() - now) / 1000));
|
|
63
|
+
return s < 60 ? 'in less than a minute' : s < 3600 ? `in ${Math.round(s / 60)} min` : s < 86400 ? `in ${Math.round(s / 3600)} h` : `in ${Math.round(s / 86400)} d`;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Recalcul automatique d'un modèle (engine 0.73.0) : horaire et prochain passage, sources dont la synchronisation
|
|
68
|
+
* le recalcule. Rien pour un engine plus ancien (champs absents). Pure (chalk passé, now pour les tests).
|
|
69
|
+
*/
|
|
70
|
+
const autoLines = (m, chalk, now = Date.now()) => {
|
|
71
|
+
const out = [];
|
|
72
|
+
if (m.schedule) out.push(chalk.grey(` schedule ${m.schedule} (${m.timezone || 'UTC'})${m.next_run ? `, next run ${new Date(m.next_run).toLocaleString()} (${until(m.next_run, now)})` : ''}`));
|
|
73
|
+
if (m.after_sources === false) out.push(chalk.grey(' not recomputed after sources (after_sources: false)'));
|
|
74
|
+
else if (Array.isArray(m.sources) && m.sources.length) out.push(chalk.grey(` recomputed after source${m.sources.length > 1 ? 's' : ''} ${m.sources.join(', ')}`));
|
|
55
75
|
return out;
|
|
56
76
|
};
|
|
57
77
|
|
|
@@ -351,4 +371,4 @@ const main = async (args = {}, raw, deps = {}) => {
|
|
|
351
371
|
};
|
|
352
372
|
|
|
353
373
|
module.exports = (args, raw) => main(args, raw);
|
|
354
|
-
Object.assign(module.exports, { main, supportsTransforms, newModelText, modelLines, graphLines, runModelLine, NAME_RE, SELECTOR_RE });
|
|
374
|
+
Object.assign(module.exports, { main, supportsTransforms, newModelText, modelLines, graphLines, runModelLine, autoLines, until, NAME_RE, SELECTOR_RE });
|
package/test/cloud.test.js
CHANGED
|
@@ -678,9 +678,10 @@ test('deploy refusé (hors d’ordre) : la renumérotation proposée, rien de fo
|
|
|
678
678
|
await poad(box, cloud.api, ['link', PID]);
|
|
679
679
|
const r = await poad(box, cloud.api, ['deploy', '--env', 'dev', '--json']);
|
|
680
680
|
assert.strictEqual(r.status, 5, r.all);
|
|
681
|
-
assert.deepStrictEqual(jsonOf(r).fix, ['poad migrate renumber 20261101000000 --env dev']);
|
|
681
|
+
assert.deepStrictEqual(jsonOf(r).fix, ['poad migrate renumber --pending --env dev', 'poad migrate renumber 20261101000000 --env dev']);
|
|
682
682
|
const text = await poad(box, cloud.api, ['deploy', '--env', 'dev']);
|
|
683
|
-
assert.match(text.stdout, /poad migrate renumber
|
|
683
|
+
assert.match(text.stdout, /poad migrate renumber --pending --env dev/);
|
|
684
|
+
assert.ok(text.stdout.indexOf('renumber --pending') < text.stdout.indexOf('one at a time'), 'la commande unique en premier');
|
|
684
685
|
assert.ok(!cloud.requests.some((q) => q.headers['x-poad-force']), 'aucun forçage');
|
|
685
686
|
});
|
|
686
687
|
|
|
@@ -760,6 +761,7 @@ test('migrate list : dossier face à poad.io (appliquée, en attente, manquante,
|
|
|
760
761
|
assert.strictEqual(jsonOf(r).migrations.find((m) => m.version === '20261203101500').applied_at, '2026-12-03T10:15:00Z');
|
|
761
762
|
const text = await poad(box, cloud.api, ['migration', 'list', '--env', 'main']);
|
|
762
763
|
assert.match(text.stdout, /poad migration pull --env main/);
|
|
764
|
+
assert.match(text.stdout, /poad migrate renumber --pending --env main/);
|
|
763
765
|
assert.match(text.stdout, /poad migrate renumber 20261202000000 --env main/);
|
|
764
766
|
|
|
765
767
|
// Appliquée sur un environnement : jamais renumérotée
|
|
@@ -778,3 +780,50 @@ test('migrate list : dossier face à poad.io (appliquée, en attente, manquante,
|
|
|
778
780
|
const unknown = await poad(box, cloud.api, ['migrate', 'renumber', '20200101000000', '--yes']);
|
|
779
781
|
assert.strictEqual(unknown.status, 2, unknown.all);
|
|
780
782
|
});
|
|
783
|
+
|
|
784
|
+
test('migrate renumber --pending : toutes les hors d’ordre d’un coup, dans l’ordre d’origine, les suivantes en attente aussi', async (t) => {
|
|
785
|
+
const box = sandbox(t);
|
|
786
|
+
const cloud = await fakeCloud(t, { migrations: remoteMigrations() });
|
|
787
|
+
await login(box, cloud);
|
|
788
|
+
await poad(box, cloud.api, ['link', PID]);
|
|
789
|
+
const mdir = path.join(box.poad, 'migrations');
|
|
790
|
+
// Le dossier a déjà les migrations de poad.io (pull) ; trois locales écrites avant la dernière appliquée, une après
|
|
791
|
+
fs.writeFileSync(path.join(mdir, '20261203101500_ajoute_notes.sql'), NOTES_SQL);
|
|
792
|
+
fs.writeFileSync(path.join(mdir, '20261201000000_a.sql'), 'select 1;\n');
|
|
793
|
+
fs.writeFileSync(path.join(mdir, '20261202000000_b.sql'), 'select 2;\n');
|
|
794
|
+
fs.writeFileSync(path.join(mdir, '20261203000000_c.sql'), 'select 3;\n');
|
|
795
|
+
fs.writeFileSync(path.join(mdir, '20261204090000_d.sql'), 'select 4;\n');
|
|
796
|
+
|
|
797
|
+
const usage = await poad(box, cloud.api, ['migrate', 'renumber', '--pending', '20261201000000', '--yes']);
|
|
798
|
+
assert.strictEqual(usage.status, 2, usage.all);
|
|
799
|
+
const ask = await poad(box, cloud.api, ['migrate', 'renumber', '--pending']);
|
|
800
|
+
assert.strictEqual(ask.status, 4, ask.all);
|
|
801
|
+
assert.ok(fs.existsSync(path.join(mdir, '20261201000000_a.sql')), 'rien de renommé sans confirmation');
|
|
802
|
+
|
|
803
|
+
const r = await poad(box, cloud.api, ['migrate', 'renumber', '--pending', '--env', 'main', '--yes', '--json']);
|
|
804
|
+
assert.strictEqual(r.status, 0, r.all);
|
|
805
|
+
const o = jsonOf(r);
|
|
806
|
+
assert.deepStrictEqual(o.renamed.map((x) => x.from), ['20261201000000_a.sql', '20261202000000_b.sql', '20261203000000_c.sql', '20261204090000_d.sql']);
|
|
807
|
+
const v = o.renamed.map((x) => x.version);
|
|
808
|
+
assert.deepStrictEqual([...v].sort(), v, 'ordre d’origine gardé');
|
|
809
|
+
assert.strictEqual(new Set(v).size, 4);
|
|
810
|
+
assert.ok(v[0] > '20261204080000', `après la dernière de poad.io : ${v[0]}`);
|
|
811
|
+
assert.deepStrictEqual(o.renamed.map((x) => fs.readFileSync(path.join(mdir, x.to), 'utf8')), ['select 1;\n', 'select 2;\n', 'select 3;\n', 'select 4;\n']);
|
|
812
|
+
for (const f of ['20261201000000_a.sql', '20261202000000_b.sql', '20261203000000_c.sql', '20261204090000_d.sql']) assert.ok(!fs.existsSync(path.join(mdir, f)));
|
|
813
|
+
assert.ok(fs.existsSync(path.join(mdir, '20261101000000_init.sql')) && fs.existsSync(path.join(mdir, '20261203101500_ajoute_notes.sql')), 'les appliquées ne bougent pas');
|
|
814
|
+
|
|
815
|
+
const list = await poad(box, cloud.api, ['migrate', 'list', '--json']);
|
|
816
|
+
assert.strictEqual(jsonOf(list).counts.out_of_order, 0);
|
|
817
|
+
const again = await poad(box, cloud.api, ['migrate', 'renumber', '--pending', '--yes', '--json']);
|
|
818
|
+
assert.strictEqual(again.status, 0, again.all);
|
|
819
|
+
assert.deepStrictEqual(jsonOf(again).renamed, []);
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
test('pendingToRenumber : pure', () => {
|
|
823
|
+
const { pendingToRenumber } = require('../project/migrate-cloud');
|
|
824
|
+
const l = (v) => ({ version: v, name: 'm' + v.slice(-2), file: `${v}_m.sql` });
|
|
825
|
+
const remote = [{ version: '20261110000000', applied: true }];
|
|
826
|
+
assert.deepStrictEqual(pendingToRenumber([l('20261111000000')], remote), []);
|
|
827
|
+
assert.deepStrictEqual(pendingToRenumber([l('20261109000000'), l('20261101000000'), l('20261111000000')], remote).map((m) => m.version), ['20261101000000', '20261109000000', '20261111000000']);
|
|
828
|
+
assert.deepStrictEqual(pendingToRenumber([l('20261101000000')], []), []);
|
|
829
|
+
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// poad deploy et les grosses références : une table envoyée mais jamais chargée dans cet environnement
|
|
2
|
+
// est chargée au deploy suivant (sans renvoi) ; refus de place de poad.io dit table par table.
|
|
3
|
+
const { test } = require('node:test');
|
|
4
|
+
const assert = require('node:assert');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const api = require('../utils/cloud/api');
|
|
9
|
+
const store = require('../utils/reference-store');
|
|
10
|
+
|
|
11
|
+
const SHA = 'a'.repeat(64);
|
|
12
|
+
const chalk = new Proxy({}, { get: () => { const f = (s) => s; return new Proxy(f, { get: () => f }); } });
|
|
13
|
+
|
|
14
|
+
function project() {
|
|
15
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'poad-reload-'));
|
|
16
|
+
fs.mkdirSync(path.join(dir, 'reference'));
|
|
17
|
+
fs.writeFileSync(path.join(dir, 'reference', 'public.commune.jsonl'), '{"id":1}\n'.repeat(4));
|
|
18
|
+
const files = store.largeFiles(dir, 5);
|
|
19
|
+
// Déjà envoyée par un deploy précédent : la mémoire locale garde son empreinte
|
|
20
|
+
fs.mkdirSync(path.join(dir, 'data'));
|
|
21
|
+
const f = files[0];
|
|
22
|
+
fs.writeFileSync(path.join(dir, 'data', 'reference-store.json'), JSON.stringify({ [f.file]: { size: f.size, mtimeMs: f.mtimeMs, sha256: SHA, target: f.target } }));
|
|
23
|
+
return { dir, files };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function fakeApi(t, routes) {
|
|
27
|
+
const calls = [];
|
|
28
|
+
const orig = api.call;
|
|
29
|
+
api.call = async (method, route, o = {}) => {
|
|
30
|
+
calls.push([method, route, o.body]);
|
|
31
|
+
for (const [re, fn] of routes) if (re.test(`${method} ${route}`)) return fn(o);
|
|
32
|
+
throw new Error(`route inattendue ${method} ${route}`);
|
|
33
|
+
};
|
|
34
|
+
t.after(() => (api.call = orig));
|
|
35
|
+
return calls;
|
|
36
|
+
}
|
|
37
|
+
const output = () => {
|
|
38
|
+
const lines = [];
|
|
39
|
+
return { lines, out: { chalk, json: false, log: (l) => lines.push(String(l)) } };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
test('envoyée, jamais chargée dans cet environnement → chargée au deploy suivant, sans renvoi', async (t) => {
|
|
43
|
+
const { dir, files } = project();
|
|
44
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
45
|
+
let polls = 0;
|
|
46
|
+
const calls = fakeApi(t, [
|
|
47
|
+
[/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: { dev: { 'public.commune': { sha256: SHA } } } })],
|
|
48
|
+
[/^POST .*\/seeds\/load$/, () => ({ load_id: 'l1', targets: ['public.commune'], plan: { mode: 'together', order: ['public.commune'] } })],
|
|
49
|
+
[/^GET .*\/seeds\/loads\/l1$/, () => (++polls < 2 ? { status: 'running', steps: [{ target: 'public.commune', status: 'running' }] } : { status: 'done', steps: [{ target: 'public.commune', status: 'done', written: 4, deleted: 0, duration_ms: 1200 }] })],
|
|
50
|
+
]);
|
|
51
|
+
const { lines, out } = output();
|
|
52
|
+
// Chargée en dev, pas en main : main la charge
|
|
53
|
+
const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
|
|
54
|
+
assert.strictEqual(r.failed, false);
|
|
55
|
+
assert.deepStrictEqual(r.tables.map((x) => [x.target, x.action, x.state]), [['public.commune', 'load', 'loaded']]);
|
|
56
|
+
assert.ok(!calls.some(([, route]) => /seeds\/upload/.test(route)), 'rien renvoyé');
|
|
57
|
+
assert.deepStrictEqual(calls.find(([, route]) => /seeds\/load$/.test(route))[2], { branch: 'main', targets: ['public.commune'] });
|
|
58
|
+
assert.ok(lines.some((l) => /public\.commune loaded into main: 4 rows/.test(l)), lines.join('\n'));
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('déjà chargée dans cet environnement : ni envoi ni chargement', async (t) => {
|
|
62
|
+
const { dir, files } = project();
|
|
63
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
64
|
+
const calls = fakeApi(t, [[/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: { main: { 'public.commune': { sha256: SHA } } } })]]);
|
|
65
|
+
const { out } = output();
|
|
66
|
+
const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
|
|
67
|
+
assert.deepStrictEqual(r.tables.map((x) => [x.action, x.state]), [['unchanged', 'loaded']]);
|
|
68
|
+
assert.strictEqual(calls.length, 1);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('poad.io refuse faute de place (aucun ordre ne tient) : chaque table dite, deploy en échec, rien lancé', async (t) => {
|
|
72
|
+
const { dir, files } = project();
|
|
73
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
74
|
+
const message = 'place insuffisante, même table par table : public.commune demande à elle seule environ 700.0 Mio, + 10 % de marge = 770.0 Mio, plus 256.0 Mio pour le journal (il manquerait 76.3 Mio). Pour passer : poad ref inspect public.commune, --exclude, ou une offre plus grande.';
|
|
75
|
+
fakeApi(t, [
|
|
76
|
+
[/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: {} })],
|
|
77
|
+
[/^POST .*\/seeds\/load$/, () => {
|
|
78
|
+
throw new api.CloudError(`reference load: ${message} (seed_no_space)`, { status: 413, code: 'seed_no_space', details: { code: 'seed_no_space', message, margin: 1.1, required: 1100, free: 1000, limit: 1024, tables: [{ target: 'public.commune', need: 734003200, status: 'refused' }, { target: 'public.region', need: 1, status: 'pending' }] } });
|
|
79
|
+
}],
|
|
80
|
+
]);
|
|
81
|
+
const { lines, out } = output();
|
|
82
|
+
const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
|
|
83
|
+
assert.strictEqual(r.failed, true);
|
|
84
|
+
assert.deepStrictEqual(r.tables.map((x) => [x.target, x.state]), [['public.commune', 'refused']]);
|
|
85
|
+
const text = lines.join('\n');
|
|
86
|
+
assert.match(text, /Reference load refused on main: place insuffisante/);
|
|
87
|
+
assert.match(text, /public\.commune: refused, not enough room \(about 700\.0 M/);
|
|
88
|
+
assert.match(text, /public\.region: pending, not loaded/);
|
|
89
|
+
assert.match(text, /next "poad deploy" loads them/);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('chargement table par table : annoncé, puis une table refusée en cours et la suivante en attente', async (t) => {
|
|
93
|
+
const { dir, files } = project();
|
|
94
|
+
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
|
|
95
|
+
fakeApi(t, [
|
|
96
|
+
[/^GET .*\/seeds$/, () => ({ store: true, items: [{ target: 'public.commune', sha256: SHA }], applied: {} })],
|
|
97
|
+
[/^POST .*\/seeds\/load$/, () => ({ load_id: 'l2', targets: ['public.commune'], plan: { mode: 'stepwise', order: ['public.a', 'public.commune', 'public.c'] } })],
|
|
98
|
+
[/^GET .*\/seeds\/loads\/l2$/, () => ({ status: 'failed', steps: [
|
|
99
|
+
{ target: 'public.a', status: 'done', written: 1, deleted: 0, duration_ms: 10, warnings: ['place restante faible sur l’engine main : 200.0 Mio libres sur 1.00 Gio (20 %)'] },
|
|
100
|
+
{ target: 'public.commune', status: 'failed', reason: 'space', error: 'refusée : place insuffisante pour cette table…' },
|
|
101
|
+
{ target: 'public.c', status: 'skipped', error: 'en attente' },
|
|
102
|
+
] })],
|
|
103
|
+
]);
|
|
104
|
+
const { lines, out } = output();
|
|
105
|
+
const r = await store.sendAndLoad('abcdefghijkl', 'main', dir, files, {}, out);
|
|
106
|
+
assert.strictEqual(r.failed, true);
|
|
107
|
+
assert.deepStrictEqual(r.tables.map((x) => x.state), ['refused']);
|
|
108
|
+
const text = lines.join('\n');
|
|
109
|
+
assert.match(text, /table by table \(3 tables, not enough room for all at once\): public\.a, public\.commune, public\.c/);
|
|
110
|
+
assert.match(text, /⚠ place restante faible/);
|
|
111
|
+
assert.match(text, /public\.commune: refusée : place insuffisante/);
|
|
112
|
+
assert.match(text, /public\.c: pending, not loaded into main; the next "poad deploy" loads it/);
|
|
113
|
+
});
|
package/test/transform.test.js
CHANGED
|
@@ -175,3 +175,18 @@ test('poad start : un dossier sans .sql ne demande rien à l’engine', (t) => {
|
|
|
175
175
|
fs.writeFileSync(path.join(poadDir, 'transforms', 'a.sql'), 'select 1');
|
|
176
176
|
assert.strictEqual(hasModels(root), true);
|
|
177
177
|
});
|
|
178
|
+
|
|
179
|
+
test('ls : horaire, prochain passage, sources suivies (engine 0.73)', () => {
|
|
180
|
+
const chalk = { bold: (x) => x, grey: (x) => x, greenBright: (x) => x, redBright: (x) => x, yellowBright: (x) => x, cyan: (x) => x };
|
|
181
|
+
const now = Date.parse('2026-12-04T10:00:00Z');
|
|
182
|
+
const lines = transform.autoLines({ schedule: '*/5 * * * *', timezone: 'Europe/Paris', next_run: '2026-12-04T10:05:00Z', after_sources: true, sources: ['commandes'] }, chalk, now);
|
|
183
|
+
assert.match(lines[0], /^ {2}schedule \*\/5 \* \* \* \* \(Europe\/Paris\), next run .* \(in 5 min\)$/);
|
|
184
|
+
assert.strictEqual(lines[1], ' recomputed after source commandes');
|
|
185
|
+
assert.deepStrictEqual(transform.autoLines({ schedule: null, after_sources: false, sources: [] }, chalk, now), [' not recomputed after sources (after_sources: false)']);
|
|
186
|
+
// engine 0.72 : rien
|
|
187
|
+
assert.deepStrictEqual(transform.autoLines({ name: 'x' }, chalk, now), []);
|
|
188
|
+
assert.strictEqual(transform.until('2026-12-04T13:00:00Z', now), 'in 3 h');
|
|
189
|
+
// dans la sortie de ls
|
|
190
|
+
const m = { ...LIST.models[0], schedule: '0 4 * * *', timezone: 'UTC', next_run: '2026-12-05T04:00:00Z', sources: ['commandes', 'magasins'] };
|
|
191
|
+
assert.ok(transform.modelLines(m, chalk).some((l) => l.includes('recomputed after sources commandes, magasins')));
|
|
192
|
+
});
|
package/utils/cloud/api.js
CHANGED
|
@@ -14,10 +14,12 @@ const DEFAULT_API = 'https://poad.io/_poad/cloud';
|
|
|
14
14
|
const EXIT = { ok: 0, error: 1, usage: 2, auth: 3, confirm: 4, failed: 5 };
|
|
15
15
|
|
|
16
16
|
class CloudError extends Error {
|
|
17
|
-
constructor(message, { status = 0, code = 'error', exit } = {}) {
|
|
17
|
+
constructor(message, { status = 0, code = 'error', exit, details } = {}) {
|
|
18
18
|
super(message);
|
|
19
19
|
this.status = status;
|
|
20
20
|
this.code = code;
|
|
21
|
+
// Champs du refus rendus par poad.io (tailles, tables…), jamais de secret
|
|
22
|
+
if (details) this.details = details;
|
|
21
23
|
this.exit = exit || (status === 401 || code === 'not_logged_in' ? EXIT.auth : EXIT.error);
|
|
22
24
|
}
|
|
23
25
|
}
|
|
@@ -104,7 +106,7 @@ function errorOf(res, what) {
|
|
|
104
106
|
const message = typeof e.message === 'string' && e.message ? e.message : `HTTP ${res.status}`;
|
|
105
107
|
if (res.status === 401) return new CloudError(`poad.io refused the session (${message}): run "poad login".`, { status: 401, code });
|
|
106
108
|
if (res.status === 404) return new CloudError(`${what ? `${what}: ` : ''}not found (${message}).`, { status: 404, code });
|
|
107
|
-
return new CloudError(`${what ? `${what}: ` : ''}${message}${code && !message.includes(code) ? ` (${code})` : ''}`, { status: res.status, code });
|
|
109
|
+
return new CloudError(`${what ? `${what}: ` : ''}${message}${code && !message.includes(code) ? ` (${code})` : ''}`, { status: res.status, code, details: e });
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
/** Appel authentifié : la réponse JSON, ou CloudError */
|
package/utils/help-details.js
CHANGED
|
@@ -328,7 +328,7 @@ const sheets = {
|
|
|
328
328
|
],
|
|
329
329
|
},
|
|
330
330
|
migrate: {
|
|
331
|
-
usage: ['poad migrate', 'poad migrate --force-reference', 'poad migrate --json', 'poad migrate list [--env <name>] [--json]', 'poad migrate pull [--env <name>] [--yes] [--dry-run] [--json]', 'poad migrate renumber <version|file> [--env <name>] [--yes] [--json]'],
|
|
331
|
+
usage: ['poad migrate', 'poad migrate --force-reference', 'poad migrate --json', 'poad migrate list [--env <name>] [--json]', 'poad migrate pull [--env <name>] [--yes] [--dry-run] [--json]', 'poad migrate renumber <version|file> [--env <name>] [--yes] [--json]', 'poad migrate renumber --pending [--env <name>] [--yes] [--json]'],
|
|
332
332
|
text: [
|
|
333
333
|
'Apply pending migrations of poad/migrations and named queries of poad/queries, then the reference tables of poad/reference (the file is the source of truth).',
|
|
334
334
|
'Then warns (never blocks) about functions and views granted to anon or authenticated that the API does not serve them (403 not_exposed: SECURITY DEFINER functions, views without security_invoker, materialized views), each with its fix; the ones a migration just created also go to the log sink (poad logs cli event=api_exposure).',
|
|
@@ -339,6 +339,7 @@ const sheets = {
|
|
|
339
339
|
['list', 'poad/migrations against an environment of poad.io (--env, else the git branch, else main; the local engine when the project is not linked): applied on both sides, pending here, missing here, written on poad.io without being applied, same version under another name, changed since applied, older than the last one applied (poad deploy refuses it); with version, name and date'],
|
|
340
340
|
['pull', 'same as poad migration pull'],
|
|
341
341
|
['renumber <version>', 'give a pending migration a version after the last one of the environment and of the folder (the file is renamed, its SQL is unchanged) when poad deploy refuses it as out of order. Refused when it is applied on any environment of poad.io; applied on the local engine only: the local history follows. Logs: poad logs cli event=migration_renumbered'],
|
|
342
|
+
['renumber --pending', 'renumber at once, in their original order, every pending migration older than the last one applied on the environment (and the pending ones after it, so the order stays): what poad deploy proposes first when it refuses the order'],
|
|
342
343
|
],
|
|
343
344
|
},
|
|
344
345
|
migration: {
|
package/utils/reference-store.js
CHANGED
|
@@ -152,6 +152,13 @@ async function sendAndLoad(id, branch, poadDir, files, opts, out) {
|
|
|
152
152
|
}
|
|
153
153
|
let load = null;
|
|
154
154
|
if (toLoad.length) load = await startAndWait(id, branch, toLoad, opts, out);
|
|
155
|
+
// État de chaque table dans cet environnement : loaded, pending (pas encore chargée), refused (place), failed
|
|
156
|
+
for (const t of tables) {
|
|
157
|
+
const st = load && (load.steps || []).find((x) => x.target === t.target);
|
|
158
|
+
if (t.action === 'unchanged') t.state = 'loaded';
|
|
159
|
+
else if (st) t.state = st.status === 'done' ? 'loaded' : st.status === 'failed' ? (st.reason === 'space' ? 'refused' : 'failed') : 'pending';
|
|
160
|
+
else t.state = 'pending';
|
|
161
|
+
}
|
|
155
162
|
return { tables, load, failed: Boolean(load && load.status === 'failed') };
|
|
156
163
|
}
|
|
157
164
|
|