func AutoMigrate(db *gorm.DB, givenTables ...interface{}) {
	for _, table := range givenTables {
		db.AutoMigrate(table)
		if migratable, ok := table.(Migratable); ok {
			exec(func() error { return migratable.AfterMigrate(db) })
		}
	}
}
AutoMigrate receives table arguments and create or update their
table structure in database.
package utils
import (
	"fmt"
	"os"
	_ "github.com/go-sql-driver/mysql"
	"github.com/jinzhu/gorm"
	_ "github.com/lib/pq"
)
func TestDB() *gorm.DB {
	var db *gorm.DB
	var err error
	var dbuser, dbpwd, dbname, dbhost = "qor", "qor", "qor_test", "localhost"
	if os.Getenv("DB_USER") != "" {
		dbuser = os.Getenv("DB_USER")
	}
	if os.Getenv("DB_PWD") != "" {
		dbpwd = os.Getenv("DB_PWD")
	}
	if os.Getenv("DB_NAME") != "" {
		dbname = os.Getenv("DB_NAME")
	}
	if os.Getenv("DB_HOST") != "" {
		dbhost = os.Getenv("DB_HOST")
	}
	if os.Getenv("TEST_DB") == "mysql" {
		db, err = gorm.Open("mysql", fmt.Sprintf("%s:%s@/%s?charset=utf8&parseTime=True&loc=Local", dbuser, dbpwd, dbname))
	} else {
		db, err = gorm.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=disable", dbuser, dbpwd, dbhost, dbname))
	}
	if err != nil {
		panic(err)
	}
	if os.Getenv("DEBUG") != "" {
		db.LogMode(true)
	}
	return db
}
var db *gorm.DB
func GetTestDB() *gorm.DB {
	if db != nil {
		return db
	}
	db = TestDB()
	return db
}
func PrepareDBAndTables(tables ...interface{}) *gorm.DB {
	db := GetTestDB()
	ResetDBTables(db, tables...)
	return db
}
func ResetDBTables(db *gorm.DB, tables ...interface{}) {
	Truncate(db, tables...)
	AutoMigrate(db, tables...)
}
func Truncate(db *gorm.DB, givenTables ...interface{}) {
	len := len(givenTables)
	for i := range givenTables {
		table := givenTables[len-i-1]
		db.DropTableIfExists(table)
	}
}