From 88728906a8652a7d3c0a5d59da4ff2767690e65f Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 11 Dec 2023 04:05:15 -0600 Subject: [PATCH] fix(copydb): fix migration to Postgres (#2601) * chore(copydb): Use query builder during setup * fix(copydb): Fix migration to Postgres --- cmd/copydb.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/copydb.go b/cmd/copydb.go index 5ec22e21..e31ce436 100644 --- a/cmd/copydb.go +++ b/cmd/copydb.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "github.com/Masterminds/squirrel" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -94,8 +95,15 @@ func copydb(fromProfile, toProfile *_profile.Profile) error { for table := range copyMap { println("Checking " + table + "...") var cnt int - err := toDb.QueryRowContext(ctx, "SELECT COUNT(*) FROM "+table).Scan(&cnt) + if toProfile.Driver == "postgres" && table == "user" { + table = `"user"` + } + builder := squirrel.Select("COUNT(*)").From(table) + query, args, err := builder.ToSql() if err != nil { + return errors.Wrapf(err, "fail to build query '%s'", table) + } + if err := toDb.QueryRowContext(ctx, query, args...).Scan(&cnt); err != nil { return errors.Wrapf(err, "fail to check '%s'", table) } if cnt > 0 && table != "system_setting" {