Skip to main content

Automatic Schema Management

Made changes to your data models and forgot to apply them in production before deployment? Have to communicate schema changes to others or wait for that project tracker issue to resolve? Unexpected changes happen all the time, often by mistake and without warning. Even with change control policies carved in stone, they may not always be followed.

Tigris lets you automate the schema management process completely and ensures that the data models in your application are always in sync with the corresponding schema in the database. This makes the change control as simple as a "Code review". Let's see how this works.

How does this work?

Define your data models in your TypeScript project. Register them with the Tigris client during build time and let the Tigris SDK automatically synchronize your data models with the database. This includes creating collections that do not exist, as well as applying schema changes if the data model has evolved.

For example, let's use following Product and User data model:

import {
} from "@tigrisdata/core";

export class Product {
@PrimaryKey(TigrisDataTypes.INT64, { order: 1, autoGenerate: true })
id?: string;

title: string;

description: string;

price: number;
import {
} from "@tigrisdata/core";

export class Status {
lastSeenAt: string;

memberSince: string;

export class User {
@PrimaryKey({ order: 1 })
name: number;

status: Status;

Use this script to register models

Now, let's write a script that can trigger build time to automatically create or update the collections

import { Tigris } from "@tigrisdata/core";
import { Product } from "./db/models/product";
import { User } from "./db/models/user";

async function main() {
// setup client
const tigrisClient = new Tigris();
// ensure branch exists, create it if it needs to be created dynamically
await tigrisClient.getDatabase().initializeBranch();
// register schemas
await tigrisClient.registerSchemas([Product, User]);

.then(async () => {
console.log("Setup complete ...");
.catch(async (e) => {

The script depends on the following environment variables to be set

Environment variable nameValue
TIGRIS_URIThe URI to your Tigris deployment. For Tigris Cloud this is
TIGRIS_PROJECTyour project name
TIGRIS_CLIENT_IDyour production app key client ID
TIGRIS_CLIENT_SECRETyour production app key client secret

Execute setup script at build time

Include this script in package.json of your npm project and register triggers depending how your project builds. Here are some examples for popular frameworks:

"scripts": {
"setup": "npx ts-node scripts/setup.ts",
"predev": "npm run setup",
"dev": "next dev",
"build": "next build",
"postbuild": "npm run setup",
"start": "next start"

This way your data models are always synchronized with the database and you never have to step out of your development workflow.


Q - Will a new collection be created if it already exists?
Q - Will a collection be deleted if corresponding model is removed?
  • No, that would be an unsafe operation. Users have to explicitly delete collection(s).