First commit

This commit is contained in:
2026-03-18 22:42:33 +09:00
commit 50657066a6
64 changed files with 5290 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
import type { FastifyPluginAsync } from "fastify";
import fp from "fastify-plugin";
import { MikroORM } from "@mikro-orm/postgresql";
import config from "@/mikro-orm.config";
import logger from "@/lib/logger";
declare module "fastify" {
interface FastifyInstance {
orm: MikroORM;
}
}
const Database: FastifyPluginAsync = async (fastify) => {
const orm = await MikroORM.init(config);
if (process.env.NODE_ENV !== "production") {
try {
await orm.schema.updateSchema();
logger.info("Database migration completed.");
} catch (err) {
logger.error("Migration failed:", err);
process.exit(1);
}
}
fastify.decorate("orm", orm);
fastify.addHook("onClose", async () => {
await orm.close(true);
});
};
export default fp(Database);