From 3f6c1cda391329bc26467013a0079f0a55aa862d Mon Sep 17 00:00:00 2001 From: zelo <1172435011@qq.com> Date: Thu, 26 Oct 2023 11:06:59 +0800 Subject: [PATCH] Implement the GetTables() interface of Migrator (#137) --- migrator.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/migrator.go b/migrator.go index 037f468..3fe3331 100644 --- a/migrator.go +++ b/migrator.go @@ -190,6 +190,12 @@ func (m Migrator) HasTable(value interface{}) bool { return count > 0 } +func (m Migrator) GetTables() (tableList []string, err error) { + // table_type Enum8('BASE TABLE' = 1, 'VIEW' = 2, 'FOREIGN TABLE' = 3, 'LOCAL TEMPORARY' = 4, 'SYSTEM VIEW' = 5) + err = m.DB.Raw("SELECT TABLE_NAME FROM information_schema.tables where table_schema=? and table_type =1", m.CurrentDatabase()).Scan(&tableList).Error + return +} + // Columns func (m Migrator) AddColumn(value interface{}, field string) error { @@ -504,14 +510,16 @@ sample input: CREATE TABLE my_database.my_foo_bar ( - `id` UInt64, - `created_at` DateTime64(3), - `updated_at` DateTime64(3), - `deleted_at` DateTime64(3), - `foo` String, - `bar` String, - INDEX idx_my_foo_bar_deleted_at deleted_at TYPE minmax GRANULARITY 3, - INDEX my_fb_foo_bar (foo, bar) TYPE minmax GRANULARITY 3 + + `id` UInt64, + `created_at` DateTime64(3), + `updated_at` DateTime64(3), + `deleted_at` DateTime64(3), + `foo` String, + `bar` String, + INDEX idx_my_foo_bar_deleted_at deleted_at TYPE minmax GRANULARITY 3, + INDEX my_fb_foo_bar (foo, bar) TYPE minmax GRANULARITY 3 + ) ENGINE = MergeTree PARTITION BY toYYYYMM(created_at)