84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
/// PocketBase migration: `tx_deletes` — synced tombstones for deleted admin
|
|
/// test transactions so another device cannot push them back into `transactions`.
|
|
///
|
|
/// 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");
|
|
|
|
try {
|
|
app.findCollectionByNameOrId("tx_deletes");
|
|
return;
|
|
} catch (_) {}
|
|
|
|
const ownerRules = {
|
|
listRule: "user = @request.auth.id",
|
|
viewRule: "user = @request.auth.id",
|
|
createRule: "@request.auth.id != '' && user = @request.auth.id",
|
|
updateRule: "user = @request.auth.id",
|
|
deleteRule: "user = @request.auth.id",
|
|
};
|
|
|
|
const txDeletes = new Collection({
|
|
type: "base",
|
|
name: "tx_deletes",
|
|
...ownerRules,
|
|
fields: [
|
|
{
|
|
type: "relation",
|
|
name: "user",
|
|
required: true,
|
|
collectionId: users.id,
|
|
cascadeDelete: true,
|
|
maxSelect: 1,
|
|
},
|
|
{
|
|
// Clipped BankTransaction.id
|
|
type: "text",
|
|
name: "tx_id",
|
|
required: true,
|
|
min: 1,
|
|
max: 2000,
|
|
},
|
|
{
|
|
type: "text",
|
|
name: "date",
|
|
required: true,
|
|
min: 1,
|
|
max: 32,
|
|
},
|
|
{
|
|
type: "text",
|
|
name: "description",
|
|
required: true,
|
|
min: 1,
|
|
max: 4000,
|
|
},
|
|
{
|
|
type: "number",
|
|
name: "amount",
|
|
required: true,
|
|
},
|
|
{
|
|
type: "text",
|
|
name: "currency",
|
|
required: true,
|
|
min: 1,
|
|
max: 8,
|
|
},
|
|
],
|
|
indexes: [
|
|
"CREATE UNIQUE INDEX idx_tx_deletes_user_tx ON tx_deletes (user, tx_id)",
|
|
],
|
|
});
|
|
app.save(txDeletes);
|
|
}, (app) => {
|
|
try {
|
|
app.delete(app.findCollectionByNameOrId("tx_deletes"));
|
|
} catch (_) {}
|
|
});
|