go-pg / migrations

SQL database migrations for Golang go-pg and PostgreSQL
https://godoc.org/github.com/go-pg/migrations
BSD 2-Clause "Simplified" License
309 stars 59 forks source link

ERROR #0A000 unimplemented at or near \"if\"" #78

Closed hazcod closed 5 years ago

hazcod commented 5 years ago

Version: "github.com/go-pg/migrations/v7" Running against cockroachdb, which should support IF EXISTS.

Error:

ERROR #0A000 unimplemented at or near \"if\""

Code:

func MigrateDatabase(db *pg.DB, schemaName string) error {
    // set the metadata table name
    migrations.SetTableName(fmt.Sprintf("%s.%s", schemaName, migrationsTableName))

    // discover the local migration files
    if err := migrations.DefaultCollection.DiscoverSQLMigrations(migrationsPath); err != nil {
        return errors.New(fmt.Sprintf("could not discover migrations: %v", err))
    }

    // try intializing the migrations meta table and migrating
    log.Debug("initializing migrations database")
    _, _, err := migrations.Run(db, "init")
    if err != nil {
        log.Warnf("could not init migrations: %v", err)
    }

    log.Debugf("migrating database")
    oldVersion, newVersion, err := migrations.Run(db, "up")
    if err != nil {
        return errors.New(fmt.Sprintf("could not migrate: %v", err))
    }

    log.Debugf("upgraded db from version %d to version %d", oldVersion, newVersion)
    return nil
}
hazcod commented 5 years ago

Caused by https://github.com/cockroachdb/cockroach/issues/26443