MCPcopy Create free account
hub / github.com/dolthub/doltgresql / beforeTableDeletionCheckTableColumns

Function beforeTableDeletionCheckTableColumns

server/hook/delete_table.go:66–115  ·  view source on GitHub ↗

beforeTableDeletionCheckTableColumns is called from BeforeTableDeletion and handles checking for columns that use a table's type.

(ctx *sql.Context, doltTable *sqle.DoltTable, allDeletedTables []doltdb.TableName)

Source from the content-addressed store, hash-verified

64// beforeTableDeletionCheckTableColumns is called from BeforeTableDeletion and handles checking for columns that use a
65// table's type.
66func beforeTableDeletionCheckTableColumns(ctx *sql.Context, doltTable *sqle.DoltTable, allDeletedTables []doltdb.TableName) error {
67 tableName := doltTable.TableName()
68 _, root, err := core.GetRootFromContext(ctx)
69 if err != nil {
70 return err
71 }
72 tableAsType := id.NewType(tableName.Schema, tableName.Name)
73 allTableNames, err := root.GetAllTableNames(ctx, false)
74 if err != nil {
75 return err
76 }
77OuterLoop:
78 for _, otherTableName := range allTableNames {
79 if doltdb.IsSystemTable(otherTableName) {
80 // System tables don't use any table types
81 continue OuterLoop
82 }
83 for _, deletedTable := range allDeletedTables {
84 if deletedTable.EqualFold(otherTableName) {
85 // If we're also deleting this table, then it doesn't matter what the columns have
86 continue OuterLoop
87 }
88 }
89 otherTable, ok, err := root.GetTable(ctx, otherTableName)
90 if err != nil {
91 return err
92 }
93 if !ok {
94 return errors.Newf("root returned table name `%s` but it could not be found?", otherTableName.String())
95 }
96 otherTableSch, err := otherTable.GetSchema(ctx)
97 if err != nil {
98 return err
99 }
100 for _, col := range otherTableSch.GetAllCols().GetColumns() {
101 colType := col.TypeInfo.ToSqlType()
102 dgtype, ok := colType.(*pgtypes.DoltgresType)
103 if !ok {
104 // If this isn't a Doltgres type, then it can't be a table type so we can ignore it
105 continue
106 }
107 if dgtype.ID == tableAsType {
108 // TODO: portion after newline should be in DETAILS but we don't yet support that in our error messages
109 return errors.Newf("cannot drop table %s because other objects depend on it\ncolumn %s of table %s depends on type %s",
110 tableName.Name, col.Name, otherTableName.Name, tableName.Name)
111 }
112 }
113 }
114 return nil
115}
116
117// beforeTableDeletionCheckFuncsProcs is called from BeforeTableDeletion and handles checking for function and procedure
118// parameters that use a table's type.

Callers 1

BeforeTableDeletionFunction · 0.85

Calls 8

GetRootFromContextFunction · 0.92
NewTypeFunction · 0.92
GetAllTableNamesMethod · 0.80
GetTableMethod · 0.80
ToSqlTypeMethod · 0.80
StringMethod · 0.65
TableNameMethod · 0.45
GetSchemaMethod · 0.45

Tested by

no test coverage detected