コード例 #1
0
ファイル: down_test.go プロジェクト: wawandco/transporter
func TestDownBadMigration(t *testing.T) {
	for dname, man := range mans {
		utils.ClearTestTables(dname)
		utils.ClearTestMigrations()
		utils.SetupTestingFolders(dname)

		firstID := transporter.MigrationIdentifier()
		lastID := transporter.MigrationIdentifier()

		utils.GenerateMigrationFiles([]utils.TestMigration{
			utils.TestMigration{
				Identifier:  firstID,
				UpCommand:   "CREATE TABLE down_table (a varchar(255))",
				DownCommand: "DROP TABLE down_table",
			},
			utils.TestMigration{
				Identifier:  lastID,
				UpCommand:   "ALTER TABLE down_table ADD COLUMN o varchar(255)",
				DownCommand: "WUHdnns oius (Bad mig!);",
			},
		})

		context := cli.NewContext(nil, &flag.FlagSet{}, nil)
		Up(context)
		Down(context)

		con, _ := utils.BuildTestingConnection(dname)
		transporter.SetManager(man)

		version := transporter.DatabaseVersion(con)
		assert.Equal(t, version, strconv.FormatInt(lastID, 10))
		defer con.Close()
	}
}
コード例 #2
0
ファイル: up_test.go プロジェクト: wawandco/transporter
func TestUpBadMigration(t *testing.T) {
	for dname := range mans {
		utils.ClearTestTables(dname)
		utils.ClearTestMigrations()
		utils.SetupTestingFolders(dname)

		utils.GenerateMigrationFiles([]utils.TestMigration{
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "Create table other_table (a varchar(255) );",
				DownCommand: "Drop Table other_table;",
			},
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "Alter table shshshshs other_table add column o varchar(12);",
				DownCommand: "Drop column Wihii;",
			},
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "Alter table other_table drop column a;",
				DownCommand: "",
			},
		})

		context := cli.NewContext(nil, &flag.FlagSet{}, nil)
		Up(context)

		con, _ := utils.BuildTestingConnection(dname)
		_, err := con.Query("Select a from other_table;")
		assert.Nil(t, err)
	}
}
コード例 #3
0
ファイル: down_test.go プロジェクト: wawandco/transporter
func TestDown(t *testing.T) {
	for dname := range mans {
		utils.ClearTestTables(dname)
		utils.ClearTestMigrations()
		utils.SetupTestingFolders(dname)

		utils.GenerateMigrationFiles([]utils.TestMigration{
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "CREATE TABLE down_table (a varchar(255))",
				DownCommand: "DROP TABLE down_table",
			},
			utils.TestMigration{
				Identifier:  transporter.MigrationIdentifier(),
				UpCommand:   "ALTER TABLE down_table ADD COLUMN o varchar(255)",
				DownCommand: "ALTER TABLE down_table DROP COLUMN o",
			},
		})

		context := cli.NewContext(nil, &flag.FlagSet{}, nil)
		Up(context)
		Down(context)

		con, _ := utils.BuildTestingConnection(dname)
		defer con.Close()

		_, err := con.Query("SELECT a FROM down_table")
		assert.Nil(t, err)

		Down(context)

		_, err = con.Query("SELECT a FROM down_table")
		log.Println(err)
		assert.NotNil(t, err)
	}
}
コード例 #4
0
ファイル: common.go プロジェクト: wawandco/transporter
	"github.com/wawandco/transporter/core"
	"github.com/wawandco/transporter/managers"
)

//MainData is the data passed to generate the main.go when running Up and Down.
type MainData struct {
	TempDir        string
	Environment    string
	DatabaseURL    string
	DatabaseDriver string
}

var sampleMigrations = []core.Migration{
	core.Migration{
		Identifier: core.MigrationIdentifier(),
		Up: func(tx *core.Tx) {
			tx.Exec("Create table tests_table (a varchar);")
		},
		Down: func(tx *core.Tx) {
			tx.Exec("Drop table tests_table;")
		},
	},

	core.Migration{
		Identifier: core.MigrationIdentifier(),
		Up: func(tx *core.Tx) {
			tx.Exec("ALTER table tests_table ADD COLUMN other varchar(20);")
		},
		Down: func(tx *core.Tx) {
			tx.Exec("ALTER table tests_table DROP COLUMN other;")