0558d92203
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
858 B
TypeScript
20 lines
858 B
TypeScript
import { Types } from "mongoose";
|
||
import { installDefaultCategories } from "@/features/categories/service";
|
||
import { AccountModel } from "@/models/account";
|
||
import { CategoryModel } from "@/models/category";
|
||
import { HouseholdModel } from "@/models/household";
|
||
import type { Migration } from "./types";
|
||
|
||
/** Hesap ve kategori index'leri + mevcut hanelere varsayılan kategori seti (idempotent). */
|
||
export const migration: Migration = {
|
||
name: "002-accounts-categories",
|
||
description: "accounts/categories index'leri ve mevcut hanelere varsayılan kategoriler",
|
||
async up() {
|
||
await AccountModel.createIndexes();
|
||
await CategoryModel.createIndexes();
|
||
for (const h of await HouseholdModel.find().select({ _id: 1, createdBy: 1 }).lean()) {
|
||
await installDefaultCategories(h._id as Types.ObjectId, h.createdBy as Types.ObjectId);
|
||
}
|
||
},
|
||
};
|