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

fix parseDDL bug with escaped quote #89

Merged
merged 1 commit into from Apr 24, 2022
Merged

fix parseDDL bug with escaped quote #89

merged 1 commit into from Apr 24, 2022

Conversation

duc-cnzj
Copy link
Contributor

@duc-cnzj duc-cnzj commented Apr 14, 2022

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

fix parseDDL bug with escaped quote, (This is probably a p0 level bug)

User Case Description

Data loss occurs when exec AutoMigrate!

reproduces:

gorm.io/driver/sqlite v1.3.1
gorm.io/gorm v1.23.4

  1. run AutoMigrate, create users table
package main

import (
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
	"log"
)

type User struct {
	ID int `json:"id" gorm:"primaryKey;"`

	FirstName string `json:"first_name" gorm:"size:100;not null;default:''"`
	LastName  string `json:"last_name" gorm:"size:100;not null;default:''"`
	Age       int    `json:"age" gorm:"not null;default:0"`
}

func main() {
	db, err := gorm.Open(sqlite.Open("/tmp/sqlite.db"), &gorm.Config{})
	if err != nil {
		panic("failed to connect database")
	}

	if err := db.AutoMigrate(&User{}); err != nil {
		log.Println(err)
	}
}
  1. insert data INSERT INTO "users" ("first_name", "last_name", "age") VALUES ('xiao', 'ming', '18');

image

  1. run AutoMigrate again, data loss!

image

@jinzhu jinzhu merged commit 0a99da5 into go-gorm:master Apr 24, 2022
1 check passed
@jinzhu
Copy link
Member

@jinzhu jinzhu commented Apr 24, 2022

Oops, sorry for the bug, thank you for your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants