Giter Club home page Giter Club logo

go-migrate-sample's Introduction

Go Migrate Sample

golang-migrate/migrateを使ったマイグレーションです。

セットアップ

$ openssl rand -base64 756 > replicaset.key
$ chmod 600 replicaset.key
$ chown 999 replicaset.key

mongosh を開く。

docker exec -it go_migrate_mongo_primary bash
mongosh -u root -p root

レプリカセットの初期化

rs.initiate({
  _id: "rs0",
  members: [
    { _id: 0, host: "go_migrate_mongo_primary:27017", priority: 3 },
    { _id: 1, host: "go_migrate_mongo_secondary:27017", priority: 2 },
    { _id: 2, host: "go_migrate_mongo_tertiary:27017", priority: 1 },
    { _id: 3, host: "go_migrate_mongo_arbiter:27017", arbiterOnly: true },
  ],
})

確認用コマンド

rs.status()
rs.conf()

マイグレーション

# 最新化
migrate -path ./migrations -database "mongodb://localhost:27017/testdb?directConnection=true" up

# 1つだけバージョンアップ
migrate -path ./migrations -database "mongodb://localhost:27017/testdb?directConnection=true" up 1

バージョンダウン

migrate -path ./migrations -database "mongodb://localhost:27017/testdb?directConnection=true" down 1

dirty 状態の解消

migrate -path ./migrations -database "mongodb://localhost:27017/testdb?directConnection=true" force 1

参考

https://zenn.dev/ytdrep/articles/217e3aeeadd07c

go-migrate-sample's People

Contributors

taako-502 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.