• Stars
    star
    9
  • Rank 1,878,587 (Top 39 %)
  • Language
    Crystal
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A database migration tool written in Crystal

migrō

(Latin) migrate

A relational database migration tool, written in Crystal. It uses the cql framework.

Installation

Requirements:

  • Crystal (currently built & tested using 0.24.1)
Clone this repository
git clone https://github.com/aisrael/migro.git
cd migro

Run the tests

To run the tests, we use Docker + Compose to bring up a PostgreSQL environment. First go:

docker-compose up

Then, in another terminal

DATABASE_URL=postgres://migro:secret@localhost/migro_test crystal spec
Build the executable and place it in your $PATH
shards build --release

That will build bin/migro. Copy that file anywhere in your $PATH

Usage

migro expects database migrations to be in db/migrations (relative to the current directory).

Migration files can be named using one of the following patterns:

  • text_only.yml - text only, will be executed before everything else (in alphabetical order)
  • 001_some_text.yml, 201802240803-some-text.yml - numeric prefix plus text, will be executed in order of the numeric prefix first, then alphabetical order if same numeric prefix

Migration files

migro currently only supports YAML migrations of the form

metadata:
  version: 0.1
changes:
  - create_table:
    name: users
    columns:
    - name: id
      type: SERIAL
      null: false
      primary: true
    - name: username
      type: VARCHAR
      size: 40
      null: false
    - name: password_hash
      type: CHAR
      size: 128
      null: false
up:
  - insert:
      table: users
      rows:
        - username: system
        - password_hash: b37e50cedcd3e3f1ff64f4afc0422084ae694253cf399326868e07a35f4a45fb

Which is equivalent to running the following SQL commands:

CREATE TABLE users (id SERIAL NOT NULL PRIMARY KEY, username VARCHAR(40) NOT NULL, password_hash CHAR(128) NOT NULL);
INSERT INTO users (username, password_hash) VALUES ('system', 'b37e50cedcd3e3f1ff64f4afc0422084ae694253cf399326868e07a35f4a45fb');

Development

TODO:

  • Support for .sql migrations ala micrate
  • Improved CLI, e.g. migro up, migro down, migro rollback --to 042-some.yml

Contributing

  1. Fork it ( https://github.com/aisrael/migro/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • aisrael Alistair A. Israel - creator, maintainer

More Repositories

1

elixir-phoenix-typescript-react

An example repository demonstrating Elixir with Phoenix 1.6, TypeScript, and React
Elixir
52
star
2

junit-rules

Provides a set of rules that showcase JUnit's @Rule functionality
Java
24
star
3

psgc

PSGC (Philippine Standard Geographic Code) Ruby gem
Ruby
10
star
4

rust-closures-futures-async-await

The accompanying source code my series of articles at https://bit.ly/2WHhzZ3
Rust
8
star
5

docker_all_the_things

A repository of Docker builds of representative apps (CLI, API, Web) in multiple languages
Ruby
6
star
6

ansibler

A Ruby gem for reading and writing Ansible files.
Ruby
6
star
7

jcombinatorics

JCombinatorics provides useful combinatorics algorithms (permutations & combinations) and functions for Java.
Java
6
star
8

cql

A SQL toolkit for Crystal, inspired by Java's jOOQ and Ruby's Sequel gem
Crystal
5
star
9

tweeter

An Elixir application showcasing Phoenix, GraphQL (absinthe), CQRS + ES, and React
Elixir
4
star
10

elixir-phoenix-svelte

An example repository demonstrating Elixir + Phoenix 1.7 with Svelte
Elixir
4
star
11

tweeter-rails

A Kubernetes demo Rails app
Ruby
4
star
12

crystal-amber-docker

Sample project demonstrating a Crystal + Amber Web application packaged in a minimal Docker container
Crystal
4
star
13

chronos

A J2EE application server independent Quartz console and bootstrap mechanism
JavaScript
3
star
14

hyper-example

Example HTTP Service written using Rust + hyper
Rust
3
star
15

ceph-rs

A Rust library for Ceph (currently, librados only)
Rust
2
star
16

doggo

doggo is a good boi. doggo is a Datadog CLI client written in Rust, that can be statically compiled, suitable for use in e.g. alpine or busybox images (am looking at you, kaniko!)
Rust
2
star
17

rails_react_redux_sample

Rails 5 + browserify + React + Redux sample app, based on the guide at http://redux.js.org/docs/basics/UsageWithReact.html
Ruby
1
star
18

msgpax_helper

A small library that provides an opionated wrapper around Msgpax to help encode/decode Elixir Date and NaiveDateTime data
Elixir
1
star
19

messenger-platform-sample-ruby

Messenger Platform sample in Ruby for sending and receiving messages. Based on the sample app at the Facebook Messenger Platform Getting Started Guide: https://developers.facebook.com/docs/messenger-platform/quickstart
Ruby
1
star
20

maru_espec_tesla

A sample Elixir project that uses maru to serve an HTTP service, and espec and tesla to test the service
Elixir
1
star
21

juniper-hyper-demo

Sample code for a GraphQL server using juniper + hyper
Rust
1
star
22

vagrant-ceph

Shell
1
star
23

xlsx_to_k8s_network_policy

SDN (Spreadsheet Defined Networking)! A Ruby gem to convert an Excel file to a Kubernetes NetworkPolicy YAML definition
Ruby
1
star
24

memory_eater

A small C program and Dockerfile that will keep trying to allocate memory until it exhausts available memory. Used to exercise and demonstrate `cgroups` and Docker/Kubernetes container resource limits. Also acts as an example for Docker multi-stage builds.
C
1
star
25

docker-packer

A Packer project that builds Ubuntu 'Trusty' 14.04 LTS with Docker 1.4.x, primarily for use in Vagrant + Virtualbox, to be able to run the docker client natively on OS X.
Shell
1
star