Underbase

Underbase

  • Docs
  • Guides
  • API
  • GitHub

›Guides

Get started

  • Introduction
  • Installation
  • Configuration
  • Writting migrations
  • Module usage
  • Logging
  • Troubleshooting

Guides

  • Organizing migrations
  • Babel usage
  • Working with backups
  • Typescript usage

API

  • Module
  • Configuration API
  • Query Interface
  • Module for development
Edit

Organizing migrations

Organizing your migrations workflow is quite easy using configuration files and versionned folders.

File structure

For example, consider the following file structure :

# Your app code base
migrations
├── 1.0
|   ├── index.js <-- entry file to execute migrations
|   ├── articles.js
|   ├── users.js
|   └── tags.js
├── 1.1
|   ├── index.js
|   ├── articles.js
├── 2.0 <-- major version
|   ├── index.js
|   ├── articles.js
|   ├── users.js
|   └── logs.js
└── config.js <-- configuration file

Managing multiple databases ?

# Your app code base
migrations
├── api <-- API database
|   ├── 1.0
|   |   ├── index.js <-- entry file to execute migrations
|   |   ├── articles.js
|   |   ├── users.js
|   |   └── tags.js
|   ├── 1.1
|   |   ├── index.js
|   |   ├── articles.js
|   └── 2.0 <-- major version
|       ├── index.js
|       ├── articles.js
|       ├── users.js
|       └── logs.js
├── worker <-- Service worker database
|   └── 1.0
|       ├── index.js <-- entry file to execute migrations
|       ├── job.js
|── api.js <-- API configuration file
└── worker.js <-- Service worker configuration file

This would result in the following execution workflow :

File structure evolution

Every collections are migrated inside the entrypoint index.js.

img1

Collections now have their own file and are executed from the entrypoint.

img2

Collections now have their own folder with files, each file is attributed to a nested collection (e.g: Tokens for Users). Users and Tasks are now groups of migrations.

img3

Execution order & middlewares

The index file for each migration version is intended to register the version and execute all migrations.

This allows you to choose the execution order and add some actions between migrations.

// Import collections mirgations
import users from './users';
import articles from './articles';
import logs from './logs';
import tags from './tags';

export default {
  version: 1.0,
  describe: 'Init collections',
  up: async ({ Migrate }) => {
    // ... do something

    await Migrate([articles, logs, users, tags]);

    // ... do something
  },
  down: async ({ Migrate }) => {
    await Migrate([articles, logs, users, tags]);
  },
};

Warning: every single arguments passed to Migrate() must be a valid migration object.

← TroubleshootingBabel usage →
  • File structure
    • File structure evolution
  • Execution order & middlewares
Underbase
Guides
Working with backupsWorking with continuous deploymentAPI Reference
Community
Stack OverflowIssues tracker
More
Release notesGitHub