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

Unexpected alter table #553

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 9 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ go 1.16

require (
github.com/denisenkom/go-mssqldb v0.12.2 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
gorm.io/driver/mysql v1.4.1
gorm.io/driver/postgres v1.4.4
gorm.io/driver/sqlite v1.4.2
github.com/jackc/pgtype v1.13.0 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/microsoft/go-mssqldb v0.19.0 // indirect
golang.org/x/crypto v0.4.0 // indirect
gorm.io/driver/mysql v1.4.4
gorm.io/driver/postgres v1.4.5
gorm.io/driver/sqlite v1.4.3
gorm.io/driver/sqlserver v1.4.1
gorm.io/gorm v1.24.0
gorm.io/gorm v1.24.2
)

replace gorm.io/gorm => ./gorm
32 changes: 27 additions & 5 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
package main

import (
"io/ioutil"
"os"
"strings"
"testing"
)

// GORM_REPO: https://github.com/go-gorm/gorm.git
// GORM_BRANCH: master
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver

func TestGORM(t *testing.T) {
user := User{Name: "jinzhu"}
type MyTable struct {
Def string `gorm:"size:512;index:idx_def,unique"`
Abc string `gorm:"size:65000000"`
}

DB.Create(&user)
func TestGORM(t *testing.T) {
sql := "CREATE TABLE `my_tables` (`def` varchar(512),`abc` longtext,UNIQUE INDEX `idx_def` (`def`))"
if err := DB.Exec(sql).Error; err != nil {
t.Errorf("Failed, got error: %v", err)
}
// stdout to pipe
rescueStdout := os.Stdout
r, w, _ := os.Pipe()
os.Stdout = w

var result User
if err := DB.First(&result, user.ID).Error; err != nil {
DB.DryRun = true
if err := DB.AutoMigrate(&MyTable{}); err != nil {
t.Errorf("Failed, got error: %v", err)
}

// get stdout from pipe
w.Close()
out, _ := ioutil.ReadAll(r)
os.Stdout = rescueStdout

if strings.Contains(string(out), "ALTER TABLE") {
t.Errorf("Unexpected alter table: %v", string(out))
}
}