All Projects → igorkamyshev → trona

igorkamyshev / trona

Licence: MIT license
Write DB migrations with SQL and run them with a CLI

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to trona

EvoNet
Evolution Simulation in XNA Refresh
Stars: ✭ 44 (+41.94%)
Mutual labels:  evolution
typescript-api-starter
🔰 Starter for Node.js express API in Typescript 🚀
Stars: ✭ 72 (+132.26%)
Mutual labels:  migration
Squeaky-Android
Appropriately lightweight database creations and migrations with SQLite on Android
Stars: ✭ 34 (+9.68%)
Mutual labels:  migration
butterfly
Application transformation tool
Stars: ✭ 35 (+12.9%)
Mutual labels:  migration
flickr to google photos migration
A tool for migrating your photo library from Flickr to Google Photos
Stars: ✭ 39 (+25.81%)
Mutual labels:  migration
schema-builder
Laravel/Lumen schema builder & migration generator
Stars: ✭ 51 (+64.52%)
Mutual labels:  migration
great-migration
Copy objects from Rackspace to S3
Stars: ✭ 15 (-51.61%)
Mutual labels:  migration
mgmigrate
mgmigrate is a tool for migrating data from MySQL or PostgreSQL to Memgraph and between Memgraph instances.
Stars: ✭ 17 (-45.16%)
Mutual labels:  migration
mik
The Move to Islandora Kit is an extensible PHP command-line tool for converting source content and metadata into packages suitable for importing into Islandora (or other digital repository and preservations systems).
Stars: ✭ 32 (+3.23%)
Mutual labels:  migration
gitlab to gitea
Gitlab to Gitea migration script.
Stars: ✭ 54 (+74.19%)
Mutual labels:  migration
porter
Export legacy forums into a format Vanilla Forums can import.
Stars: ✭ 39 (+25.81%)
Mutual labels:  migration
mongock
Lightweight Java based migration tool
Stars: ✭ 357 (+1051.61%)
Mutual labels:  migration
sprockets-bumble d
Sprockets plugin to transpile modern javascript using Babel, useful while migrating to ES6 modules
Stars: ✭ 32 (+3.23%)
Mutual labels:  migration
citylines
Citylines.co is a collaborative platform for mapping the transit systems of the world!
Stars: ✭ 53 (+70.97%)
Mutual labels:  evolution
DeepHyperNEAT
A public python implementation of the DeepHyperNEAT system for evolving neural networks. Developed by Felix Sosa and Kenneth Stanley. See paper here: https://eplex.cs.ucf.edu/papers/sosa_ugrad_report18.pdf
Stars: ✭ 42 (+35.48%)
Mutual labels:  evolution
amazon-s3-data-replication-hub-plugin
The Amazon S3 Transfer Plugin for Data Transfer Hub(https://github.com/awslabs/data-transfer-hub). Transfer objects from S3(in other partition), Alibaba Cloud OSS, Tencent COS, Qiniu Kodo into Amazon S3.
Stars: ✭ 32 (+3.23%)
Mutual labels:  migration
go-echo-boilerplate
The fastest way to build a restful API with golang and echo framework. Includes common required features for modern web applications. A boilerplate project with golang and Echo.
Stars: ✭ 53 (+70.97%)
Mutual labels:  migration
rails async migrations
Asynchronous support for ActiveRecord::Migration
Stars: ✭ 56 (+80.65%)
Mutual labels:  migration
maildir2gmail
Maildir 2 Gmail
Stars: ✭ 14 (-54.84%)
Mutual labels:  migration
git-history-flow
Visualize the evolution of a file tracked by git
Stars: ✭ 17 (-45.16%)
Mutual labels:  evolution

trona

This library allows you to write migration scenarios using SQL and run them with a simple CLI.

  • Simple: only plain SQL
  • Lightweight: only 5.6 kB in node_modules
  • Modern: ESM support out of the box

Usage example

foo@bar:~$ yarn trona

Running evolve script

--- 1.sql ---

CREATE TABLE Customers (
    id   INTEGER     NOT NULL,
    name VARCHAR(32) NOT NULL,
    primary key (id)
);

Evolution is successful!

foo@bar:~$

Installation

First you need to install trona via package manager:

yarn add trona

Configuration

Then you need to setup simple configuration file named .trona-config.js and containing script that exports async function runQuery. The function should be rejected in case of failure of said query and in case of SELECT query successfully executed returns array of selected rows in form of an object {[field]: value}.

PostgreSQL example

import PG from 'pg';

const client = new PG.Client({
  // ...
});

await client.connect();
console.log(`Connected to database`);

export function runQuery(query) {
  return client.query(query).then((result) => result.rows);
}

MySQL example

import mysql from 'mysql';
import { promisify } from 'util';

const connection = mysql.createConnection({
  // ...
});

const connect = promisify(connection.connect).bind(connection);
const runQuery = promisify(connection.query).bind(connection);

await connect();
console.log(`Connected to database`);

export { runQuery };

Write evolutions

Create a folder evolutions for your evolutions script and add your first evolution to it. Note the rules which you should follow writing said evolutions:

  1. Name file {evolution-number}-{text}.sql. Text part -{text} is optional and can be omitted (e.g. both 1.sql and 1-create-table.sql are correct). Note: file name should always start with number. Evolution script file with any other symbol will be ignored (e.g. *1-incorrect.sql or -1-worng.sql) and warning will be shown during execution.
  2. Complement evolution file with fallback scripts. Separate evolution and fallback scripts with "#DOWN" comment as it show in example below.
  3. Execution will not be started in case of any conflict of numbering is found (e.g. existing any of two: 1-abba.sql, 1-baab.sql, 1.sql, 1-baba.sql)

Folder content example:

- evolutions
    - 1.sql
    - 2.sql
    - 3.sql
    ...

Evolution contents example:

CREATE TABLE Customers (
    id   INTEGER     NOT NULL,
    name VARCHAR(32) NOT NULL,
    primary key (id)
);

#DOWN

DROP TABLE Customers;

Run command

yarn trona

This command will create table with information about evolutions, if it doesn't exist. After it will execute all your evolutions.

Usage

After you managed to successfully setup trona you can run yarn trona command. This command will automatically detect any changed or new files in your evolutions folder, run respected fallback scripts if needed and than evolve your databae schema (e. g. if you have 1.sql, 2.sql, and 3.sql evolutions already in your database, you have changed 2.sql and added 4.sql it will run fallback for 3.sql and 2.sql and then run 2.sql, 3.sql, and 4.sql scripts)

Options

Interactivity

By default evolution script will ask for a confirmation to run a degrade script. You can disable this feature by -y or --no-interactive flag.

yarn trona -y

Config

You can change path to trona config file by providing -c or --config-path option (by default trona will try to find config file .trona-config.js in a root directory).

yarn trona -c config/.trona-my-config.js

Custom evolutions folder

Custom evolutions folder can be choosen by providing -d or --evolutions-dir option. By default evolutions folder is being used.

yarn trona -d migrations

Maintenance

Release flow

  1. Bump version in package.json
  2. Fill CHANGELOG.md
  3. Commit changes by git commin -m "Release X.X.X"
  4. Create git tag for release by git tag -a vX.X.X -m "vX.X.X"
  5. Push changes to remote by git push --follow-tags
  6. Release package to registry by yarn clean-publish
  7. Fill release page with changelog on GitHub
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].