add db-migrations
Main daploy / deploy (push) Successful in 43s

This commit is contained in:
2024-11-24 23:52:52 +02:00
parent e8dce0cf5e
commit f1eb121b5e
8 changed files with 189 additions and 3 deletions
+2
View File
@@ -0,0 +1,2 @@
[chttpd_auth]
timeout = 315362081
+1
View File
@@ -0,0 +1 @@
.migrate
+5
View File
@@ -0,0 +1,5 @@
import PouchDB from "pouchdb-core";
import PouchDBAdapterHttp from "pouchdb-adapter-http";
import PouchdbFind from "pouchdb-find";
export default PouchDB.plugin(PouchDBAdapterHttp).plugin(PouchdbFind);
@@ -0,0 +1,40 @@
import { fetch } from "pouchdb-fetch";
const dbsSecurity = {
web_push_subscriptions: {
admins: { roles: ["_admin"] },
members: { roles: [] },
},
messages: {
admins: { roles: ["_admin"] },
members: { roles: [] },
},
server_settings: {
admins: { roles: ["_admin"] },
members: { roles: ["_admin"] },
},
// qr: {
// admins: { roles: ["_admin"] },
// members: { roles: [] },
// },
};
export const up = async () => {
for (const [dbName, dbSecurity] of Object.entries(dbsSecurity)) {
await fetch(`${process.env.API_URL}/${dbName}`, {
method: "PUT",
});
await fetch(`${process.env.API_URL}/${dbName}/_security`, {
method: "PUT",
body: JSON.stringify(dbSecurity),
});
}
};
export const down = async () => {
for (const dbName of Object.keys(dbsSecurity)) {
await fetch(`${process.env.API_URL}/${dbName}`, {
method: "DELETE",
});
}
};
@@ -0,0 +1,9 @@
import PouchDB from "../PouchDB.js";
export const up = async () => {
await new PouchDB(`${process.env.API_URL}/`, { skip_setup: true });
};
export const down = async () => {
await new PouchDB(`${process.env.API_URL}/`, { skip_setup: true });
};
+18
View File
@@ -0,0 +1,18 @@
{
"name": "@hereconnect/db-migrations",
"version": "1.0.0",
"type": "module",
"license": "@hereconnect",
"private": true,
"engines": {
"node": ">=v20.10.0",
"pnpm": ">=8.15.0"
},
"dependencies": {
"migrate": "^2.1.0",
"pouchdb-adapter-http": "^9.0.0",
"pouchdb-core": "^9.0.0",
"pouchdb-fetch": "^9.0.0",
"pouchdb-find": "^9.0.0"
}
}