Table Schema

https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name/schema

This endpoint enables reading or updating the schema of a given table.

Expected Parameters

NameDescriptionInRequiredSchema
db_branch_nameThe DBBranchName matches the pattern `{db_name}:{branch_name}`. pathstring
table_nameThe Table namepathstring

Get Table Schema

GET
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name/schema
Status CodeDescriptionExample Response/Type Definition
200OK
type GetTableSchema = {
    columns: Column[];
};

type Column = {
    name: string;
    type: "bool" | "int" | "float" | "string" | "text" | "email" | "multiple" | "link" | "object" | "datetime" | "vector" | "file[]" | "file";
    link?: ColumnLink;
    vector?: ColumnVector;
    file?: ColumnFile;
    ["file[]"]?: ColumnFile;
    notNull?: boolean;
    defaultValue?: string;
    unique?: boolean;
    columns?: Column[];
};

type ColumnLink = {
    table: string;
};

type ColumnVector = {
    /*
     * @maximum 10000
     * @minimum 2
     */
    dimension: number;
};

type ColumnFile = {
    defaultPublicAccess?: boolean;
};
400Bad Request
type GetTableSchema = {
    id?: string;
    message: string;
};
401Authentication Error
{
  "message": "invalid API key"
}
404Example response
type GetTableSchema = {
    id?: string;
    message: string;
};
5XXUnexpected Error
defaultUnexpected Error

Update Table Schema

PUT
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name/schema

Request Body Type Definition

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
type SetTableSchema = {
    columns: Column[];
};

type Column = {
    name: string;
    type: "bool" | "int" | "float" | "string" | "text" | "email" | "multiple" | "link" | "object" | "datetime" | "vector" | "file[]" | "file";
    link?: ColumnLink;
    vector?: ColumnVector;
    file?: ColumnFile;
    ["file[]"]?: ColumnFile;
    notNull?: boolean;
    defaultValue?: string;
    unique?: boolean;
    columns?: Column[];
};

type ColumnLink = {
    table: string;
};

type ColumnVector = {
    /*
     * @maximum 10000
     * @minimum 2
     */
    dimension: number;
};

type ColumnFile = {
    defaultPublicAccess?: boolean;
};
Status CodeDescriptionExample Response/Type Definition
200Schema migration response with ID and migration status.
type SetTableSchema = {
    /*
     * @minLength 1
     */
    migrationID: string;
    parentMigrationID: string;
    status: MigrationStatus;
};

type MigrationStatus = "completed" | "pending" | "failed";
204No Content
400Bad Request
type SetTableSchema = {
    id?: string;
    message: string;
};
401Authentication Error
{
  "message": "invalid API key"
}
404Example response
type SetTableSchema = {
    id?: string;
    message: string;
};
409Example response
type SetTableSchema = {
    id?: string;
    message: string;
};
5XXUnexpected Error
defaultUnexpected Error