Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade package #50

Merged
merged 5 commits into from
Jun 20, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.19

- name: Build
run: go build -v ./...
Expand Down
4 changes: 3 additions & 1 deletion element/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ func (c Column) migrationUp(tbName, after string, ident int) []string {
return []string{fmt.Sprintf(sql.AlterTableDropColumnStm(), sql.EscapeSqlName(tbName), sql.EscapeSqlName(c.Name))}

case MigrateModifyAction:
return []string{fmt.Sprintf(sql.AlterTableModifyColumnStm(), sql.EscapeSqlName(tbName), sql.EscapeSqlName(c.Name)+c.definition())}
def := strings.Replace(c.definition(), sql.PrimaryOption(), "", 1)

return []string{fmt.Sprintf(sql.AlterTableModifyColumnStm(), sql.EscapeSqlName(tbName), sql.EscapeSqlName(c.Name)+def)}

case MigrateRenameAction:
return []string{fmt.Sprintf(sql.AlterTableRenameColumnStm(), sql.EscapeSqlName(tbName), sql.EscapeSqlName(c.OldName), sql.EscapeSqlName(c.Name))}
Expand Down
4 changes: 0 additions & 4 deletions element/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ func (t Table) MigrationColumnUp() ([]string, map[string]struct{}) {
return []string{fmt.Sprintf(sql.DropTableStm(), sql.EscapeSqlName(t.Name))}, nil

case MigrateModifyAction:
// TODO
return nil, nil

default:
Expand Down Expand Up @@ -536,7 +535,6 @@ func (t Table) MigrationColumnDown() ([]string, map[string]struct{}) {
return t.MigrationColumnUp()

case MigrateModifyAction:
// TODO
return nil, nil

default:
Expand Down Expand Up @@ -566,7 +564,6 @@ func (t Table) MigrationIndexDown(dropCols map[string]struct{}) []string {
return t.MigrationIndexUp(dropCols)

case MigrateModifyAction:
// TODO
return nil

default:
Expand Down Expand Up @@ -596,7 +593,6 @@ func (t Table) MigrationForeignKeyDown(dropCols map[string]struct{}) []string {
return t.MigrationForeignKeyUp(dropCols)

case MigrateModifyAction:
// TODO
return nil

default:
Expand Down
45 changes: 36 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
module github.com/sunary/sqlize

go 1.14
go 1.19

require (
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/auxten/postgresql-parser v1.0.0
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354 // indirect
github.com/auxten/postgresql-parser v1.0.1
github.com/pingcap/parser v0.0.0-20200623164729-3a18f1e5dceb
github.com/pkg/errors v0.9.1
github.com/rqlite/sql v0.0.0-20221103124402-8f9ff0ceb8f0
go.uber.org/zap v1.19.1 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.7 // indirect
github.com/rqlite/sql v0.0.0-20240312185922-ffac88a740bd
)

require (
github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d // indirect
github.com/cockroachdb/apd v1.1.1-0.20181017181144-bced77f817b4 // indirect
github.com/cockroachdb/errors v1.11.3 // indirect
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/getsentry/raven-go v0.2.0 // indirect
github.com/getsentry/sentry-go v0.28.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
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/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/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.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
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
)
137 changes: 71 additions & 66 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions sql-parser/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p Parser) Visit(node sqlite.Node) (w sqlite.Visitor, err error) {
case *sqlite.UniqueConstraint:
indexCol := make([]string, len(cons.Columns))
for i := range cons.Columns {
indexCol[i] = cons.Columns[i].Name
indexCol[i] = cons.Columns[i].Collation.Name
}

p.Migration.AddIndex(tbName, element.Index{
Expand Down Expand Up @@ -139,7 +139,7 @@ func (p *Parser) parseSqliteConstrains(tbName string, conss []sqlite.Constraint)
case *sqlite.UniqueConstraint:
indexCol := make([]string, len(cons.Columns))
for i := range cons.Columns {
indexCol[i] = cons.Columns[i].Name
indexCol[i] = cons.Columns[i].Collation.Name
}

p.Migration.AddIndex(tbName, element.Index{
Expand Down
25 changes: 18 additions & 7 deletions sqlize.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

const (
genDescription = "# generate by sqlize\n\n"
emptyMigration = "# empty"
)

// Sqlize ...
Expand Down Expand Up @@ -153,17 +154,27 @@ func (s Sqlize) StringDownWithVersion(ver int64) string {
}

func (s Sqlize) writeFiles(name, migUp, migDown string) error {
if migUp == "" && migDown == "" {
return nil
}

if migUp == "" {
migUp = emptyMigration
}

if migDown == "" {
migDown = emptyMigration
}

fileName := utils.MigrationFileName(name)

if migUp != "" {
filePath := filepath.Join(s.migrationFolder, fileName+s.migrationUpSuffix)
err := os.WriteFile(filePath, []byte(genDescription+migUp), 0644)
if err != nil {
return err
}
filePath := filepath.Join(s.migrationFolder, fileName+s.migrationUpSuffix)
err := os.WriteFile(filePath, []byte(genDescription+migUp), 0644)
if err != nil {
return err
}

if migDown != "" && s.migrationDownSuffix != "" && s.migrationDownSuffix != s.migrationUpSuffix {
if s.migrationDownSuffix != "" && s.migrationDownSuffix != s.migrationUpSuffix {
filePath := filepath.Join(s.migrationFolder, fileName+s.migrationDownSuffix)
err := os.WriteFile(filePath, []byte(genDescription+migDown), 0644)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions utils/file.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package utils

import (
"github.com/pkg/errors"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
)

var (
Expand All @@ -22,7 +23,7 @@ func ReadPath(path string, suffix string) ([]string, error) {

contents := make([]string, len(files))
for i := range files {
content, err := ioutil.ReadFile(files[i])
content, err := os.ReadFile(files[i])
if err != nil {
return nil, err
}
Expand Down
Loading