import type { Types } from "mongoose"; import { installDefaultStockCategories } from "@/features/stock/service"; import { HouseholdModel } from "@/models/household"; import { ProductTypeModel } from "@/models/product-type"; import { StockCategoryModel } from "@/models/stock-category"; import { StockMovementModel } from "@/models/stock-movement"; import type { Migration } from "./types"; export const migration: Migration = { name: "011-stock", description: "stok koleksiyonları index'leri; mevcut hanelere varsayılan stok kategorileri", async up() { await StockCategoryModel.createIndexes(); await ProductTypeModel.createIndexes(); await StockMovementModel.createIndexes(); const households = await HouseholdModel.find({}).select({ createdBy: 1 }).lean(); for (const h of households) await installDefaultStockCategories(h._id as Types.ObjectId, h.createdBy as Types.ObjectId); }, };