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

Use RawSQL instead of Create to be able to upgrade to gorm new version #220

Closed
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -2,7 +2,7 @@ module github.com/go-gormigrate/gormigrate/v2

go 1.18

require gorm.io/gorm v1.25.4
require gorm.io/gorm v1.25.6

require (
github.com/jinzhu/inflection v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Expand Up @@ -4,3 +4,5 @@ github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw=
gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.6 h1:V92+vVda1wEISSOMtodHVRcUIOPYa2tgQtyF+DfFx+A=
gorm.io/gorm v1.25.6/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
3 changes: 1 addition & 2 deletions gormigrate.go
Expand Up @@ -458,8 +458,7 @@ func (g *Gormigrate) unknownMigrationsHaveHappened() (bool, error) {
}

func (g *Gormigrate) insertMigration(id string) error {
record := map[string]interface{}{g.options.IDColumnName: id}
return g.tx.Table(g.options.TableName).Create(record).Error
return g.tx.Exec("INSERT INTO " + g.options.TableName + " (" + g.options.IDColumnName + ") VALUES ('" + id + "')").Error

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can lead to SQL Injection and prevent id to have single quote inside. Am I missing something ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not much of a PR, more like the draft of a possible fix to get some feedback

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw you made one at the same time, I'm closing this one

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see ! No problem, I was just looking as I saw your PR just after I did one ahah.

}

func (g *Gormigrate) begin() {
Expand Down
2 changes: 1 addition & 1 deletion integration-test/go.mod
Expand Up @@ -11,7 +11,7 @@ require (
gorm.io/driver/postgres v1.5.2
gorm.io/driver/sqlite v1.5.3
gorm.io/driver/sqlserver v1.5.1
gorm.io/gorm v1.25.4
gorm.io/gorm v1.25.6
)

require (
Expand Down
2 changes: 2 additions & 0 deletions integration-test/go.sum
Expand Up @@ -148,6 +148,8 @@ gorm.io/driver/sqlserver v1.5.1/go.mod h1:AYHzzte2msKTmYBYsSIq8ZUsznLJwBdkB2wpI+
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.4 h1:iyNd8fNAe8W9dvtlgeRI5zSVZPsq3OpcTu37cYcpCmw=
gorm.io/gorm v1.25.4/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.6 h1:V92+vVda1wEISSOMtodHVRcUIOPYa2tgQtyF+DfFx+A=
gorm.io/gorm v1.25.6/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE=
modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
Expand Down