Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
clickhouse driver: add updated time and data size to table metadata.
spinningbot1fd7e19ad04f
diff --git a/plugin/db/clickhouse/clickhouse.go b/plugin/db/clickhouse/clickhouse.goindex 1a049c49d9..34db9fd3ea 100644--- a/plugin/db/clickhouse/clickhouse.go+++ b/plugin/db/clickhouse/clickhouse.go@@ -8,6 +8,7 @@ import ("fmt""io""strings"+ "time"clickhouse "github.com/ClickHouse/clickhouse-go""github.com/bytebase/bytebase/common"@@ -203,12 +204,13 @@ func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchname,engine,total_rows,+ total_bytes,+ metadata_modification_time,create_table_query,commentFROM system.tablesWHERE ` + tableWheretableRows, err := driver.db.QueryContext(ctx, query)- // metadata_modification_time, total_rows, total_bytes, lifetime_rows, lifetime_bytesif err != nil {return nil, nil, util.FormatErrorWithQuery(err, query)}@@ -221,12 +223,15 @@ func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchfor tableRows.Next() {var dbName, name, engine, definition, comment string- var rowCount sql.NullInt64+ var rowCount, totalBytes sql.NullInt64+ var lastUpdatedTime time.Timeif err := tableRows.Scan(&dbName,&name,&engine,&rowCount,+ &totalBytes,+ &lastUpdatedTime,&definition,&comment,); err != nil {@@ -236,6 +241,7 @@ func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchif engine == "View" {var view db.DBViewview.Name = name+ view.UpdatedTs = lastUpdatedTime.Unix()view.Definition = definitionview.Comment = commentviewMap[dbName] = append(viewMap[dbName], view)@@ -248,6 +254,10 @@ func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchif rowCount.Valid {table.RowCount = rowCount.Int64}+ if totalBytes.Valid {+ table.DataSize = totalBytes.Int64+ }+ table.UpdatedTs = lastUpdatedTime.Unix()key := fmt.Sprintf("%s/%s", dbName, name)table.ColumnList = columnMap[key]tableMap[dbName] = append(tableMap[dbName], table)