mirror of
https://github.com/johndoe6345789/postgres.git
synced 2026-04-24 13:55:00 +00:00
feat(constraints): Add PRIMARY KEY constraint support and enhance column management tests
- Add PRIMARY KEY to constraint types in features.json - Update constraints API to handle PRIMARY KEY operations - Add PRIMARY KEY to constraint listing query - Add validation and tests for PRIMARY KEY constraints - Add tests for DEFAULT value and NOT NULL in column management - Update ROADMAP.md to mark PRIMARY KEY, DEFAULT, and NOT NULL as complete - Update README.md with new constraint capabilities - Update TESTING.md with comprehensive test coverage (105 total tests) Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -69,7 +69,7 @@ export async function GET(request: Request) {
|
||||
ON tc.constraint_name = cc.constraint_name
|
||||
WHERE tc.table_schema = 'public'
|
||||
AND tc.table_name = ${tableName}
|
||||
AND tc.constraint_type IN ('UNIQUE', 'CHECK')
|
||||
AND tc.constraint_type IN ('PRIMARY KEY', 'UNIQUE', 'CHECK')
|
||||
ORDER BY tc.constraint_name
|
||||
`);
|
||||
|
||||
@@ -133,7 +133,15 @@ export async function POST(request: Request) {
|
||||
|
||||
let alterQuery = '';
|
||||
|
||||
if (constraintType === 'UNIQUE') {
|
||||
if (constraintType === 'PRIMARY KEY') {
|
||||
if (!columnName) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Column name is required for PRIMARY KEY constraint' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
alterQuery = `ALTER TABLE "${tableName}" ADD CONSTRAINT "${constraintName}" PRIMARY KEY ("${columnName}")`;
|
||||
} else if (constraintType === 'UNIQUE') {
|
||||
if (!columnName) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Column name is required for UNIQUE constraint' },
|
||||
@@ -170,7 +178,7 @@ export async function POST(request: Request) {
|
||||
alterQuery = `ALTER TABLE "${tableName}" ADD CONSTRAINT "${constraintName}" CHECK (${checkExpression})`;
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ error: 'Unsupported constraint type. Supported types: UNIQUE, CHECK' },
|
||||
{ error: 'Unsupported constraint type. Supported types: PRIMARY KEY, UNIQUE, CHECK' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -107,6 +107,12 @@
|
||||
}
|
||||
],
|
||||
"constraintTypes": [
|
||||
{
|
||||
"name": "PRIMARY KEY",
|
||||
"description": "Unique identifier for table rows",
|
||||
"requiresColumn": true,
|
||||
"requiresExpression": false
|
||||
},
|
||||
{
|
||||
"name": "UNIQUE",
|
||||
"description": "Ensure column values are unique",
|
||||
|
||||
@@ -280,6 +280,15 @@ describe('FeatureConfig', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should include PRIMARY KEY constraint type', () => {
|
||||
const constraintTypes = getConstraintTypes();
|
||||
const primaryKeyConstraint = constraintTypes.find(ct => ct.name === 'PRIMARY KEY');
|
||||
|
||||
expect(primaryKeyConstraint).toBeDefined();
|
||||
expect(primaryKeyConstraint?.requiresColumn).toBe(true);
|
||||
expect(primaryKeyConstraint?.requiresExpression).toBe(false);
|
||||
});
|
||||
|
||||
it('should include UNIQUE constraint type', () => {
|
||||
const constraintTypes = getConstraintTypes();
|
||||
const uniqueConstraint = constraintTypes.find(ct => ct.name === 'UNIQUE');
|
||||
|
||||
Reference in New Issue
Block a user