core/source/logic/serialization/postgresql_dump.ts

105 lines
2.4 KiB
TypeScript

/*
This file is part of »mimir«.
Copyright 2025 kcf <fenris@folksprak.org>
»mimir« is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
»mimir« is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with »mimir«. If not, see <http://www.gnu.org/licenses/>.
*/
namespace _mimir.serialization.postgresql_dump
{
/**
*/
export type type_parameters = {
credentials : {
host : string;
port : int;
username : string;
password : string;
schema : string;
};
};
/**
*/
export function execute(
parameters : type_parameters,
directory : string
) : Array<string>
{
const result : Array<string> = [];
const password_file_path: string = "${HOME}/.pgpass";
result.push(
lib_plankton.string.coin(
"echo '{{host}}:{{port}}:{{schema}}:{{username}}:{{password}}' > {{path}} && chmod 0600 {{path}}",
{
"path": password_file_path,
"host": parameters.credentials.host,
"port": parameters.credentials.port.toFixed(0),
"username": parameters.credentials.username,
"password": parameters.credentials.password,
"schema": parameters.credentials.schema,
}
)
);
/*
result.push(
lib_plankton.string.coin(
"mkdir --parents {{directory}}",
{
"directory": directory
}
)
);
*/
result.push(
lib_plankton.string.coin(
"pg_dump --host={{host}} --port={{port}} --username={{username}} {{schema}} > {{target_path}}",
{
"host": parameters.credentials.host,
"port": parameters.credentials.port.toFixed(0),
"username": parameters.credentials.username,
"schema": parameters.credentials.schema,
"target_path": (directory + "/dump.sql"),
}
)
);
result.push(
lib_plankton.string.coin(
"rm {{path}}",
{
"path": password_file_path,
}
)
);
return result;
}
/**
*/
export function logic(
parameters : type_parameters
) : _mimir.serialization.type_logic
{
return {
"execute": (directory) => execute(parameters, directory),
};
}
}