Initial commit
All checks were successful
Docker Build and Publish / build-and-push (push) Successful in 2m17s
All checks were successful
Docker Build and Publish / build-and-push (push) Successful in 2m17s
This commit is contained in:
111
backend/pb_migrations/1736615000_create_time_entries.js
Normal file
111
backend/pb_migrations/1736615000_create_time_entries.js
Normal file
@@ -0,0 +1,111 @@
|
||||
migrate((db) => {
|
||||
const dao = new Dao(db);
|
||||
|
||||
const collection = new Collection({
|
||||
name: "time_entries",
|
||||
type: "base",
|
||||
schema: [
|
||||
{
|
||||
name: "user",
|
||||
type: "relation",
|
||||
required: true,
|
||||
options: {
|
||||
collectionId: "_pb_users_auth_",
|
||||
cascadeDelete: true,
|
||||
maxSelect: 1,
|
||||
displayFields: []
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "date",
|
||||
type: "date",
|
||||
required: true,
|
||||
options: {
|
||||
min: "",
|
||||
max: ""
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "start_time",
|
||||
type: "date",
|
||||
required: false,
|
||||
options: {
|
||||
min: "",
|
||||
max: ""
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "end_time",
|
||||
type: "date",
|
||||
required: false,
|
||||
options: {
|
||||
min: "",
|
||||
max: ""
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "duration",
|
||||
type: "number",
|
||||
required: true,
|
||||
options: {
|
||||
min: 0,
|
||||
max: null,
|
||||
noDecimal: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "type",
|
||||
type: "select",
|
||||
required: true,
|
||||
options: {
|
||||
maxSelect: 1,
|
||||
values: ["regular", "overtime", "standby", "callback"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "day_type",
|
||||
type: "select",
|
||||
required: true,
|
||||
options: {
|
||||
maxSelect: 1,
|
||||
values: ["workday", "rest_day_1", "rest_day_2", "holiday"]
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "multiplier",
|
||||
type: "number",
|
||||
required: true,
|
||||
options: {
|
||||
min: 0,
|
||||
max: null,
|
||||
noDecimal: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "notes",
|
||||
type: "text",
|
||||
required: false,
|
||||
options: {
|
||||
min: null,
|
||||
max: null,
|
||||
pattern: ""
|
||||
}
|
||||
}
|
||||
],
|
||||
listRule: "@request.auth.id = user.id",
|
||||
viewRule: "@request.auth.id = user.id",
|
||||
createRule: "@request.auth.id = user.id",
|
||||
updateRule: "@request.auth.id = user.id",
|
||||
deleteRule: "@request.auth.id = user.id",
|
||||
});
|
||||
|
||||
return dao.saveCollection(collection);
|
||||
}, (db) => {
|
||||
const dao = new Dao(db);
|
||||
try {
|
||||
const collection = dao.findCollectionByNameOrId("time_entries");
|
||||
return dao.deleteCollection(collection);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
45
backend/pb_migrations/1736616000_update_time_entries.js
Normal file
45
backend/pb_migrations/1736616000_update_time_entries.js
Normal file
@@ -0,0 +1,45 @@
|
||||
migrate((db) => {
|
||||
const dao = new Dao(db);
|
||||
const collection = dao.findCollectionByNameOrId("time_entries");
|
||||
|
||||
// Add is_banked field
|
||||
collection.schema.addField(new SchemaField({
|
||||
name: "is_banked",
|
||||
type: "bool",
|
||||
required: false, // Default true handled in app logic or ignored for now
|
||||
options: {}
|
||||
}));
|
||||
|
||||
// Add manual_override field
|
||||
collection.schema.addField(new SchemaField({
|
||||
name: "manual_override",
|
||||
type: "bool",
|
||||
required: false,
|
||||
options: {}
|
||||
}));
|
||||
|
||||
// Add calculated_hours field
|
||||
collection.schema.addField(new SchemaField({
|
||||
name: "calculated_hours",
|
||||
type: "number",
|
||||
required: false,
|
||||
options: {
|
||||
min: null,
|
||||
max: null,
|
||||
noDecimal: false
|
||||
}
|
||||
}));
|
||||
|
||||
return dao.saveCollection(collection);
|
||||
}, (db) => {
|
||||
const dao = new Dao(db);
|
||||
const collection = dao.findCollectionByNameOrId("time_entries");
|
||||
|
||||
// logic to remove fields if needed, usually tricky in PB migrations securely without losing data
|
||||
// For now we just return null or attempt simple removal
|
||||
collection.schema.removeField("is_banked");
|
||||
collection.schema.removeField("manual_override");
|
||||
collection.schema.removeField("calculated_hours");
|
||||
|
||||
return dao.saveCollection(collection);
|
||||
})
|
||||
53
backend/pb_migrations/1736617000_update_users_supervisor.js
Normal file
53
backend/pb_migrations/1736617000_update_users_supervisor.js
Normal file
@@ -0,0 +1,53 @@
|
||||
migrate((db) => {
|
||||
const dao = new Dao(db);
|
||||
|
||||
// 1. Update 'users' collection
|
||||
const usersCollection = dao.findCollectionByNameOrId("users");
|
||||
|
||||
usersCollection.schema.addField(new SchemaField({
|
||||
name: "is_supervisor",
|
||||
type: "bool",
|
||||
required: false,
|
||||
options: {}
|
||||
}));
|
||||
|
||||
usersCollection.schema.addField(new SchemaField({
|
||||
name: "supervisor",
|
||||
type: "relation",
|
||||
required: false,
|
||||
options: {
|
||||
collectionId: usersCollection.id,
|
||||
cascadeDelete: false,
|
||||
maxSelect: 1,
|
||||
displayFields: ["name", "email"]
|
||||
}
|
||||
}));
|
||||
|
||||
dao.saveCollection(usersCollection);
|
||||
|
||||
// 2. Update 'time_entries' collection rules
|
||||
const timeEntries = dao.findCollectionByNameOrId("time_entries");
|
||||
|
||||
// Allow if owner OR if user's supervisor is requestor
|
||||
const rule = "@request.auth.id = user.id || user.supervisor.id = @request.auth.id";
|
||||
|
||||
timeEntries.listRule = rule;
|
||||
timeEntries.viewRule = rule;
|
||||
// create/update/delete usually restricted to owner, supervisors maybe read-only for now?
|
||||
// Plan said "view", so list/view is enough.
|
||||
|
||||
dao.saveCollection(timeEntries);
|
||||
|
||||
}, (db) => {
|
||||
// Revert logic (simplified)
|
||||
const dao = new Dao(db);
|
||||
const usersCollection = dao.findCollectionByNameOrId("users");
|
||||
usersCollection.schema.removeField("is_supervisor");
|
||||
usersCollection.schema.removeField("supervisor");
|
||||
dao.saveCollection(usersCollection);
|
||||
|
||||
const timeEntries = dao.findCollectionByNameOrId("time_entries");
|
||||
timeEntries.listRule = "@request.auth.id = user.id";
|
||||
timeEntries.viewRule = "@request.auth.id = user.id";
|
||||
dao.saveCollection(timeEntries);
|
||||
})
|
||||
Reference in New Issue
Block a user