(fix) remove ad-hoc cases for YDB
- remove ad-hoc cases in `sync.go`, `engine.go`. To remove, I decided in `dialects/ydb.go` method `CreateTableSQL` will only generate YQL to create table not YQL for create indexes. So, to create indexes for table, client should use `(*Session).CreateIndexes(...)`.
This commit is contained in:
parent
93101ea555
commit
a3c13ae160
2
Makefile
2
Makefile
|
@ -47,7 +47,7 @@ TEST_DAMENG_HOST ?= dameng:5236
|
||||||
TEST_DAMENG_USERNAME ?= SYSDBA
|
TEST_DAMENG_USERNAME ?= SYSDBA
|
||||||
TEST_DAMENG_PASSWORD ?= SYSDBA
|
TEST_DAMENG_PASSWORD ?= SYSDBA
|
||||||
|
|
||||||
TEST_YDB_CONNECTION_STRING ?= grpc://ydb:2136/local?go_query_bind=table_path_prefix(/local/xorm/test),declare,numeric&go_fake_tx=scan,scheme,scripting
|
TEST_YDB_CONNECTION_STRING ?= grpc://ydb:2136/local?go_query_bind=table_path_prefix(/local),declare,numeric&go_fake_tx=scan,scheme,scripting
|
||||||
|
|
||||||
TEST_CACHE_ENABLE ?= false
|
TEST_CACHE_ENABLE ?= false
|
||||||
TEST_QUOTE_POLICY ?= always
|
TEST_QUOTE_POLICY ?= always
|
||||||
|
|
|
@ -724,6 +724,8 @@ func (db *ydb) GetIndexes(
|
||||||
return indexes, nil
|
return indexes, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// !datbeohbbh! CreateTableSQL generate `CREATE TABLE` YQL.
|
||||||
|
// Method does not generate YQL for creating index.
|
||||||
func (db *ydb) CreateTableSQL(
|
func (db *ydb) CreateTableSQL(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
_ core.Queryer,
|
_ core.Queryer,
|
||||||
|
@ -761,27 +763,7 @@ func (db *ydb) CreateTableSQL(
|
||||||
}
|
}
|
||||||
joinColumns := strings.Join(columnsList, ", ")
|
joinColumns := strings.Join(columnsList, ", ")
|
||||||
|
|
||||||
// build index
|
|
||||||
indexList := []string{}
|
|
||||||
for indexName, index := range table.Indexes {
|
|
||||||
name := quote.Quote(indexName)
|
|
||||||
onCols := make([]string, len(index.Cols))
|
|
||||||
for i := 0; i < len(index.Cols); i++ {
|
|
||||||
onCols[i] = quote.Quote(index.Cols[i])
|
|
||||||
}
|
|
||||||
indexList = append(indexList,
|
|
||||||
fmt.Sprintf(
|
|
||||||
"INDEX %s GLOBAL ON ( %s )",
|
|
||||||
name, strings.Join(onCols, ", ")))
|
|
||||||
}
|
|
||||||
joinIndexes := strings.Join(indexList, ", ")
|
|
||||||
|
|
||||||
if joinIndexes != "" {
|
|
||||||
buf.WriteString(strings.Join([]string{joinColumns, joinIndexes, primaryKey}, ", "))
|
|
||||||
} else {
|
|
||||||
buf.WriteString(strings.Join([]string{joinColumns, primaryKey}, ", "))
|
buf.WriteString(strings.Join([]string{joinColumns, primaryKey}, ", "))
|
||||||
}
|
|
||||||
|
|
||||||
buf.WriteString(" ) ")
|
buf.WriteString(" ) ")
|
||||||
|
|
||||||
if db.tableParams != nil && len(db.tableParams) > 0 {
|
if db.tableParams != nil && len(db.tableParams) > 0 {
|
||||||
|
|
|
@ -552,10 +552,6 @@ func (engine *Engine) dumpTables(ctx context.Context, tables []*schemas.Table, w
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, index := range dstTable.Indexes {
|
for _, index := range dstTable.Indexes {
|
||||||
// !datbeohbbh! with YDB, if there are indexes in table, these indexes have already been created in CREATE TABLE script.
|
|
||||||
if dstDialect.URI().DBType == schemas.YDB {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
_, err = io.WriteString(w, dstDialect.CreateIndexSQL(dstTable.Name, index)+";\n")
|
_, err = io.WriteString(w, dstDialect.CreateIndexSQL(dstTable.Name, index)+";\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
5
sync.go
5
sync.go
|
@ -109,11 +109,6 @@ func (session *Session) SyncWithOptions(opts SyncOptions, beans ...interface{})
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// !datbeohbbh! skip with YDB. All indexes are created when create table.
|
|
||||||
if engine.dialect.URI().DBType == schemas.YDB {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if !opts.IgnoreConstrains {
|
if !opts.IgnoreConstrains {
|
||||||
err = session.createUniques(bean)
|
err = session.createUniques(bean)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -156,7 +156,7 @@ func PrepareScheme(bean ...interface{}) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := engine.CreateTables(bean...); err != nil {
|
if err := engine.Sync(bean...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,19 @@ func TestCreateTable(t *testing.T) {
|
||||||
|
|
||||||
assert.NoError(t, session.DropTable(&Users{}))
|
assert.NoError(t, session.DropTable(&Users{}))
|
||||||
assert.NoError(t, session.CreateTable(&Users{}))
|
assert.NoError(t, session.CreateTable(&Users{}))
|
||||||
// assert.NoError(t, session.CreateTable(&Users{}))
|
}
|
||||||
|
|
||||||
|
func TestCreateTableAndIndex(t *testing.T) {
|
||||||
|
engine, err := enginePool.GetScriptQueryEngine()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.NotNil(t, engine)
|
||||||
|
|
||||||
|
session := engine.NewSession()
|
||||||
|
defer session.Close()
|
||||||
|
|
||||||
|
assert.NoError(t, session.DropTable(&Users{}))
|
||||||
|
assert.NoError(t, session.CreateTable(&Users{}))
|
||||||
|
assert.NoError(t, session.CreateIndexes(&Users{}))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsTableEmpty(t *testing.T) {
|
func TestIsTableEmpty(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue