poad 2.74.1 → 2.75.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poad",
3
- "version": "2.74.1",
3
+ "version": "2.75.0",
4
4
  "engine": "0.28.0",
5
5
  "runner": "0.5.0",
6
6
  "main": "index.js",
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 each a version after the last one:`)}`);
50
- for (const f of e.files || []) out.push(` ${chalk.cyanBright(`poad migrate renumber ${f.slice(0, 14)}${where}`)}`);
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
  }
@@ -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)
@@ -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
- for (const r of rows.filter((x) => x.state === 'out_of_order')) out.log(` ${chalk.cyanBright(`poad migrate renumber ${r.version}${where}`)} ${chalk.grey(`gives ${r.file} a version after the last one.`)}`);
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
- const m = local.find((l) => l.version === wanted || l.file === wanted);
110
- if (!m) throw api.usageError(`No migration "${wanted}" in ${cli.rel(migrations.dir(root))} (a version of 14 digits, or a file name).`);
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
- rows = await remoteList(api, id, b.name);
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
- const there = rows.find((r) => r.version === m.version);
125
- if (there && there.applied !== false) {
126
- throw new api.CloudError(`${m.file} is already applied on ${b.name}${there.applied_at ? ` (${when(there.applied_at)})` : ''}: its version stays. Nothing renamed.`, { code: 'already_applied', exit: api.EXIT.failed });
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
- const version = nextVersion(taken);
132
- const file = `${version}_${m.name}.sql`;
133
- const target = path.join(migrations.dir(root), file);
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
- const r = await client.query("select 1 from poad_migrations.history where version = $1 and to_regclass('poad_migrations.history') is not null", [m.version]).catch(() => ({ rows: [] }));
145
- localApplied = r.rows.length > 0;
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')} ${m.file} → ${chalk.cyanBright(file)}`);
152
- out.log(chalk.grey(` after the last migration of ${env.branch} and of the folder; applied on no environment of poad.io${localApplied ? '; the local history follows (applied on the local engine)' : ''}`));
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 (localApplied) {
157
- await client.query('begin');
158
- await client.query('update poad_migrations.history set version = $1 where version = $2', [version, m.version]);
159
- fs.renameSync(m.path, target);
160
- await client.query('commit').catch(async (err) => {
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
- await client
169
- .query("insert into _logs.entries (ts, level, service, msg, attrs) values (now(), 'info', 'cli', 'migration renumbered', $1::jsonb)", [JSON.stringify({ event: 'migration_renumbered', from: m.version, to: version, migration: `poad/migrations/${file}`, env: env.branch, local_history: localApplied })])
170
- .catch(() => {});
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
- if (client && localApplied) await client.query('rollback').catch(() => {});
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 it, then "poad deploy${env.source === 'option' || !env.production ? ` --env ${env.branch}` : ''}".`));
180
- out.result({ project: id, env: env.branch, from: m.file, to: file, version, local_history: localApplied });
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 };
@@ -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
  };
@@ -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 });
@@ -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 20261101000000 --env dev/);
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
+ });
@@ -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
+ });
@@ -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: {