Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
snowflake driver: add table to sync schema.
spinningbot35161209a1e6
diff --git a/plugin/db/driver.go b/plugin/db/driver.goindex 6ee13edeb7..520f9e04e8 100644--- a/plugin/db/driver.go+++ b/plugin/db/driver.go@@ -70,21 +70,21 @@ type DBTable struct {CreatedTs int64UpdatedTs int64Type string- // Engine isn't supported for Postgres.+ // Engine isn't supported for Postgres, Snowflake.Engine string- // Collation isn't supported for Postgres, ClickHouse.+ // Collation isn't supported for Postgres, ClickHouse, Snowflake.Collation stringRowCount int64DataSize int64- // IndexSize isn't ClickHouse.+ // IndexSize isn't ClickHouse, Snowflake.IndexSize int64- // DataFree isn't supported for Postgres, ClickHouse.+ // DataFree isn't supported for Postgres, ClickHouse, Snowflake.DataFree int64- // CreateOptions isn't supported for Postgres, ClickHouse.+ // CreateOptions isn't supported for Postgres, ClickHouse, Snowflake.CreateOptions stringComment stringColumnList []DBColumn- // IndexList isn't supported for ClickHouse.+ // IndexList isn't supported for ClickHouse, Snowflake.IndexList []DBIndex}diff --git a/plugin/db/snowflake/snowflake.go b/plugin/db/snowflake/snowflake.goindex 60bd746113..91a2590843 100644--- a/plugin/db/snowflake/snowflake.go+++ b/plugin/db/snowflake/snowflake.go@@ -137,6 +137,11 @@ func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchvar schema db.DBSchemaschema.Name = database+ tableList, viewList, err := driver.syncTableSchema(ctx, database)+ if err != nil {+ return nil, nil, err+ }+ schema.TableList, schema.ViewList = tableList, viewListschemaList = append(schemaList, &schema)}@@ -144,6 +149,60 @@ func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchreturn userList, schemaList, nil}+func (driver *Driver) syncTableSchema(ctx context.Context, database string) ([]db.DBTable, []db.DBView, error) {+ // Query table info+ var excludedSchemaList []string++ // Skip all system schemas.+ for k := range systemSchemas {+ excludedSchemaList = append(excludedSchemaList, fmt.Sprintf("'%s'", k))+ }+ tableWhere := fmt.Sprintf("TABLE_SCHEMA NOT IN (%s)", strings.Join(excludedSchemaList, ", "))+ query := fmt.Sprintf(`+ SELECT+ TABLE_SCHEMA,+ TABLE_NAME,+ DATE_PART(EPOCH_SECOND, CREATED),+ DATE_PART(EPOCH_SECOND, LAST_ALTERED),+ TABLE_TYPE,+ ROW_COUNT,+ BYTES,+ IFNULL(COMMENT, '')+ FROM %s.INFORMATION_SCHEMA.TABLES+ WHERE TABLE_TYPE = 'BASE TABLE' AND %s`, database, tableWhere)+ tableRows, err := driver.db.QueryContext(ctx, query)+ if err != nil {+ return nil, nil, util.FormatErrorWithQuery(err, query)+ }+ defer tableRows.Close()++ var tables []db.DBTable+ for tableRows.Next() {+ var schemaName, tableName string+ var table db.DBTable+ if err := tableRows.Scan(+ &schemaName,+ &tableName,+ &table.CreatedTs,+ &table.UpdatedTs,+ &table.Type,+ &table.RowCount,+ &table.DataSize,+ &table.Comment,+ ); err != nil {+ return nil, nil, err+ }++ table.Name = fmt.Sprintf("%s.%s", schemaName, tableName)+ tables = append(tables, table)+ }+ if err := tableRows.Err(); err != nil {+ return nil, nil, err+ }++ return tables, nil, nil+}+func (driver *Driver) getDatabases(ctx context.Context) ([]string, error) {if err := driver.UseRole(ctx, accountAdminRole); err != nil {return nil, err