"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InsertNewProductDetailStock1687415141200 = void 0;
const typeorm_1 = require("typeorm");
class InsertNewProductDetailStock1687415141200 {
    async up(queryRunner) {
        await (0, typeorm_1.getConnection)().transaction(async (trx) => {
            await trx.query(`
        CREATE OR REPLACE FUNCTION insert_new_product_detail_stock()
        RETURNS TRIGGER AS $$
        BEGIN
            INSERT INTO product_detail_stocks (product_detail_id, qty, locked_qty, unassigned_qty, uom_value, locked_uom_value, unassigned_uom_value, updated_at, domain_id)
            VALUES (NEW.id, 0, 0, 0, 0, 0 ,0, NOW(), NEW.domain_id);
            RETURN NEW;
        END;
        $$ LANGUAGE plpgsql;
    `);
            await trx.query(`
        CREATE TRIGGER product_details_trigger
        AFTER INSERT ON product_details
        FOR EACH ROW
        EXECUTE FUNCTION insert_new_product_detail_stock();
    `);
        });
    }
    async down(queryRunner) {
        await queryRunner.query('DROP TRIGGER product_details_trigger ON product_details');
        await queryRunner.query('DROP FUNCTION IF EXISTS insert_new_product_detail_stock()');
    }
}
exports.InsertNewProductDetailStock1687415141200 = InsertNewProductDetailStock1687415141200;
//# sourceMappingURL=1687415141200-InsertNewProductDetailStock.js.map