fix url
Deploy db-migrations / db-migrations (push) Successful in 36s

This commit is contained in:
2024-12-03 17:32:50 +02:00
parent ad4dc437cf
commit 4210436ca2
@@ -40,32 +40,49 @@ const dbsSecurity = {
}, },
}; };
if (!process.env.API_URL) {
throw new Error("Environment variable API_URL is not set");
}
const urlObject = new URL(process.env.API_URL);
const headers = {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${urlObject.username}:${urlObject.password}`),
};
const getUrl = (dbUrlPath) => {
return `${dbObject.protocol}//${urlObject.host}${urlObject.pathname}${dbUrlPath}${urlObject.search}${urlObject.hash}`;
};
export const up = async () => { export const up = async () => {
for (const [dbName, dbSecurity] of Object.entries(dbsSecurity)) { for (const [dbName, dbSecurity] of Object.entries(dbsSecurity)) {
const responseCreateDb = await fetch(`${process.env.API_URL}/${dbName}`, { const responseCreateDb = await fetch(getUrl(dbName), {
method: "PUT", method: "PUT",
headers,
}).then((response) => response.json()); }).then((response) => response.json());
console.assert( if (!responseCreateDb.ok) {
responseCreateDb.ok, throw new Error(
`${dbName} create db error ${JSON.stringify(responseCreateDb)}`, `${dbName} security error ${JSON.stringify(responseCreateDb)}`,
); );
}
const responseSetSecurity = await fetch(`${process.env.API_URL}/${dbName}/_security`, { const responseSetSecurity = await fetch(getUrl(`${dbName}/_security`), {
method: "PUT", method: "PUT",
body: JSON.stringify(dbSecurity), headers,
}).then((response) => response.json()); body: JSON.stringify(dbSecurity),
}).then((response) => response.json());
console.assert( if (!responseSetSecurity.ok) {
responseSetSecurity.ok, throw new Error(
`${dbName} security error ${JSON.stringify(responseSetSecurity)}`, `${dbName} security error ${JSON.stringify(responseSetSecurity)}`,
); );
}
} }
}; };
export const down = async () => { export const down = async () => {
for (const dbName of Object.keys(dbsSecurity)) { for (const dbName of Object.keys(dbsSecurity)) {
const responseDeleteDb = await fetch(`${process.env.API_URL}/${dbName}`, { const responseDeleteDb = await fetch(getUrl(dbName), {
headers,
method: "DELETE", method: "DELETE",
}); });
console.assert( console.assert(