Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/database/models/schema-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as React from 'react';
import { DeclaredSchema } from '@/lib/models/database';
import { createSchema, patchSchema } from '@/lib/api/database';
import { createSchema, putSchema } from '@/lib/api/database';
import { FieldsTable, FormField, transformFieldsForApi } from './fields-table';
import { SchemaPreview } from './schema-preview';
import { Button } from '@/components/ui/button';
Expand Down Expand Up @@ -268,7 +268,7 @@ export function SchemaEditor({
toast({ title: 'Schema created successfully' });
onSave?.(result);
} else {
await patchSchema(schema._id, {
await putSchema(schema._id, {
fields: fieldsObject,
});
toast({ title: 'Schema updated successfully' });
Expand Down
7 changes: 7 additions & 0 deletions src/lib/api/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DeclaredSchema,
PatchSchemaRequest,
PendingSchemas,
PutSchemaRequest,
SchemaOptions,
} from '@/lib/models/database';
import { CustomEndpoint } from '@/lib/models/database/custom-endpoints';
Expand Down Expand Up @@ -86,6 +87,12 @@ export const patchSchema = async (id: string, schema: PatchSchemaRequest) => {
.then(res => res.data);
};

export const putSchema = async (id: string, schema: PutSchemaRequest) => {
return await (await getApiClient())
.put<DeclaredSchema>(`/database/schemas/${id}`, schema)
.then(res => res.data);
};

export const updateExtensions = async (
id: string,
fields: DeclaredSchema['fields']
Expand Down
10 changes: 8 additions & 2 deletions src/lib/models/database/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export type DeclaredSchema = {
updatedAt: string;
};

/** PATCH /database/schemas/:id — matches Database admin route bodyParams */
export type PatchSchemaRequest = Partial<Pick<DeclaredSchema, 'fields'>> & {
/** PATCH /database/schemas/:id — conduitOptions only; field edits go through PUT */
export type PatchSchemaRequest = {
/** Nested shapes are permissive — callers build objects from forms */
conduitOptions?: {
cms?: Record<string, unknown>;
Expand All @@ -69,6 +69,12 @@ export type PatchSchemaRequest = Partial<Pick<DeclaredSchema, 'fields'>> & {
readPreference?: string;
};
};

/** PUT /database/schemas/:id — full field replacement */
export type PutSchemaRequest = Pick<DeclaredSchema, 'fields'> & {
conduitOptions?: PatchSchemaRequest['conduitOptions'];
};

export type CreateSchemaRequest = {
name: string;
fields: any;
Expand Down
Loading