コード例 #1
0
ファイル: main.go プロジェクト: blendlabs/spiffy
func createTable() error {
	m := migration.New(
		"create `test_object` table",
		migration.Step(
			migration.AlterTable,
			migration.Body(
				`DROP TABLE IF EXISTS test_object`,
			),
			"test_object",
		),
		migration.Step(
			migration.CreateTable,
			migration.Body("CREATE TABLE test_object (id serial not null, uuid varchar(64) not null, created_utc timestamp not null, updated_utc timestamp, active boolean, name varchar(64), variance float)"),
			"test_object",
		),
	)
	return m.Apply(spiffy.DefaultDb())
}
コード例 #2
0
ファイル: main.go プロジェクト: blendlabs/spiffy
func main() {
	err := spiffy.SetDefaultDb(spiffy.NewDbConnectionFromEnvironment())
	if err != nil {
		log.Fatal(err)
	}

	m := migration.New(
		"create & fill `test_vocab`",
		migration.New(
			"create `test_vocab` table",
			migration.Step(
				migration.CreateTable,
				migration.Body(
					"CREATE TABLE test_vocab (id serial not null, word varchar(32) not null);",
					"ALTER TABLE test_vocab ADD CONSTRAINT pk_test_vocab_id PRIMARY KEY(id);",
				),
				"test_vocab",
			),
		),
		migration.New(
			"fill `test_vocab`",
			migration.ReadDataFile("data.sql"),
		),
		migration.New(
			"drop `test_vocab` table",
			migration.Step(
				migration.AlterTable,
				migration.Body(
					"DROP TABLE test_vocab;",
				),
				"test_vocab",
			),
		),
	)
	m.SetLogger(migration.NewLogger())
	m.SetShouldAbortOnError(true)
	err = m.Apply(spiffy.DefaultDb())
	if err != nil {
		log.Fatal(err)
	}
}