Branches
What a branch of a database is, how to create one for each of your environments, and what it shares with its database.
A branch is a database of its own, linked to the database it was made from. Give each of your environments its own branch: production uses the database, and preview, staging or a pull request's environment each use a branch of it.
What a branch is
- Its own database. A branch has its own documents, collections, database keys, token keys, limits and backups. Nothing written to a branch reaches its database, and nothing written to the database reaches its branches.
- Created empty. A new branch holds no documents and no collections. Apply your migrations to it as you do to the database.
- In its database's region. A branch is created in the region of the database it belongs to, and stays there.
- Linked to its database. The database is the branch named
main. Its branches are listed on its Branches page and in the branch picker beside its name.
A branch is made of a database, never of another branch.
Names
A branch's name is unique among its database's branches. Two databases may each have a branch of the same name, and main is the database itself, so no branch takes it.
A branch's address in the dashboard starts with its database's as it was when the branch was made or last renamed: the branch preview of app is at …/app-preview. Renaming the database leaves its branches' addresses as they are.
Create a branch
In the dashboard, open the database's Branches page and choose Create branch. The branch opens once it is created; it is ready when its state is ready.
From the management API, create a database with parent set to the database's ID:
curl -X POST "$MIMIC_MANAGEMENT_API/v1/databases" \
-H "Authorization: Bearer $MIMIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "preview", "parent": "db_…"}'The branch is returned like any database, with parentId set to its database's ID. Issue it keys of its own, and connect to it with its own connection.
Limits
Branches do not count toward your plan's number of databases. Each database has its own number of branches, which the plan sets: see limits.
Delete a branch
A branch is deleted like any database, with the same grace period.
A database that has branches is not deleted until its branches are: delete them first. A branch that is being deleted does not hold its database up, and once its database is being deleted, the branch can no longer be restored.