#!/usr/bin/env python3 """Create private dated worker sick-note storage, without changing employee data.""" from pb_env import http, superuser_token def main(): token = superuser_token() code, employees = http("GET", "/api/collections/employees", token=token) if code != 200: raise RuntimeError("Could not read employee schema") definition = { "name": "employee_sick_notes", "type": "base", "listRule": None, "viewRule": None, "createRule": None, "updateRule": None, "deleteRule": None, "fields": [ {"name": "employee", "type": "relation", "required": True, "collectionId": employees["id"], "maxSelect": 1, "cascadeDelete": False}, {"name": "note_date", "type": "date", "required": True}, {"name": "end_date", "type": "date", "required": False}, {"name": "photo", "type": "file", "required": True, "maxSelect": 1, "maxSize": 10485760, "mimeTypes": ["image/jpeg", "image/png", "image/webp"], "protected": True}, {"name": "created", "type": "autodate", "onCreate": True, "onUpdate": False}, ], "indexes": ["CREATE INDEX idx_employee_sick_notes_date ON employee_sick_notes (employee, note_date)"], } code, actual = http("GET", "/api/collections/employee_sick_notes", token=token) if code == 404: code, actual = http("POST", "/api/collections", definition, token) if code != 200: raise RuntimeError(f"Schema creation failed: HTTP {code}") print("Created employee_sick_notes") elif code != 200: raise RuntimeError(f"Schema read failed: HTTP {code}") fields = {field["name"]: field for field in actual["fields"]} for wanted in definition["fields"]: assert all(fields[wanted["name"]].get(key) == value for key, value in wanted.items()), "Incompatible existing sick-note schema" for key in ("listRule", "viewRule", "createRule", "updateRule", "deleteRule"): assert actual.get(key) is None, "Sick notes must remain private" print("Verified private collection and protected photo field; no employee or payroll records changed.") if __name__ == "__main__": main()