Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: separate schema and table name (#3757)

Danny Xubd81cbcc3d98
diff --git a/plugin/db/clickhouse/sync.go b/plugin/db/clickhouse/sync.go
index dfef55bfcd..98e907a889 100644
--- a/plugin/db/clickhouse/sync.go
+++ b/plugin/db/clickhouse/sync.go
@@ -170,6 +170,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
var table db.Table
table.Type = "BASE TABLE"
table.Name = name
+ table.ShortName = name
table.Engine = engine
table.Comment = comment
table.RowCount = rowCount
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index c1d501c7fa..29b4759e74 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -96,7 +96,12 @@ type Column struct {
// Table is the database table.
type Table struct {
+ // Name is a combination of schema and short name for legacy purpose.
Name string
+ // ShortName is the short table name.
+ ShortName string
+ // Schema is the schema name for a table. It should be supported only for Postgres and Snowflake.
+ Schema string
// CreatedTs isn't supported for ClickHouse, SQLite.
CreatedTs int64
// UpdatedTs isn't supported for SQLite.
diff --git a/plugin/db/mysql/sync.go b/plugin/db/mysql/sync.go
index fae18a5efe..f1b0eadd01 100644
--- a/plugin/db/mysql/sync.go
+++ b/plugin/db/mysql/sync.go
@@ -289,6 +289,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
); err != nil {
return nil, err
}
+ table.ShortName = table.Name
switch table.Type {
case baseTableType:
diff --git a/plugin/db/pg/sync.go b/plugin/db/pg/sync.go
index 5e092c606c..3148635f3e 100644
--- a/plugin/db/pg/sync.go
+++ b/plugin/db/pg/sync.go
@@ -174,6 +174,8 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
for _, tbl := range tables {
var dbTable db.Table
dbTable.Name = fmt.Sprintf("%s.%s", tbl.schemaName, tbl.name)
+ dbTable.Schema = tbl.schemaName
+ dbTable.ShortName = tbl.name
dbTable.Type = "BASE TABLE"
dbTable.Comment = tbl.comment
dbTable.RowCount = tbl.rowCount
diff --git a/plugin/db/snowflake/sync.go b/plugin/db/snowflake/sync.go
index cb8c5425a5..05a5ceb273 100644
--- a/plugin/db/snowflake/sync.go
+++ b/plugin/db/snowflake/sync.go
@@ -260,6 +260,8 @@ func (driver *Driver) syncTableSchema(ctx context.Context, database string) ([]d
}
table.Name = fmt.Sprintf("%s.%s", schemaName, tableName)
+ table.Schema = schemaName
+ table.ShortName = tableName
table.ColumnList = columnMap[table.Name]
tables = append(tables, table)
}
diff --git a/plugin/db/sqlite/sync.go b/plugin/db/sqlite/sync.go
index 8d4cc31bba..805995518e 100644
--- a/plugin/db/sqlite/sync.go
+++ b/plugin/db/sqlite/sync.go
@@ -144,6 +144,7 @@ func getTables(txn *sql.Tx, indicesMap map[string][]indexSchema) ([]db.Table, er
for _, name := range tableNames {
var tbl db.Table
tbl.Name = name
+ tbl.ShortName = name
tbl.Type = "BASE TABLE"
if err := func() error {
diff --git a/server/runner/schemasync/syncer.go b/server/runner/schemasync/syncer.go
index 44928e7a90..7b8471600e 100644
--- a/server/runner/schemasync/syncer.go
+++ b/server/runner/schemasync/syncer.go
@@ -428,7 +428,8 @@ func syncDBSchema(ctx context.Context, store *store.Store, database *api.Databas
metadata := &storepb.SchemaMetadata{}
for _, t := range schema.TableList {
metadata.TableMetadata = append(metadata.TableMetadata, &storepb.TableMetadata{
- Name: t.Name,
+ Schema: t.Schema,
+ Name: t.ShortName,
})
}
bytes, err := protojson.Marshal(metadata)