@@ -17,6 +17,7 @@ package core
1717import (
1818 "bytes"
1919 "context"
20+ "fmt"
2021 "slices"
2122 "sort"
2223 "strconv"
@@ -87,6 +88,35 @@ func (root *RootValue) CreateDatabaseSchema(ctx context.Context, dbSchema schema
8788 return root .withStorage (r ), nil
8889}
8990
91+ // DropDatabaseSchema implements the interface doltdb.RootValue.
92+ func (root * RootValue ) DropDatabaseSchema (ctx context.Context , dbSchema schema.DatabaseSchema ) (doltdb.RootValue , error ) {
93+ schemas , err := root .st .GetSchemas (ctx )
94+ if err != nil {
95+ return nil , err
96+ }
97+
98+ found := false
99+ for i , s := range schemas {
100+ if strings .EqualFold (s .Name , dbSchema .Name ) {
101+ found = true
102+ // remove this element in the slice
103+ schemas = append (schemas [:i ], schemas [i + 1 :]... )
104+ break
105+ }
106+ }
107+
108+ if ! found {
109+ return nil , fmt .Errorf ("No schema with the name %s exists" , dbSchema .Name )
110+ }
111+
112+ r , err := root .st .SetSchemas (ctx , schemas )
113+ if err != nil {
114+ return nil , err
115+ }
116+
117+ return root .withStorage (r ), nil
118+ }
119+
90120// validateSchemaForCreate returns an error if a schema with the name given cannot be created
91121func validateSchemaForCreate (existingSchemas []schema.DatabaseSchema , dbSchema schema.DatabaseSchema ) error {
92122 if dbSchema .Name == "" {
@@ -579,10 +609,10 @@ func (root *RootValue) PutTable(ctx context.Context, tName doltdb.TableName, tab
579609
580610// RemoveTables implements the interface doltdb.RootValue.
581611func (root * RootValue ) RemoveTables (
582- ctx context.Context ,
583- skipFKHandling bool ,
584- allowDroppingFKReferenced bool ,
585- originalTables ... doltdb.TableName ,
612+ ctx context.Context ,
613+ skipFKHandling bool ,
614+ allowDroppingFKReferenced bool ,
615+ originalTables ... doltdb.TableName ,
586616) (doltdb.RootValue , error ) {
587617 if len (originalTables ) == 0 {
588618 return root , nil
0 commit comments