fix schema dump (#5562)

This commit is contained in:
Michal Nicpon 2022-05-10 09:03:04 -06:00 committed by GitHub
parent d7d3076e5d
commit a005b7e7b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View file

@ -10,19 +10,6 @@ func init() {
MigrationClient.AddMigration(Up_20210927143116, Down_20210927143116)
}
func columnExists(tx *sql.Tx, table, column string) bool {
var count int
err := tx.QueryRow(
`SELECT count(*) FROM information_schema.columns WHERE COLUMN_NAME = ? AND table_name = ? LIMIT 1;`,
column, table,
).Scan(&count)
if err != nil {
return false
}
return count == 1
}
func Up_20210927143116(tx *sql.Tx) error {
if columnExists(tx, "software", "bundle_identifier") {
return nil

View file

@ -1,7 +1,33 @@
package tables
import "github.com/fleetdm/goose"
import (
"database/sql"
"github.com/fleetdm/goose"
)
var (
MigrationClient = goose.New("migration_status_tables", goose.MySqlDialect{})
)
func columnExists(tx *sql.Tx, table, column string) bool {
var count int
err := tx.QueryRow(
`
SELECT
count(*)
FROM
information_schema.columns
WHERE
TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = ?
AND COLUMN_NAME = ?
`,
table, column,
).Scan(&count)
if err != nil {
return false
}
return count > 0
}