func RunMigrations(db *gorm.DB) error {
	migrations := make([]func() error, numMigrations)
	migrations[0] = func() error {  
		return autoMigrateTables(db,
			&models.ServiceInstanceDetailsV1{},
			&models.ServiceBindingCredentialsV1{},
			&models.ProvisionRequestDetailsV1{},
			&models.PlanDetailsV1{},
			&models.MigrationV1{})
	}
	migrations[1] = func() error {  
		return autoMigrateTables(db, &models.CloudOperationV1{})
	}
	migrations[2] = func() error {  
		return nil
	}
	migrations[3] = func() error {  
		return autoMigrateTables(db, &models.ServiceInstanceDetailsV2{})
	}
	migrations[4] = func() error {  
		return autoMigrateTables(db, &models.TerraformDeploymentV1{})
	}
	migrations[5] = func() error {  
		return autoMigrateTables(db, &models.ProvisionRequestDetailsV2{})
	}
	migrations[6] = func() error {  
		if db.Dialect().GetName() == "sqlite3" {
			return nil
		} else {
			return db.Model(&models.ProvisionRequestDetailsV2{}).ModifyColumn("request_details", "text").Error
		}
	}
	var lastMigrationNumber = -1
	if db.HasTable("migrations") {
		var storedMigrations []models.Migration
		if err := db.Order("migration_id desc").Find(&storedMigrations).Error; err != nil {
			return fmt.Errorf("Error getting last migration id even though migration table exists: %s", err)
		}
		lastMigrationNumber = storedMigrations[0].MigrationId
	}
	if err := ValidateLastMigration(lastMigrationNumber); err != nil {
		return err
	}
	for i := lastMigrationNumber + 1; i < len(migrations); i++ {
		tx := db.Begin()
		err := migrations[i]()
		if err != nil {
			tx.Rollback()
			return err
		} else {
			newMigration := models.Migration{
				MigrationId: i,
			}
			if err := db.Save(&newMigration).Error; err != nil {
				tx.Rollback()
				return err
			} else {
				tx.Commit()
			}
		}
	}
	return nil
}
runs schema migrations on the provided service broker database to get it up to date
package db_service
import (
	"errors"
	"fmt"
	"github.com/GoogleCloudPlatform/gcp-service-broker/db_service/models"
	"github.com/jinzhu/gorm"
)
const numMigrations = 7