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;
    }
})
