Fixed tests, made rename illegal for dolt_schemas

This commit is contained in:
Zach Musgrave
2023-02-15 17:39:36 -08:00
parent b75f9a9129
commit b228edc046
3 changed files with 9 additions and 13 deletions
+3 -2
View File
@@ -66,8 +66,9 @@ func IsReadOnlySystemTable(name string) bool {
return HasDoltPrefix(name) && !set.NewStrSet(writeableSystemTables).Contains(name)
}
// IsNonDroppableSystemTable returns whether the table name given is a system table that cannot be dropped.
func IsNonDroppableSystemTable(name string) bool {
// IsNonAlterableSystemTable returns whether the table name given is a system table that cannot be dropped or altered
// by the user.
func IsNonAlterableSystemTable(name string) bool {
return IsReadOnlySystemTable(name) || strings.ToLower(name) == SchemasTableName
}
+2 -2
View File
@@ -733,7 +733,7 @@ func (db Database) DropTable(ctx *sql.Context, tableName string) error {
if err := branch_control.CheckAccess(ctx, branch_control.Permissions_Write); err != nil {
return err
}
if doltdb.IsNonDroppableSystemTable(tableName) {
if doltdb.IsNonAlterableSystemTable(tableName) {
return ErrSystemTableAlter.New(tableName)
}
@@ -1031,7 +1031,7 @@ func (db Database) RenameTable(ctx *sql.Context, oldName, newName string) error
return err
}
if doltdb.IsReadOnlySystemTable(oldName) {
if doltdb.IsNonAlterableSystemTable(oldName) {
return ErrSystemTableAlter.New(oldName)
}
+4 -9
View File
@@ -795,8 +795,8 @@ func TestRenameTableStatements(t *testing.T) {
}
func TestAlterSystemTables(t *testing.T) {
systemTableNames := []string{"dolt_log", "dolt_history_people", "dolt_diff_people", "dolt_commit_diff_people"} // "dolt_docs",
reservedTableNames := []string{"dolt_schemas", "dolt_query_catalog"}
systemTableNames := []string{"dolt_log", "dolt_history_people", "dolt_diff_people", "dolt_commit_diff_people", "dolt_schemas"} // "dolt_docs",
reservedTableNames := []string{"dolt_query_catalog"}
var dEnv *env.DoltEnv
var err error
@@ -825,15 +825,10 @@ func TestAlterSystemTables(t *testing.T) {
}
})
// The _history and _diff tables give not found errors right now because of https://github.com/dolthub/dolt/issues/373.
// We can remove the divergent failure logic when the issue is fixed.
t.Run("Drop", func(t *testing.T) {
setup()
for _, tableName := range systemTableNames {
expectedErr := "system table"
if strings.HasPrefix(tableName, "dolt_diff") || strings.HasPrefix(tableName, "dolt_history") {
expectedErr = "system tables cannot be dropped or altered"
}
for _, tableName := range append(systemTableNames, "dolt_schemas") {
expectedErr := "system tables cannot be dropped or altered"
assertFails(t, dEnv, fmt.Sprintf("drop table %s", tableName), expectedErr)
}
for _, tableName := range reservedTableNames {