diff --git a/core/collection_query.go b/core/collection_query.go index 77168a1f..5108dd3c 100644 --- a/core/collection_query.go +++ b/core/collection_query.go @@ -206,9 +206,9 @@ func (app *BaseApp) IsCollectionNameUnique(name string, excludeIds ...string) bo query.AndWhere(dbx.NotIn("id", list.ToInterfaceSlice(uniqueExcludeIds)...)) } - var exists bool + var total int - return query.Row(&exists) == nil && !exists + return query.Row(&total) == nil && total == 0 } // TruncateCollection deletes all records associated with the provided collection. diff --git a/core/migrations_runner.go b/core/migrations_runner.go index 9d0e77dd..b5258675 100644 --- a/core/migrations_runner.go +++ b/core/migrations_runner.go @@ -269,7 +269,7 @@ func (r *MigrationsRunner) initMigrationsTable() error { func (r *MigrationsRunner) isMigrationApplied(txApp App, file string) bool { var exists bool - err := txApp.DB().Select("count(*)"). + err := txApp.DB().Select("(1)"). From(r.tableName). Where(dbx.HashExp{"file": file}). Limit(1). diff --git a/core/migrations_runner_test.go b/core/migrations_runner_test.go index 84ee6cab..a42cdee8 100644 --- a/core/migrations_runner_test.go +++ b/core/migrations_runner_test.go @@ -202,7 +202,7 @@ func TestMigrationsRunnerRemoveMissingAppliedMigrations(t *testing.T) { func isMigrationApplied(app core.App, file string) bool { var exists bool - err := app.DB().Select("count(*)"). + err := app.DB().Select("(1)"). From(core.DefaultMigrationsTable). Where(dbx.HashExp{"file": file}). Limit(1). @@ -210,28 +210,3 @@ func isMigrationApplied(app core.App, file string) bool { return err == nil && exists } - -// // ------------------------------------------------------------------- - -// type testDB struct { -// *dbx.DB -// CalledQueries []string -// } - -// // NB! Don't forget to call `db.Close()` at the end of the test. -// func createTestDB() (*testDB, error) { -// sqlDB, err := sql.Open("sqlite", ":memory:") -// if err != nil { -// return nil, err -// } - -// db := testDB{DB: dbx.NewFromDB(sqlDB, "sqlite")} -// db.QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) { -// db.CalledQueries = append(db.CalledQueries, sql) -// } -// db.ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) { -// db.CalledQueries = append(db.CalledQueries, sql) -// } - -// return &db, nil -// }