888
This commit is contained in:
@@ -61,6 +61,11 @@ export class MetadataController {
|
||||
response.status(201).json({ success: true });
|
||||
}
|
||||
|
||||
async dropIndex(request: Request, response: Response) {
|
||||
await service.dropIndex(request.session.user!.id, request.params.tableName, request.params.indexName);
|
||||
response.status(204).send();
|
||||
}
|
||||
|
||||
async createRow(request: Request, response: Response) {
|
||||
await service.createRow(request.session.user!.id, request.params.tableName, request.body);
|
||||
response.status(201).json({ success: true });
|
||||
|
||||
@@ -60,4 +60,21 @@ export class MetadataRepository {
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
async listIndexes(tableName: string) {
|
||||
const { rows } = await pool.query(
|
||||
`
|
||||
select
|
||||
indexname as index_name,
|
||||
indexdef as index_definition
|
||||
from pg_indexes
|
||||
where schemaname = 'public'
|
||||
and tablename = $1
|
||||
order by indexname
|
||||
`,
|
||||
[tableName]
|
||||
);
|
||||
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ router.patch(
|
||||
);
|
||||
router.delete("/tables/:tableName/columns/:columnName", asyncHandler(controller.dropColumn.bind(controller)));
|
||||
router.post("/tables/:tableName/indexes", validateBody(createIndexSchema), asyncHandler(controller.createIndex.bind(controller)));
|
||||
router.delete("/tables/:tableName/indexes/:indexName", asyncHandler(controller.dropIndex.bind(controller)));
|
||||
router.post("/tables/:tableName/rows", validateBody(rowSchema), asyncHandler(controller.createRow.bind(controller)));
|
||||
router.put("/tables/:tableName/rows/:id", validateBody(rowSchema), asyncHandler(controller.updateRow.bind(controller)));
|
||||
router.delete("/tables/:tableName/rows/:id", asyncHandler(controller.deleteRow.bind(controller)));
|
||||
|
||||
@@ -16,12 +16,13 @@ export class MetadataService {
|
||||
|
||||
async getTableDetails(tableName: string) {
|
||||
assertIdentifier(tableName, "table name");
|
||||
const [columns, foreignKeys] = await Promise.all([
|
||||
const [columns, foreignKeys, indexes] = await Promise.all([
|
||||
repository.listTableColumns(tableName),
|
||||
repository.listForeignKeys(tableName)
|
||||
repository.listForeignKeys(tableName),
|
||||
repository.listIndexes(tableName)
|
||||
]);
|
||||
|
||||
return { columns, foreignKeys };
|
||||
return { columns, foreignKeys, indexes };
|
||||
}
|
||||
|
||||
async listRows(params: {
|
||||
@@ -132,6 +133,12 @@ export class MetadataService {
|
||||
await this.logSchema(userId, tableName, "create_index", payload);
|
||||
}
|
||||
|
||||
async dropIndex(userId: string, tableName: string, indexName: string) {
|
||||
await this.assertSchemaPermission(userId, tableName);
|
||||
await pool.query(`drop index if exists ${quoteIdentifier(indexName)}`);
|
||||
await this.logSchema(userId, tableName, "drop_index", { indexName });
|
||||
}
|
||||
|
||||
async createRow(userId: string, tableName: string, data: Record<string, unknown>) {
|
||||
await rbacService.assertPermission(userId, tableName, "write");
|
||||
await this.mutateRow(userId, tableName, "insert", data);
|
||||
|
||||
Reference in New Issue
Block a user