Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: support view and extension in database schema metadata (#3763)
Danny Xub017f33f4336
diff --git a/plugin/advisor/catalog/catalog.go b/plugin/advisor/catalog/catalog.goindex 9cffcb090b..31eb3724c3 100644--- a/plugin/advisor/catalog/catalog.go+++ b/plugin/advisor/catalog/catalog.go@@ -84,10 +84,7 @@ type Column struct {// View is the database view.type View struct {- Name string- // CreatedTs isn't supported for ClickHouse.- CreatedTs int64- UpdatedTs int64+ Name stringDefinition stringComment string}diff --git a/plugin/db/driver.go b/plugin/db/driver.goindex 29b4759e74..0d4d1cac37 100644--- a/plugin/db/driver.go+++ b/plugin/db/driver.go@@ -47,6 +47,10 @@ type User struct {// View is the database view.type View struct {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.CreatedTs int64UpdatedTs int64diff --git a/plugin/db/mysql/sync.go b/plugin/db/mysql/sync.goindex f1b0eadd01..dd0564c7b4 100644--- a/plugin/db/mysql/sync.go+++ b/plugin/db/mysql/sync.go@@ -345,6 +345,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d); err != nil {return nil, err}+ view.ShortName = view.Nameinfo := viewInfoMap[fmt.Sprintf("%s/%s", dbName, view.Name)]view.CreatedTs = info.createdTsdiff --git a/plugin/db/pg/sync.go b/plugin/db/pg/sync.goindex 3148635f3e..95df879a5a 100644--- a/plugin/db/pg/sync.go+++ b/plugin/db/pg/sync.go@@ -217,6 +217,8 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*dfor _, view := range views {var dbView db.ViewdbView.Name = fmt.Sprintf("%s.%s", view.schemaName, view.name)+ dbView.Schema = view.schemaName+ dbView.ShortName = view.name// Postgres does not storedbView.CreatedTs = time.Now().Unix()dbView.Definition = view.definitiondiff --git a/plugin/db/snowflake/sync.go b/plugin/db/snowflake/sync.goindex 05a5ceb273..05479a8fc6 100644--- a/plugin/db/snowflake/sync.go+++ b/plugin/db/snowflake/sync.go@@ -301,6 +301,8 @@ func (driver *Driver) syncTableSchema(ctx context.Context, database string) ([]dreturn nil, nil, err}view.Name = fmt.Sprintf("%s.%s", schemaName, viewName)+ view.Schema = schemaName+ view.ShortName = viewNameif createdTs.Valid {view.CreatedTs = createdTs.Int64}diff --git a/plugin/db/sqlite/sync.go b/plugin/db/sqlite/sync.goindex 805995518e..259596bff2 100644--- a/plugin/db/sqlite/sync.go+++ b/plugin/db/sqlite/sync.go@@ -251,6 +251,7 @@ func getViews(txn *sql.Tx) ([]db.View, error) {if err := rows.Scan(&view.Name, &view.Definition); err != nil {return nil, err}+ view.ShortName = view.Nameviews = append(views, view)}if err := rows.Err(); err != nil {diff --git a/proto/generated-go/store/database.pb.go b/proto/generated-go/store/database.pb.goindex ca2e9c4798..9f1c6e4893 100644--- a/proto/generated-go/store/database.pb.go+++ b/proto/generated-go/store/database.pb.go@@ -33,6 +33,8 @@ type DatabaseMetadata struct {CharacterSet string `protobuf:"bytes,3,opt,name=character_set,json=characterSet,proto3" json:"character_set,omitempty"`// The collation is the collation of a database.Collation string `protobuf:"bytes,4,opt,name=collation,proto3" json:"collation,omitempty"`+ // The extensions is the list of extensions in a database.+ Extensions []*ExtensionMetadata `protobuf:"bytes,5,rep,name=extensions,proto3" json:"extensions,omitempty"`}func (x *DatabaseMetadata) Reset() {@@ -95,6 +97,13 @@ func (x *DatabaseMetadata) GetCollation() string {return ""}+func (x *DatabaseMetadata) GetExtensions() []*ExtensionMetadata {+ if x != nil {+ return x.Extensions+ }+ return nil+}+// SchemaMetadata is the metadata for schemas.// This is the concept of schema in Postgres, but it's a no-op for MySQL.type SchemaMetadata struct {@@ -107,6 +116,8 @@ type SchemaMetadata struct {Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`// The tables is the list of tables in a schema.Tables []*TableMetadata `protobuf:"bytes,2,rep,name=tables,proto3" json:"tables,omitempty"`+ // The views is the list of views in a schema.+ Views []*ViewMetadata `protobuf:"bytes,3,rep,name=views,proto3" json:"views,omitempty"`}func (x *SchemaMetadata) Reset() {@@ -155,6 +166,13 @@ func (x *SchemaMetadata) GetTables() []*TableMetadata {return nil}+func (x *SchemaMetadata) GetViews() []*ViewMetadata {+ if x != nil {+ return x.Views+ }+ return nil+}+// TableMetadata is the metadata for tables.type TableMetadata struct {state protoimpl.MessageState@@ -417,6 +435,73 @@ func (x *ColumnMetadata) GetComment() string {return ""}+// ViewMetadata is the metadata for views.+type ViewMetadata struct {+ state protoimpl.MessageState+ sizeCache protoimpl.SizeCache+ unknownFields protoimpl.UnknownFields++ // The name is the name of a view.+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`+ // The definition is the definition of a view.+ Definition string `protobuf:"bytes,2,opt,name=definition,proto3" json:"definition,omitempty"`+ // The comment is the comment of a view.+ Comment string `protobuf:"bytes,3,opt,name=comment,proto3" json:"comment,omitempty"`+}++func (x *ViewMetadata) Reset() {+ *x = ViewMetadata{}+ if protoimpl.UnsafeEnabled {+ mi := &file_database_proto_msgTypes[4]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+ }+}++func (x *ViewMetadata) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*ViewMetadata) ProtoMessage() {}++func (x *ViewMetadata) ProtoReflect() protoreflect.Message {+ mi := &file_database_proto_msgTypes[4]+ if protoimpl.UnsafeEnabled && x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use ViewMetadata.ProtoReflect.Descriptor instead.+func (*ViewMetadata) Descriptor() ([]byte, []int) {+ return file_database_proto_rawDescGZIP(), []int{4}+}++func (x *ViewMetadata) GetName() string {+ if x != nil {+ return x.Name+ }+ return ""+}++func (x *ViewMetadata) GetDefinition() string {+ if x != nil {+ return x.Definition+ }+ return ""+}++func (x *ViewMetadata) GetComment() string {+ if x != nil {+ return x.Comment+ }+ return ""+}+// IndexMetadata is the metadata for indexes.type IndexMetadata struct {state protoimpl.MessageState@@ -443,7 +528,7 @@ type IndexMetadata struct {func (x *IndexMetadata) Reset() {*x = IndexMetadata{}if protoimpl.UnsafeEnabled {- mi := &file_database_proto_msgTypes[4]+ mi := &file_database_proto_msgTypes[5]ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))ms.StoreMessageInfo(mi)}@@ -456,7 +541,7 @@ func (x *IndexMetadata) String() string {func (*IndexMetadata) ProtoMessage() {}func (x *IndexMetadata) ProtoReflect() protoreflect.Message {- mi := &file_database_proto_msgTypes[4]+ mi := &file_database_proto_msgTypes[5]if protoimpl.UnsafeEnabled && x != nil {ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))if ms.LoadMessageInfo() == nil {@@ -469,7 +554,7 @@ func (x *IndexMetadata) ProtoReflect() protoreflect.Message {// Deprecated: Use IndexMetadata.ProtoReflect.Descriptor instead.func (*IndexMetadata) Descriptor() ([]byte, []int) {- return file_database_proto_rawDescGZIP(), []int{4}+ return file_database_proto_rawDescGZIP(), []int{5}}func (x *IndexMetadata) GetName() string {@@ -521,12 +606,79 @@ func (x *IndexMetadata) GetComment() string {return ""}+// ExtensionMetadata is the metadata for extensions.+type ExtensionMetadata struct {+ state protoimpl.MessageState+ sizeCache protoimpl.SizeCache+ unknownFields protoimpl.UnknownFields++ // The name is the name of an extension.+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`+ // The version is the version of an extension.+ Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"`+ // The description is the description of an extension.+ Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`+}++func (x *ExtensionMetadata) Reset() {+ *x = ExtensionMetadata{}+ if protoimpl.UnsafeEnabled {+ mi := &file_database_proto_msgTypes[6]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+ }+}++func (x *ExtensionMetadata) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*ExtensionMetadata) ProtoMessage() {}++func (x *ExtensionMetadata) ProtoReflect() protoreflect.Message {+ mi := &file_database_proto_msgTypes[6]+ if protoimpl.UnsafeEnabled && x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use ExtensionMetadata.ProtoReflect.Descriptor instead.+func (*ExtensionMetadata) Descriptor() ([]byte, []int) {+ return file_database_proto_rawDescGZIP(), []int{6}+}++func (x *ExtensionMetadata) GetName() string {+ if x != nil {+ return x.Name+ }+ return ""+}++func (x *ExtensionMetadata) GetVersion() string {+ if x != nil {+ return x.Version+ }+ return ""+}++func (x *ExtensionMetadata) GetDescription() string {+ if x != nil {+ return x.Description+ }+ return ""+}+var File_database_proto protoreflect.FileDescriptorvar file_database_proto_rawDesc = []byte{0x0a, 0x0e, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,0x12, 0x0e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65,- 0x22, 0xa3, 0x01, 0x0a, 0x10, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x4d, 0x65, 0x74,+ 0x22, 0xe6, 0x01, 0x0a, 0x10, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x4d, 0x65, 0x74,0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x38, 0x0a, 0x07, 0x73, 0x63, 0x68,0x65, 0x6d, 0x61, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x62, 0x79, 0x74,@@ -536,68 +688,87 @@ var file_database_proto_rawDesc = []byte{0x5f, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x68, 0x61, 0x72,0x61, 0x63, 0x74, 0x65, 0x72, 0x53, 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6c, 0x6c,0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6c,- 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x5b, 0x0a, 0x0e, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61,- 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65,- 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x35, 0x0a, 0x06,- 0x74, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x62,- 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x54, 0x61,- 0x62, 0x6c, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x06, 0x74, 0x61, 0x62,- 0x6c, 0x65, 0x73, 0x22, 0x83, 0x03, 0x0a, 0x0d, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x4d, 0x65, 0x74,- 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20,- 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x38, 0x0a, 0x07, 0x63, 0x6f, 0x6c,- 0x75, 0x6d, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x62, 0x79, 0x74,- 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x6f, 0x6c, 0x75,- 0x6d, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x07, 0x63, 0x6f, 0x6c, 0x75,- 0x6d, 0x6e, 0x73, 0x12, 0x37, 0x0a, 0x07, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x65, 0x73, 0x18, 0x03,- 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e,- 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x65, 0x74, 0x61, 0x64,- 0x61, 0x74, 0x61, 0x52, 0x07, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06,- 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x6e,- 0x67, 0x69, 0x6e, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f,- 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69,- 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f, 0x77, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18,- 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x72, 0x6f, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12,- 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x07, 0x20, 0x01,- 0x28, 0x03, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1d, 0x0a, 0x0a,- 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03,- 0x52, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x64,- 0x61, 0x74, 0x61, 0x5f, 0x66, 0x72, 0x65, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08,- 0x64, 0x61, 0x74, 0x61, 0x46, 0x72, 0x65, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x72, 0x65, 0x61,- 0x74, 0x65, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09,- 0x52, 0x0d, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12,- 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09,- 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x88, 0x02, 0x0a, 0x0e, 0x43, 0x6f,- 0x6c, 0x75, 0x6d, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04,+ 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x41, 0x0a, 0x0a, 0x65, 0x78, 0x74, 0x65, 0x6e, 0x73,+ 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x62, 0x79, 0x74,+ 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x45, 0x78, 0x74, 0x65,+ 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x0a, 0x65,+ 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0x8f, 0x01, 0x0a, 0x0e, 0x53, 0x63,+ 0x68, 0x65, 0x6d, 0x61, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04,+ 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,+ 0x12, 0x35, 0x0a, 0x06, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b,+ 0x32, 0x1d, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72,+ 0x65, 0x2e, 0x54, 0x61, 0x62, 0x6c, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52,+ 0x06, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x12, 0x32, 0x0a, 0x05, 0x76, 0x69, 0x65, 0x77, 0x73,+ 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73,+ 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x56, 0x69, 0x65, 0x77, 0x4d, 0x65, 0x74, 0x61,+ 0x64, 0x61, 0x74, 0x61, 0x52, 0x05, 0x76, 0x69, 0x65, 0x77, 0x73, 0x22, 0x83, 0x03, 0x0a, 0x0d,+ 0x54, 0x61, 0x62, 0x6c, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a,+ 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,+ 0x65, 0x12, 0x38, 0x0a, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03,+ 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74,+ 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61,+ 0x74, 0x61, 0x52, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x12, 0x37, 0x0a, 0x07, 0x69,+ 0x6e, 0x64, 0x65, 0x78, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x62,+ 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x49, 0x6e,+ 0x64, 0x65, 0x78, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x07, 0x69, 0x6e, 0x64,+ 0x65, 0x78, 0x65, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x18, 0x04,+ 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x12, 0x1c, 0x0a, 0x09,+ 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52,+ 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x72, 0x6f,+ 0x77, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x72,+ 0x6f, 0x77, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f,+ 0x73, 0x69, 0x7a, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61,+ 0x53, 0x69, 0x7a, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x5f, 0x73, 0x69,+ 0x7a, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x53,+ 0x69, 0x7a, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x66, 0x72, 0x65, 0x65,+ 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x46, 0x72, 0x65, 0x65,+ 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x5f, 0x6f, 0x70, 0x74, 0x69, 0x6f,+ 0x6e, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65,+ 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65,+ 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e,+ 0x74, 0x22, 0x88, 0x02, 0x0a, 0x0e, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x4d, 0x65, 0x74, 0x61,+ 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,+ 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69,+ 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69,+ 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x61, 0x73, 0x5f, 0x64, 0x65, 0x66, 0x61,+ 0x75, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x61, 0x73, 0x44, 0x65,+ 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,+ 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12,+ 0x1a, 0x0a, 0x08, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28,+ 0x08, 0x52, 0x08, 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x54,+ 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12,+ 0x23, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74,+ 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65,+ 0x72, 0x53, 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f,+ 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69,+ 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x09, 0x20,+ 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x5c, 0x0a, 0x0c,+ 0x56, 0x69, 0x65, 0x77, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04,+ 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,+ 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02,+ 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e,+ 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,+ 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0xbf, 0x01, 0x0a, 0x0d, 0x49,+ 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04,0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65,- 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01,- 0x28, 0x05, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1f, 0x0a, 0x0b,- 0x68, 0x61, 0x73, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,- 0x08, 0x52, 0x0a, 0x68, 0x61, 0x73, 0x44, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a,- 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,- 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6e, 0x75, 0x6c, 0x6c, 0x61,- 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6e, 0x75, 0x6c, 0x6c, 0x61,- 0x62, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28,- 0x09, 0x52, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x72, 0x61,- 0x63, 0x74, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c,- 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x53, 0x65, 0x74, 0x12, 0x1c, 0x0a, 0x09,- 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52,- 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f,- 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d,- 0x6d, 0x65, 0x6e, 0x74, 0x22, 0xbf, 0x01, 0x0a, 0x0d, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x65,- 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,- 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x65, 0x78,- 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52,- 0x0b, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04,- 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65,- 0x12, 0x16, 0x0a, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08,- 0x52, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, 0x6d,- 0x61, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x72, 0x69, 0x6d, 0x61,- 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x06, 0x20,- 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07,- 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63,- 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61,- 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72,- 0x6f, 0x74, 0x6f, 0x33,+ 0x12, 0x20, 0x0a, 0x0b, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x18,+ 0x02, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f,+ 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09,+ 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65,+ 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x12, 0x18,+ 0x0a, 0x07, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52,+ 0x07, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, 0x73, 0x69,+ 0x62, 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62,+ 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20,+ 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x63, 0x0a, 0x11,+ 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,+ 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,+ 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,+ 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12,+ 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03,+ 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f,+ 0x6e, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67,+ 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,}var (@@ -612,24 +783,28 @@ func file_database_proto_rawDescGZIP() []byte {return file_database_proto_rawDescData}-var file_database_proto_msgTypes = make([]protoimpl.MessageInfo, 5)+var file_database_proto_msgTypes = make([]protoimpl.MessageInfo, 7)var file_database_proto_goTypes = []interface{}{- (*DatabaseMetadata)(nil), // 0: bytebase.store.DatabaseMetadata- (*SchemaMetadata)(nil), // 1: bytebase.store.SchemaMetadata- (*TableMetadata)(nil), // 2: bytebase.store.TableMetadata- (*ColumnMetadata)(nil), // 3: bytebase.store.ColumnMetadata- (*IndexMetadata)(nil), // 4: bytebase.store.IndexMetadata+ (*DatabaseMetadata)(nil), // 0: bytebase.store.DatabaseMetadata+ (*SchemaMetadata)(nil), // 1: bytebase.store.SchemaMetadata+ (*TableMetadata)(nil), // 2: bytebase.store.TableMetadata+ (*ColumnMetadata)(nil), // 3: bytebase.store.ColumnMetadata+ (*ViewMetadata)(nil), // 4: bytebase.store.ViewMetadata+ (*IndexMetadata)(nil), // 5: bytebase.store.IndexMetadata+ (*ExtensionMetadata)(nil), // 6: bytebase.store.ExtensionMetadata}var file_database_proto_depIdxs = []int32{1, // 0: bytebase.store.DatabaseMetadata.schemas:type_name -> bytebase.store.SchemaMetadata- 2, // 1: bytebase.store.SchemaMetadata.tables:type_name -> bytebase.store.TableMetadata- 3, // 2: bytebase.store.TableMetadata.columns:type_name -> bytebase.store.ColumnMetadata- 4, // 3: bytebase.store.TableMetadata.indexes:type_name -> bytebase.store.IndexMetadata- 4, // [4:4] is the sub-list for method output_type- 4, // [4:4] is the sub-list for method input_type- 4, // [4:4] is the sub-list for extension type_name- 4, // [4:4] is the sub-list for extension extendee- 0, // [0:4] is the sub-list for field type_name+ 6, // 1: bytebase.store.DatabaseMetadata.extensions:type_name -> bytebase.store.ExtensionMetadata+ 2, // 2: bytebase.store.SchemaMetadata.tables:type_name -> bytebase.store.TableMetadata+ 4, // 3: bytebase.store.SchemaMetadata.views:type_name -> bytebase.store.ViewMetadata+ 3, // 4: bytebase.store.TableMetadata.columns:type_name -> bytebase.store.ColumnMetadata+ 5, // 5: bytebase.store.TableMetadata.indexes:type_name -> bytebase.store.IndexMetadata+ 6, // [6:6] is the sub-list for method output_type+ 6, // [6:6] is the sub-list for method input_type+ 6, // [6:6] is the sub-list for extension type_name+ 6, // [6:6] is the sub-list for extension extendee+ 0, // [0:6] is the sub-list for field type_name}func init() { file_database_proto_init() }@@ -687,6 +862,18 @@ func file_database_proto_init() {}}file_database_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {+ switch v := v.(*ViewMetadata); i {+ case 0:+ return &v.state+ case 1:+ return &v.sizeCache+ case 2:+ return &v.unknownFields+ default:+ return nil+ }+ }+ file_database_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {switch v := v.(*IndexMetadata); i {case 0:return &v.state@@ -698,6 +885,18 @@ func file_database_proto_init() {return nil}}+ file_database_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} {+ switch v := v.(*ExtensionMetadata); i {+ case 0:+ return &v.state+ case 1:+ return &v.sizeCache+ case 2:+ return &v.unknownFields+ default:+ return nil+ }+ }}type x struct{}out := protoimpl.TypeBuilder{@@ -705,7 +904,7 @@ func file_database_proto_init() {GoPackagePath: reflect.TypeOf(x{}).PkgPath(),RawDescriptor: file_database_proto_rawDesc,NumEnums: 0,- NumMessages: 5,+ NumMessages: 7,NumExtensions: 0,NumServices: 0,},diff --git a/proto/store/database.proto b/proto/store/database.protoindex aa02c6d9b8..83362d4311 100644--- a/proto/store/database.proto+++ b/proto/store/database.proto@@ -15,6 +15,9 @@ message DatabaseMetadata {// The collation is the collation of a database.string collation = 4;++ // The extensions is the list of extensions in a database.+ repeated ExtensionMetadata extensions = 5;}// SchemaMetadata is the metadata for schemas.@@ -26,6 +29,9 @@ message SchemaMetadata {// The tables is the list of tables in a schema.repeated TableMetadata tables = 2;++ // The views is the list of views in a schema.+ repeated ViewMetadata views = 3;}// TableMetadata is the metadata for tables.@@ -69,10 +75,10 @@ message TableMetadata {// ColumnMetadata is the metadata for columns.message ColumnMetadata {// The name is the name of a column.- string name = 1;+ string name = 1;// The position is the position in columns.- int32 position = 2;+ int32 position = 2;// The has_default is whether a column has a default.// In proto3, we cannot distinguish between an empty string default value or no default.@@ -83,32 +89,44 @@ message ColumnMetadata {string default = 4;// The nullable is the nullable of a column.- bool nullable = 5;+ bool nullable = 5;// The type is the type of a column.string Type = 6;// The character_set is the character_set of a column.- string character_set = 7;+ string character_set = 7;// The collation is the collation of a column.- string collation = 8;+ string collation = 8;// The comment is the comment of a column.- string comment = 9;+ string comment = 9;+}++// ViewMetadata is the metadata for views.+message ViewMetadata {+ // The name is the name of a view.+ string name = 1;++ // The definition is the definition of a view.+ string definition = 2;++ // The comment is the comment of a view.+ string comment = 3;}// IndexMetadata is the metadata for indexes.message IndexMetadata {// The name is the name of an index.- string name = 1;+ string name = 1;// The expressions are the ordered columns or expressions of an index.// This could refer to a column or an expression.- repeated string expressions = 2;+ repeated string expressions = 2;// The type is the type of an index.- string type = 3;+ string type = 3;// The unique is whether the index is unique.bool unique = 4;@@ -121,4 +139,17 @@ message IndexMetadata {// The comment is the comment of an index.string comment = 7;-}\ No newline at end of file+}+++// ExtensionMetadata is the metadata for extensions.+message ExtensionMetadata {+ // The name is the name of an extension.+ string name = 1;++ // The version is the version of an extension.+ string version = 2;++ // The description is the description of an extension.+ string description = 3;+}diff --git a/server/runner/schemasync/syncer.go b/server/runner/schemasync/syncer.goindex 9ab2c98a94..7a1e6cecb0 100644--- a/server/runner/schemasync/syncer.go+++ b/server/runner/schemasync/syncer.go@@ -446,7 +446,6 @@ func syncDBSchema(ctx context.Context, store *store.Store, database *api.Databas}func convertDBSchema(schema *db.Schema) *storepb.DatabaseMetadata {- // TODO(d): finish the implementation.// TODO(d): add unit test.databaseMetadata := &storepb.DatabaseMetadata{Name: schema.Name,@@ -456,10 +455,15 @@ func convertDBSchema(schema *db.Schema) *storepb.DatabaseMetadata {schemaNameMap := make(map[string]bool)schemaTableMap := make(map[string][]db.Table)+ schemaViewMap := make(map[string][]db.View)for _, table := range schema.TableList {schemaNameMap[table.Schema] = trueschemaTableMap[table.Schema] = append(schemaTableMap[table.Schema], table)}+ for _, view := range schema.ViewList {+ schemaNameMap[view.Schema] = true+ schemaViewMap[view.Schema] = append(schemaViewMap[view.Schema], view)+ }var schemaNames []stringfor schemaName := range schemaNameMap {schemaNames = append(schemaNames, schemaName)@@ -484,9 +488,80 @@ func convertDBSchema(schema *db.Schema) *storepb.DatabaseMetadata {CreateOptions: table.CreateOptions,Comment: table.Comment,}++ sort.Slice(table.ColumnList, func(i, j int) bool {+ return table.ColumnList[i].Position < table.ColumnList[j].Position+ })+ for _, column := range table.ColumnList {+ columnMetadata := &storepb.ColumnMetadata{+ Name: column.Name,+ Position: int32(column.Position),+ Nullable: column.Nullable,+ Type: column.Type,+ CharacterSet: column.CharacterSet,+ Collation: column.Collation,+ Comment: column.Comment,+ }+ if column.Default != nil {+ columnMetadata.HasDefault = true+ columnMetadata.Default = *column.Default+ }+ tableMetadata.Columns = append(tableMetadata.Columns, columnMetadata)+ }++ indexMap := make(map[string][]db.Index)+ for _, expression := range table.IndexList {+ indexMap[expression.Name] = append(indexMap[expression.Name], expression)+ }+ var indexNames []string+ for indexName := range indexMap {+ indexNames = append(indexNames, indexName)+ }+ sort.Strings(indexNames)+ for _, indexName := range indexNames {+ expressionList := indexMap[indexName]+ sort.Slice(expressionList, func(i, j int) bool {+ return expressionList[i].Position < expressionList[j].Position+ })+ indexMetadata := &storepb.IndexMetadata{+ Name: expressionList[0].Name,+ Type: expressionList[0].Type,+ Unique: expressionList[0].Unique,+ Primary: expressionList[0].Primary,+ Visible: expressionList[0].Visible,+ Comment: expressionList[0].Comment,+ }+ for _, expression := range expressionList {+ indexMetadata.Expressions = append(indexMetadata.Expressions, expression.Expression)+ }+ tableMetadata.Indexes = append(tableMetadata.Indexes, indexMetadata)+ }+schemaMetadata.Tables = append(schemaMetadata.Tables, tableMetadata)}+ views := schemaViewMap[schemaName]+ sort.Slice(views, func(i, j int) bool {+ return views[i].ShortName < views[j].ShortName+ })+ for _, view := range views {+ schemaMetadata.Views = append(schemaMetadata.Views, &storepb.ViewMetadata{+ Name: view.ShortName,+ Definition: view.Definition,+ Comment: view.Comment,+ })+ }databaseMetadata.Schemas = append(databaseMetadata.Schemas, schemaMetadata)}++ sort.Slice(schema.ExtensionList, func(i, j int) bool {+ return schema.ExtensionList[i].Name < schema.ExtensionList[j].Name+ })+ for _, extension := range schema.ExtensionList {+ databaseMetadata.Extensions = append(databaseMetadata.Extensions, &storepb.ExtensionMetadata{+ Name: extension.Name,+ Version: extension.Version,+ Description: extension.Description,+ })+ }return databaseMetadata}diff --git a/store/catalog.go b/store/catalog.goindex c1cdaba2e7..3c6f5a81e3 100644--- a/store/catalog.go+++ b/store/catalog.go@@ -170,8 +170,6 @@ func splitPGSchema(name string) (string, string, error) {func convertView(view *api.View) *catalog.View {return &catalog.View{Name: view.Name,- CreatedTs: view.CreatedTs,- UpdatedTs: view.UpdatedTs,Definition: view.Definition,Comment: view.Comment,}