Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/GuiaBolso/darwin
Database schema evolution library for Go
https://github.com/GuiaBolso/darwin
database go golang migration
Last synced: about 2 months ago
JSON representation
Database schema evolution library for Go
- Host: GitHub
- URL: https://github.com/GuiaBolso/darwin
- Owner: GuiaBolso
- License: mit
- Created: 2016-04-05T15:57:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-24T17:39:33.000Z (almost 2 years ago)
- Last Synced: 2024-07-31T20:49:35.702Z (5 months ago)
- Topics: database, go, golang, migration
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 145
- Watchers: 4
- Forks: 34
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - darwin - Database schema evolution library for Go. (Database / Database Schema Migration)
- awesome-go-storage - darwin - Database schema evolution library for Go (Database)
- awesome-go - darwin - Database schema evolution library for Go - ★ 71 (Database)
- awesome-go-extra - darwin - 04-05T15:57:59Z|2021-03-24T15:22:39Z| (Generators / Database Schema Migration)
- awesome-go-storage - darwin - Database schema evolution library for Go (Database)
README
[![Build Status](https://travis-ci.org/GuiaBolso/darwin.svg?branch=master)](https://travis-ci.org/GuiaBolso/darwin)
[![Go Report Card](https://goreportcard.com/badge/github.com/GuiaBolso/darwin)](https://goreportcard.com/report/github.com/GuiaBolso/darwin)
[![GoDoc](https://godoc.org/github.com/GuiaBolso/darwin?status.svg)](https://godoc.org/github.com/GuiaBolso/darwin)Try browsing [the code on Sourcegraph](https://sourcegraph.com/github.com/GuiaBolso/darwin)!
# Darwin
Database schema evolution library for Go
# Example
```go
package mainimport (
"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.