This commit is contained in:
2026-03-19 17:23:29 +07:00
parent 9dddc3f377
commit 7950b401dc
7 changed files with 1735 additions and 8 deletions

View File

@@ -80,13 +80,16 @@ export class MetadataService {
};
}
async createTable(userId: string, payload: { tableName: string; columns: { name: string; type: string; nullable?: boolean }[] }) {
async createTable(
userId: string,
payload: { tableName: string; columns: { name: string; type: string; nullable?: boolean; primaryKey?: boolean }[] }
) {
await this.assertSchemaPermission(userId, payload.tableName);
const columnSql = payload.columns
.map(
(column: { name: string; type: string; nullable?: boolean }) =>
`${quoteIdentifier(column.name)} ${column.type}${column.nullable ? "" : " NOT NULL"}`
(column: { name: string; type: string; nullable?: boolean; primaryKey?: boolean }) =>
`${quoteIdentifier(column.name)} ${column.type}${column.primaryKey ? " PRIMARY KEY" : column.nullable ? "" : " NOT NULL"}`
)
.join(", ");

View File

@@ -6,7 +6,8 @@ export const createTableSchema = z.object({
z.object({
name: z.string().min(1),
type: z.string().min(1),
nullable: z.boolean().optional()
nullable: z.boolean().optional(),
primaryKey: z.boolean().optional()
})
).min(1)
});