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

This commit is contained in:
2024-12-03 18:25:24 +02:00
parent a2eab7c1de
commit 8949a25e0a
@@ -1,18 +1,9 @@
import { fetch } from "pouchdb-fetch"; import { fetch } from "pouchdb-fetch";
const dbsSecurity = { const dbsSecurity = {
_users: { _users: null,
admins: { roles: ["_admin"] }, _replicator: null,
members: { roles: ["_admin"] }, _global_changes: null,
},
_replicator: {
admins: { roles: ["_admin"] },
members: { roles: ["_admin"] },
},
_global_changes: {
admins: { roles: ["_admin"] },
members: { roles: ["_admin"] },
},
server_settings: { server_settings: {
admins: { roles: ["_admin"] }, admins: { roles: ["_admin"] },
@@ -59,19 +50,29 @@ export const up = async () => {
headers, headers,
}).then((response) => response.json()); }).then((response) => response.json());
if (!responseCreateDb.ok) { if (responseCreateDb.ok) {
console.log(`created ${dbName}`);
} else if (responseCreateDb.error === "file_exists") {
console.log(`exists ${dbName}`);
} else {
throw new Error( throw new Error(
`${dbName} security error ${JSON.stringify(responseCreateDb)}`, `${dbName} create error ${JSON.stringify(responseCreateDb)}`,
); );
} }
if (!dbSecurity) {
continue;
}
const responseSetSecurity = await fetch(getUrl(`${dbName}/_security`), { const responseSetSecurity = await fetch(getUrl(`${dbName}/_security`), {
method: "PUT", method: "PUT",
headers, headers,
body: JSON.stringify(dbSecurity), body: JSON.stringify(dbSecurity),
}).then((response) => response.json()); }).then((response) => response.json());
if (!responseSetSecurity.ok) { if (responseSetSecurity.ok) {
console.log(`security ${dbName}`);
} else {
throw new Error( throw new Error(
`${dbName} security error ${JSON.stringify(responseSetSecurity)}`, `${dbName} security error ${JSON.stringify(responseSetSecurity)}`,
); );
@@ -80,14 +81,19 @@ export const up = async () => {
}; };
export const down = async () => { export const down = async () => {
for (const dbName of Object.keys(dbsSecurity)) { const promises = Object.keys(dbsSecurity).map(async (dbName) => {
const responseDeleteDb = await fetch(getUrl(dbName), { const responseDeleteDb = await fetch(getUrl(dbName), {
headers, headers,
method: "DELETE", method: "DELETE",
}); }).then((response) => response.json());
console.assert( if (responseDeleteDb.ok) {
(await responseDeleteDb.json()).ok, console.log(`deleted ${dbName}`);
`${dbName} create db error`, } else {
throw new Error(
`${dbName} delete error ${JSON.stringify(responseDeleteDb)}`,
); );
} }
});
await Promise.allSettled(promises);
await Promise.all(promises);
}; };