Fix issue where version wouldn't correctly populate

This commit is contained in:
Paul Bergeron 2014-08-26 20:19:13 -07:00
parent 28f6567fa0
commit a191c8bf36
1 changed files with 7 additions and 1 deletions

View File

@ -49,6 +49,12 @@ func (driver *Driver) Close() error {
func (driver *Driver) ensureVersionTableExists() error {
err := driver.session.Query("CREATE TABLE IF NOT EXISTS " + tableName + " (version counter, versionRow bigint primary key);").Exec()
if err != nil {
return err
}
driver.session.Query("UPDATE "+tableName+" SET version = version + 1 where versionRow = ?", versionRow).Exec()
if err != nil {
return err
}
@ -93,5 +99,5 @@ func (driver *Driver) Migrate(f file.File, pipe chan interface{}) {
func (driver *Driver) Version() (uint64, error) {
var version int64
err := driver.session.Query("SELECT version FROM "+tableName+" WHERE versionRow = ?", versionRow).Scan(&version)
return uint64(version), err
return uint64(version) - 1, err
}