2026-04-01
This commit is contained in:
parent
ef19ba2b72
commit
5f332f4068
34 changed files with 9392 additions and 391 deletions
40
scripts/importe-dernier-export-bdd.ts
Normal file
40
scripts/importe-dernier-export-bdd.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { $ } from "bun";
|
||||
import { Array, Option, Order, pipe } from "effect";
|
||||
import { readdir } from "node:fs/promises";
|
||||
|
||||
const launchContainers = async (): Promise<string> => {
|
||||
return await $`podman compose up -d`.text();
|
||||
};
|
||||
|
||||
const getLatestDbExport = async (): Promise<string> => {
|
||||
return pipe(
|
||||
await readdir(`../db`),
|
||||
(paths: ReadonlyArray<string>) => Array.sort(paths, Order.string),
|
||||
(sortedPaths: ReadonlyArray<string>) => Array.last(sortedPaths),
|
||||
(last: Option.Option<string>) =>
|
||||
Option.getOrThrowWith(last, () => new Error("Aucun export de BDD n'est disponible.")),
|
||||
);
|
||||
};
|
||||
|
||||
const importLatestDbInWordpressContainer = async (exportPath: string) => {
|
||||
await $`podman exec -it haikuatelier.fr-wordpress fish -c "cd web && wp --allow-root db import ${exportPath}"`;
|
||||
};
|
||||
|
||||
try {
|
||||
// S'assure que les conteneurs soient lancées.
|
||||
await launchContainers();
|
||||
|
||||
const latestExportPath: string = `../db/${await getLatestDbExport()}`;
|
||||
console.log(`Dernier export : ${latestExportPath}`);
|
||||
|
||||
// Exécute l'opération d'import dans le conteneur WordPress via wp-cli.
|
||||
await importLatestDbInWordpressContainer(latestExportPath);
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof $.ShellError) {
|
||||
console.error(`Commande échouée avec code d'erreur: ${error.exitCode}`);
|
||||
console.log(error.stdout.toString());
|
||||
console.log(error.stderr.toString());
|
||||
} else {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue