Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions backend/python/plugins/azuredevops/azuredevops/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def add_build_id_as_job_primary_key(b: MigrationScriptBuilder):
@migration(20230606165630)
def rename_tx_rule_table_to_scope_config(b: MigrationScriptBuilder):
b.rename_table('_tool_azuredevops_azuredevopstransformationrules', GitRepositoryConfig.__tablename__)


@migration(20230607165630, name="add entities column to gitrepositoryconfig table")
def add_entities_column_to_scope_config(b: MigrationScriptBuilder):
b.add_column(GitRepositoryConfig.__tablename__, 'entities', 'json')


Expand Down
9 changes: 6 additions & 3 deletions backend/server/services/remote/models/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ type AddColumnOperation struct {

func (o AddColumnOperation) Execute(dal dal.Dal) errors.Error {
if dal.HasColumn(o.Table, o.Column) {
return dal.DropColumns(o.Table, o.Column)
err := dal.DropColumns(o.Table, o.Column)
if err != nil {
return err
}
}
return dal.AddColumn(o.Table, o.Column, o.ColumnType)
}
Expand Down Expand Up @@ -162,9 +165,9 @@ func (s *RemoteMigrationScript) UnmarshalJSON(data []byte) error {
}

func (s *RemoteMigrationScript) Up(basicRes context.BasicRes) errors.Error {
dal := basicRes.GetDal()
db := basicRes.GetDal()
for _, operation := range s.operations {
err := operation.Execute(dal)
err := operation.Execute(db)
if err != nil {
return err
}
Expand Down
17 changes: 12 additions & 5 deletions backend/server/services/remote/plugin/plugin_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,28 +231,35 @@ func (p *remotePluginImpl) ApiResources() map[string]map[string]plugin.ApiResour
}

func (p *remotePluginImpl) RunAutoMigrations() errors.Error {
db := basicRes.GetDal()
err := api.CallDB(db.AutoMigrate, p.connectionTabler.New())
err := p.createTable(p.connectionTabler.New())
if err != nil {
return err
}
err = api.CallDB(db.AutoMigrate, p.scopeTabler.New())
err = p.createTable(p.scopeTabler.New())
if err != nil {
return err
}
err = api.CallDB(db.AutoMigrate, p.scopeConfigTabler.New())
err = p.createTable(p.scopeConfigTabler.New())
if err != nil {
return err
}
for _, toolModelTabler := range p.toolModelTablers {
err = api.CallDB(db.AutoMigrate, toolModelTabler.New())
err = p.createTable(toolModelTabler.New())
if err != nil {
return err
}
}
return nil
}

func (p *remotePluginImpl) createTable(tbl coreModels.DynamicTabler) errors.Error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change disables all automigrations but table creation, and I thought we settled on adding a CreateTable op instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this ticket. I'll handle that in #5689. For now, we create tables like this, and every other migration is done manually

db := basicRes.GetDal()
if db.HasTable(tbl.TableName()) {
return nil
}
return api.CallDB(db.AutoMigrate, tbl)
}

func (p *remotePluginImpl) OpenApiSpec() string {
return p.openApiSpec
}
Expand Down