@@ -2185,6 +2185,14 @@ func (db Database) CreateTemporaryTable(ctx *sql.Context, tableName string, pkSc
21852185 return nil
21862186}
21872187
2188+ // SupportsDatabaseSchemas implements sql.SchemaDatabase
2189+ // TODO: this interface is only necessary because we don't have a separate sql.Database implementation for doltgres,
2190+ // which has additional capabilities (like schema creation). Dolt technically can create schemas (multiple DBs in
2191+ // the same commit graph), but there's no way for users to access this functionality currently.
2192+ func (db Database ) SupportsDatabaseSchemas () bool {
2193+ return resolve .UseSearchPath
2194+ }
2195+
21882196// CreateSchema implements sql.SchemaDatabase
21892197func (db Database ) CreateSchema (ctx * sql.Context , schemaName string ) error {
21902198 if err := dsess .CheckAccessForDb (ctx , db , branch_control .Permissions_Write ); err != nil {
@@ -2215,6 +2223,36 @@ func (db Database) CreateSchema(ctx *sql.Context, schemaName string) error {
22152223 return db .SetRoot (ctx , root )
22162224}
22172225
2226+ // DropSchema implements sql.SchemaDatabase
2227+ func (db Database ) DropSchema (ctx * sql.Context , schemaName string ) error {
2228+ if err := dsess .CheckAccessForDb (ctx , db , branch_control .Permissions_Write ); err != nil {
2229+ return err
2230+ }
2231+
2232+ root , err := db .GetRoot (ctx )
2233+ if err != nil {
2234+ return err
2235+ }
2236+
2237+ _ , exists , err := doltdb .ResolveDatabaseSchema (ctx , root , schemaName )
2238+ if err != nil {
2239+ return err
2240+ }
2241+
2242+ if ! exists {
2243+ return sql .ErrDatabaseSchemaNotFound .New (schemaName )
2244+ }
2245+
2246+ root , err = root .DropDatabaseSchema (ctx , schema.DatabaseSchema {
2247+ Name : schemaName ,
2248+ })
2249+ if err != nil {
2250+ return err
2251+ }
2252+
2253+ return db .SetRoot (ctx , root )
2254+ }
2255+
22182256// GetSchema implements sql.SchemaDatabase
22192257func (db Database ) GetSchema (ctx * sql.Context , schemaName string ) (sql.DatabaseSchema , bool , error ) {
22202258 // For doltgres, the information_schema database should be a schema.
@@ -2570,13 +2608,13 @@ func (db Database) CreateTrigger(ctx *sql.Context, definition sql.TriggerDefinit
25702608 definition .Name ,
25712609 definition .CreateStatement ,
25722610 definition .CreatedAt ,
2573- fmt .Errorf ("triggers `%s` already exists" , definition .Name ), //TODO: add a sql error and return that instead
2611+ fmt .Errorf ("triggers `%s` already exists" , definition .Name ), // TODO: add a sql error and return that instead
25742612 )
25752613}
25762614
25772615// DropTrigger implements sql.TriggerDatabase.
25782616func (db Database ) DropTrigger (ctx * sql.Context , name string ) error {
2579- //TODO: add a sql error and use that as the param error instead
2617+ // TODO: add a sql error and use that as the param error instead
25802618 return db .dropFragFromSchemasTable (ctx , "trigger" , name , sql .ErrTriggerDoesNotExist .New (name ))
25812619}
25822620
0 commit comments