Beispiel #1
0
func createOldMigrationFile(url, migrationsPath string) error {
	version := file.Version(20060102150405)
	filenamef := "%d_%s.%s.%s"
	name := "old"
	d, err := driver.New(url)
	if err != nil {
		return err
	}

	mfile := &file.MigrationFile{
		Version: version,
		UpFile: &file.File{
			Path:      migrationsPath,
			FileName:  fmt.Sprintf(filenamef, version, name, "up", d.FilenameExtension()),
			Name:      name,
			Content:   []byte(""),
			Direction: direction.Up,
		},
		DownFile: &file.File{
			Path:      migrationsPath,
			FileName:  fmt.Sprintf(filenamef, version, name, "down", d.FilenameExtension()),
			Name:      name,
			Content:   []byte(""),
			Direction: direction.Down,
		},
	}

	err = ioutil.WriteFile(path.Join(mfile.UpFile.Path, mfile.UpFile.FileName), mfile.UpFile.Content, 0644)
	return err
}
Beispiel #2
0
// Versions returns applied versions.
func Versions(url, migrationsPath string) (versions file.Versions, err error) {
	d, err := driver.New(url)
	if err != nil {
		return file.Versions{}, err
	}
	return d.Versions()
}
Beispiel #3
0
// initDriverAndReadMigrationFilesAndGetVersionsAndGetVersion is a small helper
// function that is common to most of the migration funcs.
func initDriverAndReadMigrationFilesAndGetVersions(url, migrationsPath string) (driver.Driver, file.MigrationFiles, file.Versions, error) {
	d, err := driver.New(url)
	if err != nil {
		return nil, nil, file.Versions{}, err
	}
	files, err := file.ReadMigrationFiles(migrationsPath, file.FilenameRegex(d.FilenameExtension()))
	if err != nil {
		d.Close() // TODO what happens with errors from this func?
		return nil, nil, file.Versions{}, err
	}

	versions, err := d.Versions()
	if err != nil {
		d.Close() // TODO what happens with errors from this func?
		return nil, nil, file.Versions{}, err

	}

	return d, files, versions, nil
}