From c697537d009342e5c87139715d1bb07d9f46b5ff Mon Sep 17 00:00:00 2001 From: "dino.ma" Date: Thu, 11 Nov 2021 20:54:36 +0800 Subject: [PATCH 1/2] feat(migrator.go) : add GetTables method. --- migrator.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/migrator.go b/migrator.go index 392b47a..00aca14 100644 --- a/migrator.go +++ b/migrator.go @@ -163,6 +163,13 @@ func (m Migrator) DropIndex(value interface{}, name string) error { }) } +func (m Migrator) GetTables() (tableList []string, err error) { + var schemaName string + m.DB.Raw("SELECT CURRENT_SCHEMA()").Scan(&schemaName) + return tableList, m.DB.Raw( "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_type = ?", schemaName,"BASE TABLE").Scan(&tableList).Error +} + + func (m Migrator) CreateTable(values ...interface{}) (err error) { if err = m.Migrator.CreateTable(values...); err != nil { return From f70e32ad6c208adf6d17f304fda2164c2eb45367 Mon Sep 17 00:00:00 2001 From: "dino.ma" Date: Thu, 11 Nov 2021 21:44:32 +0800 Subject: [PATCH 2/2] fix(migrator.go): use CurrentSchema method --- migrator.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/migrator.go b/migrator.go index 00aca14..70bab96 100644 --- a/migrator.go +++ b/migrator.go @@ -164,12 +164,10 @@ func (m Migrator) DropIndex(value interface{}, name string) error { } func (m Migrator) GetTables() (tableList []string, err error) { - var schemaName string - m.DB.Raw("SELECT CURRENT_SCHEMA()").Scan(&schemaName) - return tableList, m.DB.Raw( "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_type = ?", schemaName,"BASE TABLE").Scan(&tableList).Error + currentSchema, _ := m.CurrentSchema(m.DB.Statement, "") + return tableList, m.DB.Raw("SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_type = ?", currentSchema, "BASE TABLE").Scan(&tableList).Error } - func (m Migrator) CreateTable(values ...interface{}) (err error) { if err = m.Migrator.CreateTable(values...); err != nil { return