github.com/sharovik/devbot@v1.0.1-0.20240308094637-4a0387c40516/scripts/update/migrations/6-add-column-questions.go (about) 1 package migrations 2 3 import ( 4 "fmt" 5 6 "github.com/pkg/errors" 7 "github.com/sharovik/devbot/internal/container" 8 "github.com/sharovik/devbot/internal/dto/databasedto" 9 "github.com/sharovik/orm/clients" 10 "github.com/sharovik/orm/dto" 11 ) 12 13 type AddColumnQuestions struct { 14 Client clients.BaseClientInterface 15 } 16 17 func (m AddColumnQuestions) SetClient(client clients.BaseClientInterface) { 18 m.Client = client 19 } 20 21 func (m AddColumnQuestions) GetName() string { 22 return "6-add-column-questions" 23 } 24 25 func (m AddColumnQuestions) Execute() error { 26 client := container.C.Dictionary.GetDBClient() 27 28 q := new(clients.Query).Drop(databasedto.EventTriggerHistoryModel) 29 if _, err := client.Execute(q); err != nil { 30 return errors.Wrap(err, fmt.Sprintf("Failed to drop %s table", databasedto.EventTriggerHistoryModel.GetTableName())) 31 } 32 33 //Create events table 34 q = new(clients.Query). 35 Alter(databasedto.QuestionsModel). 36 AddColumn(dto.ModelField{ 37 Name: "is_variable", 38 Type: dto.BooleanColumnType, 39 Value: nil, 40 Default: false, 41 }). 42 AddIndex(dto.Index{ 43 Name: "is_variable_index", 44 Target: databasedto.QuestionsModel.GetTableName(), 45 Key: "is_variable", 46 Unique: false, 47 }) 48 if _, err := client.Execute(q); err != nil { 49 return errors.Wrap(err, fmt.Sprintf("Failed to create %s table", databasedto.EventTriggerHistoryModel.GetTableName())) 50 } 51 52 return nil 53 }