@@ -2,13 +2,11 @@ package schema
22
33import (
44 "fmt"
5- "slices"
6- "strings"
7-
85 "github.com/goravel/framework/contracts/database/orm"
96 contractsschema "github.com/goravel/framework/contracts/database/schema"
107 "github.com/goravel/framework/database/schema/grammars"
118 "github.com/goravel/framework/database/schema/processors"
9+ "slices"
1210)
1311
1412type PostgresSchema struct {
@@ -81,19 +79,21 @@ func (r *PostgresSchema) DropAllTypes() error {
8179 }
8280 }
8381
84- if len (dropTypes ) > 0 {
85- if _ , err := r .orm .Query ().Exec (r .grammar .CompileDropAllTypes (dropTypes )); err != nil {
86- return err
82+ return r .orm .Transaction (func (tx orm.Query ) error {
83+ if len (dropTypes ) > 0 {
84+ if _ , err := tx .Exec (r .grammar .CompileDropAllTypes (dropTypes )); err != nil {
85+ return err
86+ }
8787 }
88- }
8988
90- if len (dropDomains ) > 0 {
91- if _ , err := r .orm .Query ().Exec (r .grammar .CompileDropAllDomains (dropDomains )); err != nil {
92- return err
89+ if len (dropDomains ) > 0 {
90+ if _ , err := tx .Exec (r .grammar .CompileDropAllDomains (dropDomains )); err != nil {
91+ return err
92+ }
9393 }
94- }
9594
96- return nil
95+ return nil
96+ })
9797}
9898
9999func (r * PostgresSchema ) DropAllViews () error {
@@ -121,7 +121,11 @@ func (r *PostgresSchema) DropAllViews() error {
121121}
122122
123123func (r * PostgresSchema ) GetIndexes (table string ) ([]contractsschema.Index , error ) {
124- schema , table := r .parseSchemaAndTable (table )
124+ schema , table , err := parseSchemaAndTable (table , r .schema )
125+ if err != nil {
126+ return nil , err
127+ }
128+
125129 table = r .prefix + table
126130
127131 var dbIndexes []processors.DBIndex
@@ -140,16 +144,3 @@ func (r *PostgresSchema) GetTypes() ([]contractsschema.Type, error) {
140144
141145 return r .processor .ProcessTypes (types ), nil
142146}
143-
144- func (r * PostgresSchema ) parseSchemaAndTable (reference string ) (schema , table string ) {
145- parts := strings .Split (reference , "." )
146- schema = r .schema
147- if len (parts ) == 2 {
148- schema = parts [0 ]
149- parts = parts [1 :]
150- }
151-
152- table = parts [0 ]
153-
154- return
155- }
0 commit comments