"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get down () {
        return down;
    },
    get up () {
        return up;
    }
});
const _sequelize = require("sequelize");
async function up(query) {
    await query.createTable('ai_documents', {
        id: {
            // ai documents use a generated id derived from (type, record_type, record_id)
            // so two facilities independently generating a summary for the same logical record
            type: `TEXT GENERATED ALWAYS AS ("type" || ';' || record_type || ';' || REPLACE("record_id", ';', ':')) STORED`
        },
        type: {
            type: _sequelize.DataTypes.STRING,
            allowNull: false,
            primaryKey: true
        },
        record_type: {
            type: _sequelize.DataTypes.STRING,
            allowNull: false,
            primaryKey: true
        },
        record_id: {
            type: _sequelize.DataTypes.STRING,
            allowNull: false,
            primaryKey: true
        },
        status: {
            type: _sequelize.DataTypes.STRING,
            allowNull: false,
            defaultValue: 'generated'
        },
        content: {
            type: _sequelize.DataTypes.TEXT,
            allowNull: true
        },
        source: {
            type: _sequelize.DataTypes.STRING,
            allowNull: false,
            defaultValue: 'ai'
        },
        created_at: {
            type: _sequelize.DataTypes.DATE,
            allowNull: false,
            defaultValue: _sequelize.DataTypes.NOW
        },
        updated_at: {
            type: _sequelize.DataTypes.DATE,
            allowNull: false,
            defaultValue: _sequelize.DataTypes.NOW
        },
        deleted_at: {
            type: _sequelize.DataTypes.DATE,
            allowNull: true
        }
    });
    // unique constraint on the generated id so single-id lookups (e.g. PUT /:id) are
    // indexed; the composite primary key already enforces logical uniqueness.
    await query.sequelize.query(`ALTER TABLE ai_documents ADD CONSTRAINT ai_documents_id_key UNIQUE (id);`);
}
async function down(query) {
    await query.dropTable('ai_documents');
}

//# sourceMappingURL=1778035386449-createAiDocuments.js.map