Spanner support enhancements (#101634)

* Adds ability to run integration tests against spanner (by using GRAFANA_TEST_DB=spanner env variable. SPANNER_DB variable then specifies database to use: spannertest, emulator or string like /projects/<project>/instances/<instance>/databases/<db>)
* Adds feature to migration dialects to create database from a snapshot, instead of running individual migrations.
* Adds first version of Spanner snapshot, prepared from "OSS" migrations.
* Uses generated bit-reversed-positive values instead of auto_increment. (As an experiment)
This commit is contained in:
Peter Štibraný
2025-03-06 16:11:20 +01:00
committed by GitHub
parent 43f56c5ca1
commit 9e690bd620
18 changed files with 1477 additions and 86 deletions
+14 -15
View File
@@ -7,7 +7,6 @@ package xorm
import (
"errors"
"fmt"
"math/rand"
"reflect"
"sort"
"strconv"
@@ -346,20 +345,20 @@ func (session *Session) innerInsert(bean any) (int64, error) {
return 0, err
}
// XXX: hack to handle autoincrement in spanner
if len(table.AutoIncrement) > 0 && session.engine.dialect.DBType() == "spanner" {
var found bool
for _, col := range colNames {
if col == table.AutoIncrement {
found = true
break
}
}
if !found {
colNames = append(colNames, table.AutoIncrement)
args = append(args, rand.Int63n(9e15))
}
}
//// XXX: hack to handle autoincrement in spanner
//if len(table.AutoIncrement) > 0 && session.engine.dialect.DBType() == "spanner" {
// var found bool
// for _, col := range colNames {
// if col == table.AutoIncrement {
// found = true
// break
// }
// }
// if !found {
// colNames = append(colNames, table.AutoIncrement)
// args = append(args, rand.Int63n(9e15))
// }
//}
exprs := session.statement.exprColumns
colPlaces := strings.Repeat("?, ", len(colNames))