本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/sql/sqlbase.TableDescriptor.SetUpVersion方法的典型用法代碼示例。如果您正苦於以下問題:Golang TableDescriptor.SetUpVersion方法的具體用法?Golang TableDescriptor.SetUpVersion怎麽用?Golang TableDescriptor.SetUpVersion使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/sql/sqlbase.TableDescriptor
的用法示例。
在下文中一共展示了TableDescriptor.SetUpVersion方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RenameTable
//.........這裏部分代碼省略.........
return nil, sqlbase.NewUndefinedViewError(oldTn.String())
}
} else {
tableDesc, err = p.getTableDesc(oldTn)
if err != nil {
return nil, err
}
if tableDesc == nil {
if n.IfExists {
// Noop.
return &emptyNode{}, nil
}
// Key does not exist, but we want it to: error out.
return nil, sqlbase.NewUndefinedTableError(oldTn.String())
}
if tableDesc.State != sqlbase.TableDescriptor_PUBLIC {
return nil, sqlbase.NewUndefinedTableError(oldTn.String())
}
}
if err := p.checkPrivilege(tableDesc, privilege.DROP); err != nil {
return nil, err
}
// Check if any views depend on this table/view. Because our views
// are currently just stored as strings, they explicitly specify the name
// of everything they depend on. Rather than trying to rewrite the view's
// query with the new name, we simply disallow such renames for now.
if len(tableDesc.DependedOnBy) > 0 {
return nil, p.dependentViewRenameError(
tableDesc.TypeName(), oldTn.String(), tableDesc.ParentID, tableDesc.DependedOnBy[0].ID)
}
// Check if target database exists.
targetDbDesc, err := p.mustGetDatabaseDesc(newTn.Database())
if err != nil {
return nil, err
}
if err := p.checkPrivilege(targetDbDesc, privilege.CREATE); err != nil {
return nil, err
}
// oldTn and newTn are already normalized, so we can compare directly here.
if oldTn.Database() == newTn.Database() && oldTn.Table() == newTn.Table() {
// Noop.
return &emptyNode{}, nil
}
tableDesc.SetName(newTn.Table())
tableDesc.ParentID = targetDbDesc.ID
descKey := sqlbase.MakeDescMetadataKey(tableDesc.GetID())
newTbKey := tableKey{targetDbDesc.ID, newTn.Table()}.Key()
if err := tableDesc.Validate(p.txn); err != nil {
return nil, err
}
descID := tableDesc.GetID()
descDesc := sqlbase.WrapDescriptor(tableDesc)
if err := tableDesc.SetUpVersion(); err != nil {
return nil, err
}
renameDetails := sqlbase.TableDescriptor_RenameInfo{
OldParentID: dbDesc.ID,
OldName: oldTn.Table()}
tableDesc.Renames = append(tableDesc.Renames, renameDetails)
if err := p.writeTableDesc(tableDesc); err != nil {
return nil, err
}
// We update the descriptor to the new name, but also leave the mapping of the
// old name to the id, so that the name is not reused until the schema changer
// has made sure it's not in use any more.
b := &client.Batch{}
b.Put(descKey, descDesc)
b.CPut(newTbKey, descID, nil)
if err := p.txn.Run(b); err != nil {
if _, ok := err.(*roachpb.ConditionFailedError); ok {
return nil, sqlbase.NewRelationAlreadyExistsError(newTn.Table())
}
return nil, err
}
p.notifySchemaChange(tableDesc.ID, sqlbase.InvalidMutationID)
p.setTestingVerifyMetadata(func(systemConfig config.SystemConfig) error {
if err := expectDescriptorID(systemConfig, newTbKey, descID); err != nil {
return err
}
if err := expectDescriptor(systemConfig, descKey, descDesc); err != nil {
return err
}
return nil
})
return &emptyNode{}, nil
}