Skip to content

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

feat: add more schema metadata proto definition (#3761)

Danny Xu760464c51b1c
diff --git a/plugin/advisor/catalog/catalog.go b/plugin/advisor/catalog/catalog.go
index bde2644fd6..9cffcb090b 100644
--- a/plugin/advisor/catalog/catalog.go
+++ b/plugin/advisor/catalog/catalog.go
@@ -30,11 +30,7 @@ type Schema struct {
// Table is the database table.
type Table struct {
Name string
- // CreatedTs isn't supported for ClickHouse, SQLite.
- CreatedTs int64
- // UpdatedTs isn't supported for SQLite.
- UpdatedTs int64
- Type string
+ Type string
// Engine isn't supported for Postgres, Snowflake, SQLite.
Engine string
// Collation isn't supported for Postgres, ClickHouse, Snowflake, SQLite.
diff --git a/proto/generated-go/store/database.pb.go b/proto/generated-go/store/database.pb.go
index e2f9c4cabd..ca2e9c4798 100644
--- a/proto/generated-go/store/database.pb.go
+++ b/proto/generated-go/store/database.pb.go
@@ -20,20 +20,99 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
-// SchemaMetadata defines the schema for database schema metadata.
+// DatabaseMetadata is the metadata for databases.
+type DatabaseMetadata struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+ // The schemas is the list of schemas in a database.
+ Schemas []*SchemaMetadata `protobuf:"bytes,2,rep,name=schemas,proto3" json:"schemas,omitempty"`
+ // The character_set is the character set of a database.
+ 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"`
+}
+
+func (x *DatabaseMetadata) Reset() {
+ *x = DatabaseMetadata{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_database_proto_msgTypes[0]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *DatabaseMetadata) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*DatabaseMetadata) ProtoMessage() {}
+
+func (x *DatabaseMetadata) ProtoReflect() protoreflect.Message {
+ mi := &file_database_proto_msgTypes[0]
+ 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 DatabaseMetadata.ProtoReflect.Descriptor instead.
+func (*DatabaseMetadata) Descriptor() ([]byte, []int) {
+ return file_database_proto_rawDescGZIP(), []int{0}
+}
+
+func (x *DatabaseMetadata) GetName() string {
+ if x != nil {
+ return x.Name
+ }
+ return ""
+}
+
+func (x *DatabaseMetadata) GetSchemas() []*SchemaMetadata {
+ if x != nil {
+ return x.Schemas
+ }
+ return nil
+}
+
+func (x *DatabaseMetadata) GetCharacterSet() string {
+ if x != nil {
+ return x.CharacterSet
+ }
+ return ""
+}
+
+func (x *DatabaseMetadata) GetCollation() string {
+ if x != nil {
+ return x.Collation
+ }
+ return ""
+}
+
+// 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 {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- // The table_metadata is the metadata for a list of tables in a database.
- TableMetadata []*TableMetadata `protobuf:"bytes,1,rep,name=table_metadata,json=tableMetadata,proto3" json:"table_metadata,omitempty"`
+ // The name is the schema name.
+ // It is an empty string for databases without such concept such as MySQL.
+ 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"`
}
func (x *SchemaMetadata) Reset() {
*x = SchemaMetadata{}
if protoimpl.UnsafeEnabled {
- mi := &file_database_proto_msgTypes[0]
+ mi := &file_database_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -46,7 +125,7 @@ func (x *SchemaMetadata) String() string {
func (*SchemaMetadata) ProtoMessage() {}
func (x *SchemaMetadata) ProtoReflect() protoreflect.Message {
- mi := &file_database_proto_msgTypes[0]
+ mi := &file_database_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -59,32 +138,57 @@ func (x *SchemaMetadata) ProtoReflect() protoreflect.Message {
// Deprecated: Use SchemaMetadata.ProtoReflect.Descriptor instead.
func (*SchemaMetadata) Descriptor() ([]byte, []int) {
- return file_database_proto_rawDescGZIP(), []int{0}
+ return file_database_proto_rawDescGZIP(), []int{1}
}
-func (x *SchemaMetadata) GetTableMetadata() []*TableMetadata {
+func (x *SchemaMetadata) GetName() string {
if x != nil {
- return x.TableMetadata
+ return x.Name
+ }
+ return ""
+}
+
+func (x *SchemaMetadata) GetTables() []*TableMetadata {
+ if x != nil {
+ return x.Tables
}
return nil
}
-// TableMetadata is the metadata for a database table.
+// TableMetadata is the metadata for tables.
type TableMetadata struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- // The schema is the schema name of a table. It is an empty string for databases without such concept such as MySQL.
- Schema string `protobuf:"bytes,1,opt,name=schema,proto3" json:"schema,omitempty"`
// The name is the name of a table.
- Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+ // The columns is the ordered list of columns in a table.
+ Columns []*ColumnMetadata `protobuf:"bytes,2,rep,name=columns,proto3" json:"columns,omitempty"`
+ // The indexes is the list of indexes in a table.
+ Indexes []*IndexMetadata `protobuf:"bytes,3,rep,name=indexes,proto3" json:"indexes,omitempty"`
+ // The engine is the engine of a table.
+ Engine string `protobuf:"bytes,4,opt,name=engine,proto3" json:"engine,omitempty"`
+ // The collation is the collation of a table.
+ Collation string `protobuf:"bytes,5,opt,name=collation,proto3" json:"collation,omitempty"`
+ // The row_count is the estimated number of rows of a table.
+ RowCount int64 `protobuf:"varint,6,opt,name=row_count,json=rowCount,proto3" json:"row_count,omitempty"`
+ // The data_size is the estimated data size of a table.
+ DataSize int64 `protobuf:"varint,7,opt,name=data_size,json=dataSize,proto3" json:"data_size,omitempty"`
+ // The index_size is the estimated index size of a table.
+ IndexSize int64 `protobuf:"varint,8,opt,name=index_size,json=indexSize,proto3" json:"index_size,omitempty"`
+ // The data_free is the estimated free data size of a table.
+ DataFree int64 `protobuf:"varint,9,opt,name=data_free,json=dataFree,proto3" json:"data_free,omitempty"`
+ // The create_options is the create option of a table.
+ CreateOptions string `protobuf:"bytes,10,opt,name=create_options,json=createOptions,proto3" json:"create_options,omitempty"`
+ // The comment is the comment of a table.
+ Comment string `protobuf:"bytes,11,opt,name=comment,proto3" json:"comment,omitempty"`
}
func (x *TableMetadata) Reset() {
*x = TableMetadata{}
if protoimpl.UnsafeEnabled {
- mi := &file_database_proto_msgTypes[1]
+ mi := &file_database_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@@ -97,7 +201,7 @@ func (x *TableMetadata) String() string {
func (*TableMetadata) ProtoMessage() {}
func (x *TableMetadata) ProtoReflect() protoreflect.Message {
- mi := &file_database_proto_msgTypes[1]
+ mi := &file_database_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@@ -110,40 +214,390 @@ func (x *TableMetadata) ProtoReflect() protoreflect.Message {
// Deprecated: Use TableMetadata.ProtoReflect.Descriptor instead.
func (*TableMetadata) Descriptor() ([]byte, []int) {
- return file_database_proto_rawDescGZIP(), []int{1}
+ return file_database_proto_rawDescGZIP(), []int{2}
}
-func (x *TableMetadata) GetSchema() string {
+func (x *TableMetadata) GetName() string {
if x != nil {
- return x.Schema
+ return x.Name
}
return ""
}
-func (x *TableMetadata) GetName() string {
+func (x *TableMetadata) GetColumns() []*ColumnMetadata {
+ if x != nil {
+ return x.Columns
+ }
+ return nil
+}
+
+func (x *TableMetadata) GetIndexes() []*IndexMetadata {
+ if x != nil {
+ return x.Indexes
+ }
+ return nil
+}
+
+func (x *TableMetadata) GetEngine() string {
+ if x != nil {
+ return x.Engine
+ }
+ return ""
+}
+
+func (x *TableMetadata) GetCollation() string {
+ if x != nil {
+ return x.Collation
+ }
+ return ""
+}
+
+func (x *TableMetadata) GetRowCount() int64 {
+ if x != nil {
+ return x.RowCount
+ }
+ return 0
+}
+
+func (x *TableMetadata) GetDataSize() int64 {
+ if x != nil {
+ return x.DataSize
+ }
+ return 0
+}
+
+func (x *TableMetadata) GetIndexSize() int64 {
+ if x != nil {
+ return x.IndexSize
+ }
+ return 0
+}
+
+func (x *TableMetadata) GetDataFree() int64 {
+ if x != nil {
+ return x.DataFree
+ }
+ return 0
+}
+
+func (x *TableMetadata) GetCreateOptions() string {
+ if x != nil {
+ return x.CreateOptions
+ }
+ return ""
+}
+
+func (x *TableMetadata) GetComment() string {
+ if x != nil {
+ return x.Comment
+ }
+ return ""
+}
+
+// ColumnMetadata is the metadata for columns.
+type ColumnMetadata struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ // The name is the name of a column.
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+ // The position is the position in columns.
+ Position int32 `protobuf:"varint,2,opt,name=position,proto3" json:"position,omitempty"`
+ // The has_default is whether a column has a default.
+ // In proto3, we cannot distinguish between an empty string default value or no default.
+ // We have to introduce a boolean field to indicate the existance of a default.
+ HasDefault bool `protobuf:"varint,3,opt,name=has_default,json=hasDefault,proto3" json:"has_default,omitempty"`
+ // The default is the default of a column.
+ Default string `protobuf:"bytes,4,opt,name=default,proto3" json:"default,omitempty"`
+ // The nullable is the nullable of a column.
+ Nullable bool `protobuf:"varint,5,opt,name=nullable,proto3" json:"nullable,omitempty"`
+ // The type is the type of a column.
+ Type string `protobuf:"bytes,6,opt,name=Type,proto3" json:"Type,omitempty"`
+ // The character_set is the character_set of a column.
+ CharacterSet string `protobuf:"bytes,7,opt,name=character_set,json=characterSet,proto3" json:"character_set,omitempty"`
+ // The collation is the collation of a column.
+ Collation string `protobuf:"bytes,8,opt,name=collation,proto3" json:"collation,omitempty"`
+ // The comment is the comment of a column.
+ Comment string `protobuf:"bytes,9,opt,name=comment,proto3" json:"comment,omitempty"`
+}
+
+func (x *ColumnMetadata) Reset() {
+ *x = ColumnMetadata{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_database_proto_msgTypes[3]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *ColumnMetadata) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*ColumnMetadata) ProtoMessage() {}
+
+func (x *ColumnMetadata) ProtoReflect() protoreflect.Message {
+ mi := &file_database_proto_msgTypes[3]
+ 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 ColumnMetadata.ProtoReflect.Descriptor instead.
+func (*ColumnMetadata) Descriptor() ([]byte, []int) {
+ return file_database_proto_rawDescGZIP(), []int{3}
+}
+
+func (x *ColumnMetadata) GetName() string {
if x != nil {
return x.Name
}
return ""
}
+func (x *ColumnMetadata) GetPosition() int32 {
+ if x != nil {
+ return x.Position
+ }
+ return 0
+}
+
+func (x *ColumnMetadata) GetHasDefault() bool {
+ if x != nil {
+ return x.HasDefault
+ }
+ return false
+}
+
+func (x *ColumnMetadata) GetDefault() string {
+ if x != nil {
+ return x.Default
+ }
+ return ""
+}
+
+func (x *ColumnMetadata) GetNullable() bool {
+ if x != nil {
+ return x.Nullable
+ }
+ return false
+}
+
+func (x *ColumnMetadata) GetType() string {
+ if x != nil {
+ return x.Type
+ }
+ return ""
+}
+
+func (x *ColumnMetadata) GetCharacterSet() string {
+ if x != nil {
+ return x.CharacterSet
+ }
+ return ""
+}
+
+func (x *ColumnMetadata) GetCollation() string {
+ if x != nil {
+ return x.Collation
+ }
+ return ""
+}
+
+func (x *ColumnMetadata) GetComment() string {
+ if x != nil {
+ return x.Comment
+ }
+ return ""
+}
+
+// IndexMetadata is the metadata for indexes.
+type IndexMetadata struct {
+ state protoimpl.MessageState
+ sizeCache protoimpl.SizeCache
+ unknownFields protoimpl.UnknownFields
+
+ // The name is the name of an index.
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+ // The expressions are the ordered columns or expressions of an index.
+ // This could refer to a column or an expression.
+ Expressions []string `protobuf:"bytes,2,rep,name=expressions,proto3" json:"expressions,omitempty"`
+ // The type is the type of an index.
+ Type string `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
+ // The unique is whether the index is unique.
+ Unique bool `protobuf:"varint,4,opt,name=unique,proto3" json:"unique,omitempty"`
+ // The primary is whether the index is a primary key index.
+ Primary bool `protobuf:"varint,5,opt,name=primary,proto3" json:"primary,omitempty"`
+ // The visible is whether the index is visible.
+ Visible bool `protobuf:"varint,6,opt,name=visible,proto3" json:"visible,omitempty"`
+ // The comment is the comment of an index.
+ Comment string `protobuf:"bytes,7,opt,name=comment,proto3" json:"comment,omitempty"`
+}
+
+func (x *IndexMetadata) Reset() {
+ *x = IndexMetadata{}
+ if protoimpl.UnsafeEnabled {
+ mi := &file_database_proto_msgTypes[4]
+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
+ ms.StoreMessageInfo(mi)
+ }
+}
+
+func (x *IndexMetadata) String() string {
+ return protoimpl.X.MessageStringOf(x)
+}
+
+func (*IndexMetadata) ProtoMessage() {}
+
+func (x *IndexMetadata) 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 IndexMetadata.ProtoReflect.Descriptor instead.
+func (*IndexMetadata) Descriptor() ([]byte, []int) {
+ return file_database_proto_rawDescGZIP(), []int{4}
+}
+
+func (x *IndexMetadata) GetName() string {
+ if x != nil {
+ return x.Name
+ }
+ return ""
+}
+
+func (x *IndexMetadata) GetExpressions() []string {
+ if x != nil {
+ return x.Expressions
+ }
+ return nil
+}
+
+func (x *IndexMetadata) GetType() string {
+ if x != nil {
+ return x.Type
+ }
+ return ""
+}
+
+func (x *IndexMetadata) GetUnique() bool {
+ if x != nil {
+ return x.Unique
+ }
+ return false
+}
+
+func (x *IndexMetadata) GetPrimary() bool {
+ if x != nil {
+ return x.Primary
+ }
+ return false
+}
+
+func (x *IndexMetadata) GetVisible() bool {
+ if x != nil {
+ return x.Visible
+ }
+ return false
+}
+
+func (x *IndexMetadata) GetComment() string {
+ if x != nil {
+ return x.Comment
+ }
+ return ""
+}
+
var File_database_proto protoreflect.FileDescriptor
var 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, 0x56, 0x0a, 0x0e, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61,
- 0x74, 0x61, 0x12, 0x44, 0x0a, 0x0e, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x6d, 0x65, 0x74, 0x61,
- 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 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, 0x0d, 0x74, 0x61, 0x62, 0x6c, 0x65,
- 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3b, 0x0a, 0x0d, 0x54, 0x61, 0x62, 0x6c,
- 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x63, 0x68,
- 0x65, 0x6d, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d,
- 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
- 0x04, 0x6e, 0x61, 0x6d, 0x65, 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,
+ 0x22, 0xa3, 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,
+ 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x53, 0x63, 0x68, 0x65,
+ 0x6d, 0x61, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x52, 0x07, 0x73, 0x63, 0x68, 0x65,
+ 0x6d, 0x61, 0x73, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72,
+ 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,
+ 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,
}
var (
@@ -158,18 +612,24 @@ func file_database_proto_rawDescGZIP() []byte {
return file_database_proto_rawDescData
}
-var file_database_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
+var file_database_proto_msgTypes = make([]protoimpl.MessageInfo, 5)
var file_database_proto_goTypes = []interface{}{
- (*SchemaMetadata)(nil), // 0: bytebase.store.SchemaMetadata
- (*TableMetadata)(nil), // 1: bytebase.store.TableMetadata
+ (*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
}
var file_database_proto_depIdxs = []int32{
- 1, // 0: bytebase.store.SchemaMetadata.table_metadata:type_name -> bytebase.store.TableMetadata
- 1, // [1:1] is the sub-list for method output_type
- 1, // [1:1] is the sub-list for method input_type
- 1, // [1:1] is the sub-list for extension type_name
- 1, // [1:1] is the sub-list for extension extendee
- 0, // [0:1] is the sub-list for field type_name
+ 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
}
func init() { file_database_proto_init() }
@@ -179,7 +639,7 @@ func file_database_proto_init() {
}
if !protoimpl.UnsafeEnabled {
file_database_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
- switch v := v.(*SchemaMetadata); i {
+ switch v := v.(*DatabaseMetadata); i {
case 0:
return &v.state
case 1:
@@ -191,6 +651,18 @@ func file_database_proto_init() {
}
}
file_database_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*SchemaMetadata); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ file_database_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*TableMetadata); i {
case 0:
return &v.state
@@ -202,6 +674,30 @@ func file_database_proto_init() {
return nil
}
}
+ file_database_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*ColumnMetadata); i {
+ case 0:
+ return &v.state
+ case 1:
+ return &v.sizeCache
+ case 2:
+ return &v.unknownFields
+ default:
+ return nil
+ }
+ }
+ file_database_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
+ switch v := v.(*IndexMetadata); 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{
@@ -209,7 +705,7 @@ func file_database_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_database_proto_rawDesc,
NumEnums: 0,
- NumMessages: 2,
+ NumMessages: 5,
NumExtensions: 0,
NumServices: 0,
},
diff --git a/proto/store/database.proto b/proto/store/database.proto
index 6a0f5ec264..aa02c6d9b8 100644
--- a/proto/store/database.proto
+++ b/proto/store/database.proto
@@ -3,16 +3,122 @@ syntax = "proto3";
package bytebase.store;
option go_package = "generated-go/store";
-// SchemaMetadata defines the schema for database schema metadata.
+// DatabaseMetadata is the metadata for databases.
+message DatabaseMetadata {
+ string name = 1;
+
+ // The schemas is the list of schemas in a database.
+ repeated SchemaMetadata schemas = 2;
+
+ // The character_set is the character set of a database.
+ string character_set = 3;
+
+ // The collation is the collation of a database.
+ string collation = 4;
+}
+
+// SchemaMetadata is the metadata for schemas.
+// This is the concept of schema in Postgres, but it's a no-op for MySQL.
message SchemaMetadata {
- // The table_metadata is the metadata for a list of tables in a database.
- repeated TableMetadata table_metadata = 1;
+ // The name is the schema name.
+ // It is an empty string for databases without such concept such as MySQL.
+ string name = 1;
+
+ // The tables is the list of tables in a schema.
+ repeated TableMetadata tables = 2;
}
-// TableMetadata is the metadata for a database table.
+// TableMetadata is the metadata for tables.
message TableMetadata {
- // The schema is the schema name of a table. It is an empty string for databases without such concept such as MySQL.
- string schema = 1;
// The name is the name of a table.
- string name = 2;
+ string name = 1;
+
+ // The columns is the ordered list of columns in a table.
+ repeated ColumnMetadata columns = 2;
+
+ // The indexes is the list of indexes in a table.
+ repeated IndexMetadata indexes = 3;
+
+ // TODO(d): figure out whether we need to store table type such as "BASE TABLE".
+
+ // The engine is the engine of a table.
+ string engine = 4;
+
+ // The collation is the collation of a table.
+ string collation = 5;
+
+ // The row_count is the estimated number of rows of a table.
+ int64 row_count = 6;
+
+ // The data_size is the estimated data size of a table.
+ int64 data_size = 7;
+
+ // The index_size is the estimated index size of a table.
+ int64 index_size = 8;
+
+ // The data_free is the estimated free data size of a table.
+ int64 data_free = 9;
+
+ // The create_options is the create option of a table.
+ string create_options = 10;
+
+ // The comment is the comment of a table.
+ string comment = 11;
+}
+
+// ColumnMetadata is the metadata for columns.
+message ColumnMetadata {
+ // The name is the name of a column.
+ string name = 1;
+
+ // The position is the position in columns.
+ 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.
+ // We have to introduce a boolean field to indicate the existance of a default.
+ bool has_default = 3;
+
+ // The default is the default of a column.
+ string default = 4;
+
+ // The nullable is the nullable of a column.
+ 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;
+
+ // The collation is the collation of a column.
+ string collation = 8;
+
+ // The comment is the comment of a column.
+ string comment = 9;
+}
+
+// IndexMetadata is the metadata for indexes.
+message IndexMetadata {
+ // The name is the name of an index.
+ 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;
+
+ // The type is the type of an index.
+ string type = 3;
+
+ // The unique is whether the index is unique.
+ bool unique = 4;
+
+ // The primary is whether the index is a primary key index.
+ bool primary = 5;
+
+ // The visible is whether the index is visible.
+ bool visible = 6;
+
+ // The comment is the comment of an index.
+ string comment = 7;
}
\ No newline at end of file
diff --git a/server/runner/schemasync/syncer.go b/server/runner/schemasync/syncer.go
index 7b8471600e..9ab2c98a94 100644
--- a/server/runner/schemasync/syncer.go
+++ b/server/runner/schemasync/syncer.go
@@ -5,6 +5,7 @@ import (
"context"
"fmt"
"net/http"
+ "sort"
"sync"
"time"
@@ -424,15 +425,9 @@ func syncDBSchema(ctx context.Context, store *store.Store, database *api.Databas
if err != nil {
return err
}
- // TODO(d): finish the implementation.
- metadata := &storepb.SchemaMetadata{}
- for _, t := range schema.TableList {
- metadata.TableMetadata = append(metadata.TableMetadata, &storepb.TableMetadata{
- Schema: t.Schema,
- Name: t.ShortName,
- })
- }
- bytes, err := protojson.Marshal(metadata)
+
+ databaseMetadata := convertDBSchema(schema)
+ bytes, err := protojson.Marshal(databaseMetadata)
if err != nil {
return err
}
@@ -449,3 +444,49 @@ func syncDBSchema(ctx context.Context, store *store.Store, database *api.Databas
}
return nil
}
+
+func convertDBSchema(schema *db.Schema) *storepb.DatabaseMetadata {
+ // TODO(d): finish the implementation.
+ // TODO(d): add unit test.
+ databaseMetadata := &storepb.DatabaseMetadata{
+ Name: schema.Name,
+ CharacterSet: schema.CharacterSet,
+ Collation: schema.Collation,
+ }
+
+ schemaNameMap := make(map[string]bool)
+ schemaTableMap := make(map[string][]db.Table)
+ for _, table := range schema.TableList {
+ schemaNameMap[table.Schema] = true
+ schemaTableMap[table.Schema] = append(schemaTableMap[table.Schema], table)
+ }
+ var schemaNames []string
+ for schemaName := range schemaNameMap {
+ schemaNames = append(schemaNames, schemaName)
+ }
+ sort.Strings(schemaNames)
+ for _, schemaName := range schemaNames {
+ schemaMetadata := &storepb.SchemaMetadata{
+ Name: schemaName,
+ }
+ tables := schemaTableMap[schemaName]
+ sort.Slice(tables, func(i, j int) bool {
+ return tables[i].ShortName < tables[j].ShortName
+ })
+ for _, table := range tables {
+ tableMetadata := &storepb.TableMetadata{
+ Name: table.ShortName,
+ Engine: table.Engine,
+ Collation: table.Collation,
+ RowCount: table.RowCount,
+ DataSize: table.DataSize,
+ DataFree: table.DataFree,
+ CreateOptions: table.CreateOptions,
+ Comment: table.Comment,
+ }
+ schemaMetadata.Tables = append(schemaMetadata.Tables, tableMetadata)
+ }
+ databaseMetadata.Schemas = append(databaseMetadata.Schemas, schemaMetadata)
+ }
+ return databaseMetadata
+}
diff --git a/store/catalog.go b/store/catalog.go
index c3a6f2999e..c1cdaba2e7 100644
--- a/store/catalog.go
+++ b/store/catalog.go
@@ -180,8 +180,6 @@ func convertView(view *api.View) *catalog.View {
func convertTable(table *api.Table) *catalog.Table {
return &catalog.Table{
Name: table.Name,
- CreatedTs: table.CreatedTs,
- UpdatedTs: table.UpdatedTs,
Type: table.Type,
Engine: table.Engine,
Collation: table.Collation,