32 lines
959 B
JavaScript
32 lines
959 B
JavaScript
/// PocketBase migration: `is_admin` on usersapp (admin vs normal accounts).
|
|
///
|
|
/// Admins can create test transactions in the app. Set the flag in Admin UI:
|
|
/// Users → pick user → is_admin = true.
|
|
///
|
|
/// Apply on the server:
|
|
///
|
|
/// sudo cp this_file /opt/pocketbase/pb_migrations/
|
|
/// sudo chown pocketbase:pocketbase /opt/pocketbase/pb_migrations/*.js
|
|
/// sudo -u pocketbase /opt/pocketbase/pocketbase migrate up
|
|
/// sudo systemctl restart pocketbase
|
|
migrate((app) => {
|
|
const users = app.findCollectionByNameOrId("usersapp");
|
|
if (users.fields.getByName("is_admin")) return;
|
|
|
|
users.fields.add(new Field({
|
|
type: "bool",
|
|
name: "is_admin",
|
|
required: false,
|
|
}));
|
|
app.save(users);
|
|
}, (app) => {
|
|
try {
|
|
const users = app.findCollectionByNameOrId("usersapp");
|
|
const field = users.fields.getByName("is_admin");
|
|
if (field) {
|
|
users.fields.removeById(field.id);
|
|
app.save(users);
|
|
}
|
|
} catch (_) {}
|
|
});
|