github.com/mmatczuk/gohan@v0.0.0-20170206152520-30e45d9bdb69/examples/db_migration/README.md (about) 1 DB migration example 2 --------------------- 3 4 We show how we can use db versioing with Gohan. 5 Bascially, Gohan won't create table if it has already exist. 6 so you can use any DB migration tool. 7 8 However, Gohan provides helper utility to generate migration file. 9 10 Step1 11 ------- 12 13 Prepare goose configuraion file. 14 We have a example in db/dbconf.yml 15 16 ``` yaml 17 development: 18 driver: sqlite3 19 open: ./gohan.db 20 ``` 21 22 Step2 23 -------- 24 25 Generate initial migration file 26 27 ``` shell 28 gohan migrate -path db/migrations/ --schema example_schema.yaml 29 ``` 30 31 Step3 32 -------- 33 34 apply goose file 35 36 ``` shell 37 $ goose up 38 goose: migrating db environment 'development', current version: 0, target: 20151110132025 39 OK 20151110132025_init_schema.sql 40 41 ``` 42 43 Step4 44 --------- 45 46 Update schema 47 48 49 Step4 50 --------- 51 52 Add goose migration code in db/migrations. 53 Note that Gohan can't produce goose file from diff of schema, so you need 54 to write it. 55 56 ``` 57 -- +goose Up 58 CREATE TABLE post ( 59 id int NOT NULL, 60 title text, 61 body text, 62 PRIMARY KEY(id) 63 ); 64 65 -- +goose Down 66 DROP TABLE post; 67 ``` 68 69 Step5 70 ---------- 71 72 Keep goose up