github.com/goravel/framework@v1.13.9/database/console/table_guesser.go (about) 1 package console 2 3 import ( 4 "regexp" 5 ) 6 7 var CreatePatterns = []string{ 8 `^create_(\w+)_table$`, 9 `^create_(\w+)$`, 10 } 11 12 var ChangePatterns = []string{ 13 `_(to|from|in)_(\w+)_table$`, 14 `_(to|from|in)_(\w+)$`, 15 } 16 17 type TableGuesser struct { 18 } 19 20 // Guess Attempt to guess the table name and "creation" status of the given migration, return table, create. 21 func (receiver TableGuesser) Guess(migration string) (string, bool) { 22 for _, createPattern := range CreatePatterns { 23 reg := regexp.MustCompile(createPattern) 24 matches := reg.FindStringSubmatch(migration) 25 26 if len(matches) > 0 { 27 return matches[1], true 28 } 29 } 30 31 for _, changePattern := range ChangePatterns { 32 reg := regexp.MustCompile(changePattern) 33 matches := reg.FindStringSubmatch(migration) 34 35 if len(matches) > 0 { 36 return matches[2], false 37 } 38 } 39 40 return "", false 41 }