Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions element/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"strings"

ptypes "github.com/auxten/postgresql-parser/pkg/sql/types"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/format"
"github.com/pingcap/parser/types"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/format"
"github.com/pingcap/tidb/pkg/parser/types"
sqlite "github.com/rqlite/sql"
sql_templates "github.com/sunary/sqlize/sql-templates"
)
Expand Down Expand Up @@ -42,7 +42,7 @@ type Column struct {
// GetType ...
func (c Column) GetType() byte {
if c.CurrentAttr.MysqlType != nil {
return c.CurrentAttr.MysqlType.Tp
return c.CurrentAttr.MysqlType.GetType()
}

return 0
Expand Down Expand Up @@ -244,7 +244,11 @@ func (c Column) pkDefinition(isPrev bool) (string, bool) {
}

_ = opt.Restore(ctx)
strSql += " " + b.String()
optStr := b.String()
if opt.Tp == ast.ColumnOptionDefaultValue {
optStr = strings.ReplaceAll(optStr, "DEFAULT _UTF8MB4", "DEFAULT ")
}
strSql += " " + optStr
}

return strSql, isPrimaryKey
Expand Down
5 changes: 2 additions & 3 deletions element/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
"fmt"
"strings"

"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/pkg/parser/ast"
)

// Index ...
type Index struct {
Node
Typ ast.IndexKeyType
IndexType model.IndexType
IndexType ast.IndexType
CnsTyp ast.ConstraintType
Columns []string
}
Expand Down
2 changes: 1 addition & 1 deletion element/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/binary"
"strings"

"github.com/pingcap/parser/ast"
"github.com/pingcap/tidb/pkg/parser/ast"
sql_templates "github.com/sunary/sqlize/sql-templates"
"github.com/sunary/sqlize/utils"
)
Expand Down
9 changes: 5 additions & 4 deletions element/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"strings"

ptypes "github.com/auxten/postgresql-parser/pkg/sql/types"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/types"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/sunary/sqlize/utils"
)

Expand Down Expand Up @@ -449,9 +449,10 @@ func (t Table) MigrationColumnUp() ([]string, map[string]struct{}) {
strCols := make([]string, 0)
commentCols := make([]string, 0)
for i := range t.Columns {
if t.Columns[i].Action == MigrateAddAction {
switch t.Columns[i].Action {
case MigrateAddAction:
strCols = append(strCols, " "+t.Columns[i].migrationUp("", "", maxIdent)[0])
} else if t.Columns[i].Action == MigrateModifyAction || t.Columns[i].Action == MigrateRenameAction {
case MigrateModifyAction, MigrateRenameAction:
nCol := t.Columns[i]
nCol.Action = MigrateAddAction
strCols = append(strCols, " "+nCol.migrationUp("", "", maxIdent)[0])
Expand Down
8 changes: 4 additions & 4 deletions export/avro/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"strconv"
"strings"

"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/types"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/types"
"github.com/sunary/sqlize/element"
)

Expand Down Expand Up @@ -59,7 +59,7 @@ func getAvroType(col element.Column) interface{} {
"type": "string",
"connect.version": 1,
"connect.parameters": map[string]string{
"allowed": strings.Join(col.CurrentAttr.MysqlType.Elems, ","),
"allowed": strings.Join(col.CurrentAttr.MysqlType.GetElems(), ","),
},
"connect.default": "init",
"connect.name": "io.debezium.data.Enum",
Expand All @@ -71,7 +71,7 @@ func getAvroType(col element.Column) interface{} {
return "int"

case types.ETDecimal:
displayFlen, displayDecimal := col.CurrentAttr.MysqlType.Flen, col.CurrentAttr.MysqlType.Decimal
displayFlen, displayDecimal := col.CurrentAttr.MysqlType.GetFlen(), col.CurrentAttr.MysqlType.GetDecimal()
return map[string]interface{}{
"type": "bytes",
"scale": displayDecimal,
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/sunary/sqlize

go 1.19
go 1.24.1

require (
github.com/auxten/postgresql-parser v1.0.1
github.com/pingcap/parser v0.0.0-20200623164729-3a18f1e5dceb
github.com/pingcap/tidb/pkg/parser v0.0.0-20250728085548-73284c42b94f
github.com/pkg/errors v0.9.1
github.com/rqlite/sql v0.0.0-20241111133259-a4122fabb196
)
Expand All @@ -24,16 +24,18 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/pingcap/errors v0.11.4 // indirect
github.com/pingcap/errors v0.11.5-0.20250523034308-74f78ae071ee // indirect
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
github.com/pingcap/log v1.1.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/text v0.27.0 // indirect
google.golang.org/genproto v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
Expand Down
Loading