feat(seed): varsayılan kategoriler, örnek hesaplar ve 002 migration
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
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);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1,10 +1,11 @@
|
||||
import { getDb } from "@/lib/db/mongo";
|
||||
import { connectMongoose } from "@/lib/db/mongoose";
|
||||
import { migration as m001 } from "./001-initial-indexes";
|
||||
import { migration as m002 } from "./002-accounts-categories";
|
||||
import type { Migration } from "./types";
|
||||
|
||||
/** Sıralı migration listesi. Yeni migration: dosyayı ekle ve buraya sırayla ekle. */
|
||||
export const MIGRATIONS: Migration[] = [m001];
|
||||
export const MIGRATIONS: Migration[] = [m001, m002];
|
||||
|
||||
const COLLECTION = "migrations";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user