poad 2.76.0 → 2.76.2

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.
@@ -484,28 +484,30 @@ Object.assign(sheets, {
484
484
  notes: [EXIT_NOTE],
485
485
  },
486
486
  deploy: {
487
- usage: ['poad deploy [--env <name>] [--dry-run] [--yes] [--allow-destructive] [--json]'],
487
+ usage: ['poad deploy [--env <name>] [--dry-run] [--yes] [--allow-destructive] [--verbose] [--json]'],
488
488
  text: [
489
489
  '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.',
490
490
  '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.',
491
491
  ],
492
492
  options: [
493
493
  ['--env <name>', 'the environment (default: the current git branch if it exists on poad.io, else main)'],
494
- ['--dry-run', 'poad.io says what it would do (migrations to apply), nothing changes'],
494
+ ['--dry-run', 'poad.io says what it would do (migrations to apply, and for each large reference table: already loaded, to load or to send then load), nothing changes'],
495
495
  ['--yes', 'no question for production (required outside a terminal); does not accept a data loss'],
496
+ ['--verbose', 'also the SECURITY DEFINER functions used by RLS policies (normal: not callable directly by the API, no fix needed); --json always lists them (api_exposure.policy_functions)'],
496
497
  ['--allow-destructive', 'production: apply migrations that lose data without asking (required outside a terminal when they do); alias --accept-data-loss'],
497
498
  PROJECT_OPT,
498
499
  JSON_OPT,
499
500
  ],
500
501
  notes: [
501
502
  'Before applying, poad.io counts on the database of the environment what the pending migrations would lose (DROP TABLE, DROP COLUMN, ALTER COLUMN … TYPE, TRUNCATE, DELETE, DROP SCHEMA; RENAME and DROP VIEW / FUNCTION served by the API break clients): nothing is said when the target is created by the same deploy or is empty; otherwise file, statement and number of rows (data_loss in --json, --dry-run included). Production: a loss of data needs a confirmation in a terminal, or --allow-destructive; refused otherwise (exit code 4), nothing changed. Other environments: a warning.',
503
+ 'Large reference tables (poad/reference files over 20 MB, outside git): their state is read in the database of the environment (a mark set by the load, with the sha256 of the content and its number of rows): one line per table, "already loaded (N rows, sha256 …)", "to load (table empty | rows without the load mark | another version is loaded | N of M rows)" or "to send, then load". A volume recreated empty or a database reset loads them again (logs: poad logs deploy event=reference_state).',
502
504
  'Production (main): a summary, then a confirmation (none for --dry-run, which changes nothing). Uncommitted changes in poad/: a warning, and no commit id is sent (the commit id is sent when poad/ is clean).',
503
505
  EXIT_NOTE,
504
506
  ],
505
507
  },
506
508
  push: {
507
509
  usage: [
508
- 'poad push [--env <name>] [--dry-run] [--only code,base,auth,s3,refs | --skip …] [--tables a,b] [--with-secrets] [--yes] [--json]',
510
+ 'poad push [--env <name>] [--dry-run] [--only code,base,auth,s3,refs | --skip …] [--tables a,b] [--with-secrets] [--clean] [--yes] [--json]',
509
511
  'poad push --env main --yes --confirm <project id> (production, outside a terminal)',
510
512
  ],
511
513
  text: [
@@ -513,6 +515,8 @@ Object.assign(sheets, {
513
515
  'A preview always comes first, part by part and table by table: rows added (+), replaced (~), deleted (-) and identical, compared row by row with fingerprints of the primary key and of each row (never a value; above 200,000 rows a table is compared by counts only), sizes, room left on the target. An identical table is not rewritten.',
514
516
  'Base and auth go in ONE transaction, through the direct database access of poad.io (db.poad.io), run by the PostgreSQL tools of the local engine: the source is read in one consistent snapshot, the target is written with triggers and foreign keys paused during the load (nothing cascades), sequences are set as on the source; any error and nothing changes. Sessions and refresh tokens of the target are closed (accounts sign in again there), confirmation and recovery tokens are emptied. The structure must match first: a table missing or different on the target stops the base part before anything is written, and the code part (when chosen) runs first and is checked again after it.',
515
517
  'Secrets only with --with-secrets, after a confirmation of their own: the values of the variables of the engine and the credentials (fields, uses, vault values), except those of the storage, which each environment keeps. Values are never shown, written to a file or logged; keys of the engine, auth provider secrets and MCP tokens are never copied.',
518
+ 'Files: compared by name, size and checksum (MD5): what is already there is not sent again, a truncated or different object is. Above 6 MiB a file goes in resumable chunks (read from the source by ranges): an upload cut by the network, or by the end of the command, goes on from where the target is at the next run. The timeout is one of inactivity (an upload that moves is never cut); a passing error (network, timeout, 5xx, 429) is tried again after 1 s, 2 s, 4 s… and the number of transfers at once halves while errors come, then goes back up. Each file sent is read back on the target (size and checksum).',
519
+ 'Run again: poad push resumes. Code is deployed again (idempotent), identical tables and accounts are not rewritten (and production is not backed up again when the base has nothing to write), files already there are skipped. Failed files are summed up at the end (the first 5; all of them in --json and in the logs), with the command to run again; exit code 5.',
516
520
  ],
517
521
  options: [
518
522
  ['--env <name>', 'the environment (default: the current git branch if it exists on poad.io, else main)'],
@@ -521,6 +525,7 @@ Object.assign(sheets, {
521
525
  ['--skip <parts>', 'all parts but these'],
522
526
  ['--tables <a,b>', 'only these tables of the base part (table or schema.table)'],
523
527
  ['--with-secrets', 'also the values of variables and credentials (asks separately)'],
528
+ ['--clean', 'free the room first: the tables to rewrite are emptied (TRUNCATE, in a transaction of its own) and the files to replace removed before the copy; identical ones are kept. Not all or nothing any more: a failure leaves them empty until the next run'],
524
529
  ['--allow-destructive', 'passed to poad deploy (alias --accept-data-loss): migrations that lose data are applied on production without asking'],
525
530
  ['--yes', 'no question (required outside a terminal)'],
526
531
  ['--confirm <id>', 'production: the project id, typed in the command (outside a terminal: with --yes)'],
@@ -528,13 +533,14 @@ Object.assign(sheets, {
528
533
  JSON_OPT,
529
534
  ],
530
535
  notes: [
531
- 'Production (main): a backup of its database first (kept in its volume, 3 kept), a check of the room left (rows to write + 10 % + the journal of the database), and a strong confirmation: type the project id; outside a terminal, --yes --confirm <id>, else nothing changes.',
532
- 'The local project must be started (poad start). Logs, one line per part and per table (part, table, rows, bytes, duration_ms, outcome; never a value): poad logs cli event=project_push here, and in the logs of the environment on poad.io (poad logs --project … event=project_push).',
536
+ 'Production (main): a backup of its database first when the base is to be written (kept in its volume, 3 kept), and a strong confirmation: type the project id; outside a terminal, --yes --confirm <id>, else nothing changes.',
537
+ 'Room: what will be written (base: rows + 10 % + the journal of the database; files: their size) against the volume of the target, base and files told apart; files replaced or removed count as freed (removed first), tables only with --clean. A volume already over its size says "exceeded by"; not enough room stops before anything is written.',
538
+ 'The local project must be started (poad start). Logs, one line per part and per table (part, table, rows, bytes, duration_ms, outcome; never a value), and one per file that failed (file, reason: timeout, network, too_large, verify…, attempts) or resumed (offset): poad logs cli event=project_push here, and in the logs of the environment on poad.io (poad logs --project … event=project_push).',
533
539
  EXIT_NOTE.replace('5 deploy failed', '5 a part failed (the base part is all or nothing)'),
534
540
  ],
535
541
  },
536
542
  pull: {
537
- usage: ['poad pull [--env <name>] [--dry-run] [--only code,base,auth,s3,refs | --skip …] [--tables a,b] [--with-secrets] [--yes] [--json]'],
543
+ usage: ['poad pull [--env <name>] [--dry-run] [--only code,base,auth,s3,refs | --skip …] [--tables a,b] [--with-secrets] [--clean] [--yes] [--json]'],
538
544
  text: [
539
545
  'The other way of poad push: make the local project the mirror of an environment of poad.io, part by part: code (the migrations written there, by poad migration pull, then the deployed files of queries, auth, storage, functions, flows, api, reference, sources, transforms, connections, variables and seed.sql, then poad migrate), base, auth, refs (the reference tables of the store, loaded into the local engine), s3 (files of the storage).',
540
546
  'A local file is replaced or removed only when git tracks it without uncommitted change; otherwise it is kept and named (commit or stash it, then pull again). Migrations are never overwritten (a version used here under another name is a conflict, said and left alone).',
@@ -547,6 +553,7 @@ Object.assign(sheets, {
547
553
  ['--skip <parts>', 'all parts but these'],
548
554
  ['--tables <a,b>', 'only these tables of the base part'],
549
555
  ['--with-secrets', 'also the values of variables and credentials (asks separately)'],
556
+ ['--clean', 'free the room first (as for poad push)'],
550
557
  ['--yes', 'no question (required outside a terminal)'],
551
558
  PROJECT_OPT,
552
559
  JSON_OPT,
@@ -78,7 +78,7 @@ module.exports = async (root, config, { quietWhenNone = false, report = null, ex
78
78
  }
79
79
  // Fonctions et vues accordées à anon ou authenticated que l'API ne leur sert pas (SECURITY DEFINER, vues sans
80
80
  // security_invoker, vues matérialisées) : même règle que poad deploy et poad upgrade (utils/api-exposure)
81
- for (const l of require('./api-exposure').migrateLines(result.apiExposure, chalk, { full: exposureList || applied.length > 0 })) console.log(l);
81
+ for (const l of require('./api-exposure').migrateLines(result.apiExposure, chalk, { full: exposureList || applied.length > 0, verbose: process.argv.includes('--verbose') })) console.log(l);
82
82
  return qr.errors.length === 0;
83
83
  };
84
84
 
@@ -243,6 +243,59 @@ function fits(need, space) {
243
243
  return { known: true, ok: required <= free, required, free, reserve, limit: space.limit };
244
244
  }
245
245
 
246
+ /**
247
+ * --clean : vide d'abord, en une transaction à part, les tables à réécrire (TRUNCATE rend leur place tout de
248
+ * suite, contrairement à DELETE). Une table de la cible qui y renvoie par clé étrangère et n'est pas vidée
249
+ * fait échouer le tout : rien n'est vidé. Pure.
250
+ */
251
+ function truncateSql(tables = []) {
252
+ if (!tables.length) return 'select 1;';
253
+ return `set lock_timeout = '30s';\nbegin;\ntruncate table ${tables.map((t) => qname(t.schema, t.name)).join(', ')};\ncommit;`;
254
+ }
255
+
256
+ /**
257
+ * Place sur la cible de poad push / pull, parties ensemble. Pure.
258
+ * need { base, files } octets à écrire : lignes réécrites (base et comptes), fichiers envoyés
259
+ * freed { base, files } octets libérés avant ou pendant la copie : fichiers retirés ou remplacés (le
260
+ * Stockage retire leur contenu une minute après), tables vidées d'abord (--clean). Les lignes
261
+ * remplacées dans la transaction de la base ne libèrent rien avant la fin de celle-ci : 0 sans --clean.
262
+ * space { limit, used, storage?, reserve? } volume de la cible ; storage : la part des fichiers, si connue
263
+ * La base demande + 10 % et la réserve du journal ; les fichiers, leur taille. Jamais d'octets négatifs : un
264
+ * volume déjà rempli au-delà de sa taille se dit « dépassé de » (over).
265
+ */
266
+ function room({ need = {}, freed = {}, space } = {}) {
267
+ const pos = (v) => (Number.isFinite(Number(v)) && Number(v) > 0 ? Math.round(Number(v)) : 0);
268
+ const nb = pos(need.base);
269
+ const nf = pos(need.files);
270
+ const fb = pos(freed.base);
271
+ const ff = pos(freed.files);
272
+ const base = { need: { base: nb, files: nf }, freed: { base: fb, files: ff } };
273
+ if (!space || !Number.isFinite(Number(space.limit)) || !Number.isFinite(Number(space.used)) || Number(space.limit) <= 0) return { known: false, ok: true, ...base };
274
+ const limit = Number(space.limit);
275
+ const used = Math.max(0, Number(space.used));
276
+ const reserve = nb > 0 ? (space.reserve !== undefined ? pos(space.reserve) : walReserve(limit)) : 0;
277
+ const required = Math.ceil((nb * 11) / 10 + reserve + nf);
278
+ const left = limit - used;
279
+ const available = left + fb + ff;
280
+ const ok = required <= available;
281
+ const files = Number.isFinite(Number(space.storage)) && space.storage !== null ? Math.min(used, pos(space.storage)) : null;
282
+ return {
283
+ known: true,
284
+ ok,
285
+ ...base,
286
+ required,
287
+ reserve,
288
+ limit,
289
+ used,
290
+ used_files: files,
291
+ used_base: files === null ? null : used - files,
292
+ free: Math.max(0, left),
293
+ over: Math.max(0, -left),
294
+ available: Math.max(0, available),
295
+ missing: ok ? 0 : required - available,
296
+ };
297
+ }
298
+
246
299
  /**
247
300
  * Script bash du transfert des données (base et comptes), lancé dans le conteneur de l'engine local.
248
301
  * srcFn / dstFn commandes psql vers la source / la cible
@@ -424,6 +477,8 @@ module.exports = {
424
477
  changed,
425
478
  walReserve,
426
479
  fits,
480
+ room,
481
+ truncateSql,
427
482
  transferScript,
428
483
  sequencesSql,
429
484
  sequencesFor,