Database schema evolution library for Go

Build Status Go Report Card GoDoc

Try browsing the code on Sourcegraph!

Darwin

Database schema evolution library for Go

Example

package main

import (
	"database/sql"
	"log"

	"github.com/GuiaBolso/darwin"
	_ "github.com/go-sql-driver/mysql"
)

var (
	migrations = []darwin.Migration{
		{
			Version:     1,
			Description: "Creating table posts",
			Script: `CREATE TABLE posts (
						id INT 		auto_increment, 
						title 		VARCHAR(255),
						PRIMARY KEY (id)
					 ) ENGINE=InnoDB CHARACTER SET=utf8;`,
		},
		{
			Version:     2,
			Description: "Adding column body",
			Script:      "ALTER TABLE posts ADD body TEXT AFTER title;",
		},
	}
)

func main() {
	database, err := sql.Open("mysql", "root:@/darwin")

	if err != nil {
		log.Fatal(err)
	}

	driver := darwin.NewGenericDriver(database, darwin.MySQLDialect{})

	d := darwin.New(driver, migrations, nil)
	err = d.Migrate()

	if err != nil {
		log.Println(err)
	}
}

Questions

Q. Why there is not a command line utility?

A. The purpose of this library is just be a library.

Q. How can I read migrations from file system?

A. You can read with the standard library and build the migration list.

Q. Can I put more than one statement in the same Script migration?

A. I do not recommend. Put one database change per migration, if some migration fail, you exactly what statement caused the error. Also only postgres correctly handle rollback in DDL transactions.

To be less annoying you can organize your migrations like? 1.0, 1.1, 1.2 and so on.

Q. Why does not exists downgrade migrations?

A. Please read https://flywaydb.org/documentation/faq#downgrade

Q. Does Darwin perform a roll back if a migration fails?

A. Please read https://flywaydb.org/documentation/faq#rollback

Q. What is the best strategy for dealing with hot fixes?

A. Plese read https://flywaydb.org/documentation/faq#hot-fixes

LICENSE

The MIT License (MIT)

Copyright (c) 2016 Claudemiro

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Similar Resources

goydb, a couchdb compatible embeddable database written in go

goydb, a couchdb compatible embeddable database written in go

goydb, a couchdb compatible embeddable database written in go Getting started (not embedded) Using docker mkdir data docker run -e GOYDB_ADMINS=admin:

Sep 14, 2022

A simple database migration tool using an sql.DB connection and fs.FS for the migration source

A simple database migration tool using an sql.DB connection and fs.FS for the migration source. It has no non-test dependencies.

Dec 7, 2022

mini tools handling migrasion database from cli

mini tools handling migrasion database from cli

Dec 13, 2021

Opinionated tool for database structure management and migrations

trek Requirements At least version 13 of postgres is needed. Installation go install . Setup Create config.yaml: model_name: model_name db_name: db

Dec 14, 2022

Database migration through structures - development

goMigration 基于 Golang 的数据库迁移工具,目前仍在开发中,有兴趣的小伙伴可以联系我一起~ 食用方法 go get https://github.com/DGuang21/goMigration 手动将其安装 可通过 gom gen create_c_user_table 方法生

Dec 2, 2021

A database migration tool written in Go.

dbmagritte created by Austin Poor A database migration tool written in Go. Usage Commands: init: Set up the repo by creating a .dbmagritte.yaml file a

Jan 29, 2022

A migration engine to deploy database changes in your golang + mongodb app.

bisonmigration A migration engine to deploy database changes in your golang + mongodb app. Migration files register their UP and DOWN functions in the

Jan 30, 2022

Open Sound Control (OSC) library for Golang. Implemented in pure Go.

GoOSC Open Sound Control (OSC) library for Golang. Implemented in pure Go. This repository is a heavily modified fork of the original go-osc. Please c

Dec 22, 2021

SampleD - scalable sample collection, routing, and schema evolution

SampleD Realtime event analytics capture and processor Emit samples from your application code (libraries provided) Configure fluentbit to capture sam

Dec 7, 2022

A tool to compare if terraform provider migration schema snapshot is equal to schema defined in resource code

migration schema comparer for Terraform When develop Terraform provider sometimes we need do some state migration(not schema migration) via StateUpgra

Nov 18, 2021

Schema - JSON Schema rules plugin

This plugin allows to configure JSON Schema validations rules ensuring user-submitted records adhere to a pre-defined data schema.

Feb 16, 2022

Evolutionary optimization library for Go (genetic algorithm, partical swarm optimization, differential evolution)

Evolutionary optimization library for Go (genetic algorithm, partical swarm optimization, differential evolution)

eaopt is an evolutionary optimization library Table of Contents Changelog Example Background Features Usage General advice Genetic algorithms Overview

Dec 30, 2022

Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers.

Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers. It is a stand

Jan 1, 2023

golife is a cell evolution simulator.

golife is a cell evolution simulator.

golife WORK IN PROGRESS golife is a cell evolution simulator. It presents autonomous organism with inner properties and behavior (hunter or prey) that

Dec 30, 2021

Generate a Go ORM tailored to your database schema.

Generate a Go ORM tailored to your database schema.

SQLBoiler is a tool to generate a Go ORM tailored to your database schema. It is a "database-first" ORM as opposed to "code-first" (like gorm/gorp). T

Jan 2, 2023

Schema-free, document-oriented streaming database that optimized for monitoring network traffic in real-time

Basenine Schema-free, document-oriented streaming database that optimized for monitoring network traffic in real-time. Featured Aspects Has the fastes

Nov 2, 2022

Generate a Go ORM tailored to your database schema.

Generate a Go ORM tailored to your database schema.

SQLBoiler is a tool to generate a Go ORM tailored to your database schema. It is a "database-first" ORM as opposed to "code-first" (like gorm/gorp). T

Jan 9, 2023

Web-based, zero-config, dependency-free database schema change and version control tool for teams

Web-based, zero-config, dependency-free database schema change and version control tool for teams

Live Demo • Install • Help • Development • Design Doc Bytebase is a web-based, zero-config, dependency-free database schema change and version control

Jan 1, 2023

Go library that stores data in Redis with SQL-like schema

Go library that stores data in Redis with SQL-like schema. The goal of this library is we can store data in Redis with table form.

Mar 14, 2022
Comments
  • Update dependency to its canonical name

    Update dependency to its canonical name

    The author of the DATADOG package has requested users to use the github.com name. This is documented in the module file for the project. This change will allow the module tooling to use the latest version of the package without the need for developers to issue replace calls.

  • Add Dialect implementation for ql database

    Add Dialect implementation for ql database

    This adds Dialect implementation for the go embedded sql database

    https://github.com/cznic/ql

    SIDE NOTE I stumbled on this project just a few mins ago, the name is awesome just like the project itself. I inlcuded test for the implementation which uses in memory database.

  • No insight on which migration is failing

    No insight on which migration is failing

    Hello, thanks for the tool, we chose it a few months ago for handling our migrations and it really eased the process of keeping our DBs up to date.

    That being said, when an error occurs on running migrations, error messages don't enable us to find easily which migrations were being run. Do you think it could be improved ? I would not mind working on it if you cannot provide the worktime ;)

    Cheers Julien

  • Sample Implementation

    Sample Implementation

    I really like this migration library (and I've tried several). My only complaint was getting started. I thought it might help others to share the approach I took.

    I used a x.xx database versioning approach, but took the extra step to "minify" the script before including it in the migration. This allowed simple formatting and comment changes to be made (after release) without causing checksum errors.

    Each migration step is a variable (with all steps of a major version defined inside a variable group for easy code folding).

    I wanted to show the current database version with a before and after version if migrations were applied. Something like this:

    DB Version: 2.01 (migrated from 1.03 to 2.01)
    

    But I didn't want to perform an Info() call twice just to get the last version each time (it returns all migrations from the database).

    I also wanted to provide a detailed error message if a migration failed. I do this with the very convenient info channel feature.

    Here is the what I ended up with:

    https://gist.github.com/dougwinsby/48db699dadaee6f9d8e80ea692bb4c79

    Hope it helps someone.

Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers.

Dbmate is a database migration tool, to keep your database schema in sync across multiple developers and your production servers. It is a stand

Jan 1, 2023
Schema management CLI for MySQL
Schema management CLI for MySQL

Skeema is a tool for managing MySQL tables and schema changes in a declarative fashion using pure SQL. It provides a CLI tool allowing you to: Export

Dec 27, 2022
SQL schema migration tool for Go.

sql-migrate SQL Schema migration tool for Go. Based on gorp and goose. Using modl? Check out modl-migrate. Features Usable as a CLI tool or as a libra

Jan 2, 2023
GitHub's Online Schema Migrations for MySQL
GitHub's Online Schema Migrations for MySQL

gh-ost GitHub's online schema migration for MySQL gh-ost is a triggerless online schema migration solution for MySQL. It is testable and provides paus

Apr 3, 2020
Django style fixtures for Golang's excellent built-in database/sql library.

go-fixtures Django style fixtures for Golang's excellent built-in database/sql library. Currently only YAML fixtures are supported. There are two rese

Sep 26, 2022
Database migrations. CLI and Golang library.

migrate Database migrations written in Go. Use as CLI or import as library. Migrate reads migrations from sources and applies them in correct order to

Dec 31, 2022
Dead simple Go database migration library.
Dead simple Go database migration library.

migrator Dead simple Go database migration library. Features Simple code Usage as a library, embeddable and extensible on your behalf Support of any d

Nov 9, 2022
Database migrations. CLI and Golang library.

Database migrations written in Go. Use as CLI or import as library.

May 30, 2021
Goose database migration tool - fork of https://bitbucket.org/liamstask/goose

goose Goose is a database migration tool. Manage your database schema by creating incremental SQL changes or Go functions. Goals of this fork github.c

Dec 30, 2022
Minimalistic database migration helper for Gorm ORM

Gormigrate Gormigrate is a minimalistic migration helper for Gorm. Gorm already has useful migrate functions, just misses proper schema versioning and

Dec 25, 2022