-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddl-controller.ts
More file actions
23 lines (19 loc) · 854 Bytes
/
ddl-controller.ts
File metadata and controls
23 lines (19 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Request, Response } from 'express';
import { sequelize } from '../config/database';
import { successResponse, errorResponse } from '../utils/response';
import { DDLOperations } from '../types/ddl';
import { DDLExecutor } from '../operations/migrate';
export const migrate = async (req: Request, res: Response) => {
const { operations }: { operations: DDLOperations[] } = req.body;
if (!operations || !Array.isArray(operations))
return errorResponse(res, 'Invalid payload structure', 400);
const transaction = await sequelize.transaction();
try {
await DDLExecutor.execute(operations, transaction);
await transaction.commit();
return successResponse(res, {}, 'DDL operations completed successfully');
} catch (error: any) {
await transaction.rollback();
return errorResponse(res, error.message, 500);
}
};