...
 
Commits (2)
  • Lucy Zhang's avatar
    sql: add SchemaDescriptor · 0ea6acc8
    Lucy Zhang authored
    This PR adds a `SchemaDescriptor` type to the `sqlbase.Descriptor`
    union.
    
    Release note: None
    0ea6acc8
  • craig[bot]'s avatar
    Merge #48725 · 62f32ca9
    craig[bot] authored
    48725: sql: add SchemaDescriptor r=lucy-zhang a=lucy-zhang
    
    This PR adds a `SchemaDescriptor` type to the `sqlbase.Descriptor`
    union.
    
    Release note: None
    Co-authored-by: default avatarLucy Zhang <[email protected]>
    62f32ca9
......@@ -26,6 +26,8 @@ import (
var _ DescriptorProto = &DatabaseDescriptor{}
var _ DescriptorProto = &TableDescriptor{}
var _ DescriptorProto = &TypeDescriptor{}
var _ DescriptorProto = &SchemaDescriptor{}
// DescriptorKey is the interface implemented by both
// databaseKey and tableKey. It is used to easily get the
......@@ -35,8 +37,7 @@ type DescriptorKey interface {
Name() string
}
// DescriptorProto is the interface implemented by DatabaseDescriptor,
// TableDescriptor, and TypeDescriptor.
// DescriptorProto is the interface implemented by all Descriptors.
// TODO(marc): this is getting rather large.
type DescriptorProto interface {
protoutil.Message
......@@ -61,6 +62,8 @@ func WrapDescriptor(descriptor DescriptorProto) *Descriptor {
desc.Union = &Descriptor_Database{Database: t}
case *TypeDescriptor:
desc.Union = &Descriptor_Type{Type: t}
case *SchemaDescriptor:
desc.Union = &Descriptor_Schema{Schema: t}
default:
panic(fmt.Sprintf("unknown descriptor type: %s", descriptor.TypeName()))
}
......
......@@ -4158,6 +4158,26 @@ func (desc *TypeDescriptor) HydrateTypeInfo(typ *types.T) error {
// NameResolutionResult implements the NameResolutionResult interface.
func (desc *TypeDescriptor) NameResolutionResult() {}
// GetAuditMode implements the DescriptorProto interface.
func (desc *SchemaDescriptor) GetAuditMode() TableDescriptor_AuditMode {
return TableDescriptor_DISABLED
}
// SetID implements the DescriptorProto interface.
func (desc *SchemaDescriptor) SetID(id ID) {
desc.ID = id
}
// TypeName implements the DescriptorProto interface.
func (desc *SchemaDescriptor) TypeName() string {
return "schema"
}
// SetName implements the DescriptorProto interface.
func (desc *SchemaDescriptor) SetName(name string) {
desc.Name = name
}
// DatabaseKey implements DescriptorKey.
type DatabaseKey struct {
name string
......
This diff was suppressed by a .gitattributes entry.
......@@ -964,8 +964,8 @@ message TableDescriptor {
}
// DatabaseDescriptor represents a namespace (aka database) and is stored
// in a structured metadata key. The DatabaseDescriptor has a globally-unique
// ID shared with the TableDescriptor ID.
// in a structured metadata key. The DatabaseDescriptor has a globally-unique ID
// shared with other Descriptors.
// Permissions are applied to all tables in the namespace.
message DatabaseDescriptor {
option (gogoproto.equal) = true;
......@@ -979,8 +979,8 @@ message DatabaseDescriptor {
}
// TypeDescriptor represents a user defined type and is stored in a structured
// metadata key. The TypeDescriptor has a globally-unique ID shared with the
// TableDescriptor and DatabaseDescriptor ID's.
// metadata key. The TypeDescriptor has a globally-unique ID shared with other
// Descriptors.
message TypeDescriptor {
option (gogoproto.equal) = true;
// Needed for the descriptorProto interface.
......@@ -1029,12 +1029,36 @@ message TypeDescriptor {
// TODO (rohany): Do we need a draining names like the table descriptor?
}
// Descriptor is a union type holding either a table or database descriptor.
// SchemaDescriptor represents a physical schema and is stored in a structured
// metadata key.
message SchemaDescriptor {
option (gogoproto.equal) = true;
// Needed for the descriptorProto interface.
option (gogoproto.goproto_getters) = true;
// parent_id refers to the database the schema is in.
optional uint32 parent_id = 1
[(gogoproto.nullable) = false, (gogoproto.customname) = "ParentID", (gogoproto.casttype) = "ID"];
// name is the name of the schema.
optional string name = 2 [(gogoproto.nullable) = false];
// id is the schema ID, globally unique across all descriptors.
optional uint32 id = 3
[(gogoproto.nullable) = false, (gogoproto.customname) = "ID", (gogoproto.casttype) = "ID"];
// privileges contains the privileges for the schema.
optional PrivilegeDescriptor privileges = 4;
}
// Descriptor is a union type for descriptors for tables, schemas, databases,
// and types.
message Descriptor {
option (gogoproto.equal) = true;
oneof union {
TableDescriptor table = 1;
DatabaseDescriptor database = 2;
TypeDescriptor type = 3;
SchemaDescriptor schema = 4;
}
}