From 49bb1e19c26e2b10e1fc76ef9df4a244f2c9e13a Mon Sep 17 00:00:00 2001 From: Jay Taylor Date: Tue, 17 Mar 2015 11:19:51 -0700 Subject: [PATCH] Reworked broken db-type query to ensure accurate detection. --- postgres.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/postgres.go b/postgres.go index 4b124bd2..f80ca92f 100644 --- a/postgres.go +++ b/postgres.go @@ -91,14 +91,15 @@ func (s *postgres) RemoveIndex(scope *Scope, indexName string) { } func (s *postgres) HasIndex(scope *Scope, tableName string, indexName string) bool { - // Determine whehter the pg_indexes talbe is - detect := []int{} //make([]int, 2) // If detect[0] == 1 then we have postgres, else if detect[1] == 1 then we have detectationDB. - scope.NewDB().Raw(`SELECT count(*) "detect" FROM INFORMATION_SCHEMA.tables WHERE table_name = 'pg_indexes' UNION SELECT count(*) "detect" FROM INFORMATION_SCHEMA.tables WHERE table_name = 'indexes'`).Pluck("detect", &detect) + // Determine whether we're using a postgres db or foundation. + var isPg int + var isFdb int + scope.NewDB().Raw(`SELECT (SELECT count(*) FROM INFORMATION_SCHEMA.tables WHERE table_name = 'pg_indexes') "pg", (SELECT count(*) FROM INFORMATION_SCHEMA.tables WHERE table_name = 'indexes') "fdb"`).Row().Scan(&isPg, &isFdb) var count int var indexQuery string - if detect[0] == 1 { // Then we have postgres. + if isPg == 1 { // Then we have postgres. indexQuery = "SELECT count(*) FROM pg_indexes WHERE tablename = ? AND indexname = ?" - } else if detect[1] == 1 { // Then we have FoundationDB. + } else if isFdb == 1 { // Then we have FoundationDB. indexQuery = "SELECT count(*) FROM INFORMATION_SCHEMA.indexes WHERE table_schema = current_schema AND table_name = ? AND index_name = ?" } else { panic("unable to query for indexes, unrecognized database schema layout")