Database Branch by Name

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

This path allows interacting with a given database branch, referenced by parameter db_branch_name, which is expected in the format database_name:branch_name.

Expected Parameters

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

Get Branch Schema and Metadata

GET
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name
Status CodeDescriptionExample Response/Type Definition
200OK
type GetBranchDetails = {
    databaseName: DBName;
    branchName: BranchName;
    createdAt: DateTime;
    id: string;
    version: number;
    lastMigrationID: string;
    metadata?: BranchMetadata;
    startedFrom?: StartedFromMetadata;
    schema: Schema;
};

/**
 * @maxLength 255
 * @minLength 1
 * @pattern [a-zA-Z0-9_\-~]+
 */
type DBName = string;

/**
 * @maxLength 255
 * @minLength 1
 * @pattern [a-zA-Z0-9_\-~]+
 */
type BranchName = string;

/**
 * @format date-time
 */
type DateTime = string;

/**
 * @example {"repository":"github.com/my/repository","branch":"feature-login","stage":"testing","labels":["epic-100"]}
 */
type BranchMetadata = {
    /*
     * @minLength 1
     */
    repository?: string;
    branch?: BranchName;
    /*
     * @minLength 1
     */
    stage?: string;
    labels?: string[];
};

type StartedFromMetadata = {
    branchName: BranchName;
    dbBranchID: string;
    migrationID: string;
};

type Schema = {
    tables: Table[];
    tablesOrder?: string[];
};

type Table = {
    id?: string;
    name: TableName;
    columns: Column[];
    revLinks?: RevLink[];
};

/**
 * @maxLength 255
 * @minLength 1
 * @pattern [a-zA-Z0-9_\-~]+
 */
type TableName = string;

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 RevLink = {
    linkID: string;
    table: string;
};

type ColumnLink = {
    table: string;
};

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

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

Create Database Branch

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

Expected Parameters

NameDescriptionInRequiredSchema
fromName of source branch to branch the new schema fromquery-string

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
type CreateBranch = {
    /*
     * Select the branch to fork from. Defaults to 'main'
     */
    from?: string;
    metadata?: BranchMetadata;
};

/**
 * @example {"repository":"github.com/my/repository","branch":"feature-login","stage":"testing","labels":["epic-100"]}
 */
type BranchMetadata = {
    /*
     * @minLength 1
     */
    repository?: string;
    branch?: BranchName;
    /*
     * @minLength 1
     */
    stage?: string;
    labels?: string[];
};

/**
 * @maxLength 255
 * @minLength 1
 * @pattern [a-zA-Z0-9_\-~]+
 */
type BranchName = string;
Status CodeDescriptionExample Response/Type Definition
201Created
{
  "databaseName": "mydatabase",
  "branchName": "mybranch",
  "status": "completed"
}
400Bad Request
type CreateBranch = {
    id?: string;
    message: string;
};
401Authentication Error
{
  "message": "invalid API key"
}
404Example response
type CreateBranch = {
    id?: string;
    message: string;
};
423Example response
type CreateBranch = {
    id?: string;
    message: string;
};
5XXUnexpected Error
defaultUnexpected Error

Delete Database Branch

DELETE
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name

Delete the branch in the database and all its resources

Status CodeDescriptionExample Response/Type Definition
200OK
type DeleteBranch = {
    status: MigrationStatus;
};

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