3
0

Add indexes to automation_sessions table

This will prevent mysql sorting memory issue
This commit is contained in:
Denis Arh 2021-05-23 15:00:09 +02:00
parent 0149bbcdd7
commit c9009df73b
2 changed files with 33 additions and 0 deletions

View File

@ -21,6 +21,7 @@ type (
DropColumn(context.Context, string, string) (bool, error)
RenameColumn(context.Context, string, string, string) (bool, error)
AddPrimaryKey(context.Context, string, *ddl.Index) (bool, error)
CreateIndex(context.Context, *ddl.Index) (bool, error)
Exec(context.Context, string, ...interface{}) error
}
)
@ -77,6 +78,10 @@ func (g genericUpgrades) Upgrade(ctx context.Context, t *ddl.Table) error {
return g.all(ctx,
g.AlterComposeModuleFieldAddExpresions,
)
case "automation_sessions":
return g.all(ctx,
g.CreateAutomationSessionIndexes,
)
//case "compose_attachment_binds":
// return g.all(ctx,
// g.MigrateComposeAttachmentsToBindsTable,
@ -377,3 +382,25 @@ func (g genericUpgrades) AlterComposeModuleFieldAddExpresions(ctx context.Contex
_, err = g.u.AddColumn(ctx, "compose_module_field", col)
return
}
func (g genericUpgrades) CreateAutomationSessionIndexes(ctx context.Context) (err error) {
var (
ii = []*ddl.Index{
{Name: "event_type", Fields: []*ddl.IField{{Field: "event_type", Length: handleLength}}},
{Name: "resource_type", Fields: []*ddl.IField{{Field: "resource_type", Length: handleLength}}},
{Name: "status", Fields: []*ddl.IField{{Field: "status"}}},
{Name: "created_at", Fields: []*ddl.IField{{Field: "created_at"}}},
{Name: "completed_at", Fields: []*ddl.IField{{Field: "completed_at"}}},
{Name: "suspended_at", Fields: []*ddl.IField{{Field: "suspended_at"}}},
}
)
for _, i := range ii {
i.Table = "automation_sessions"
if _, err = g.u.CreateIndex(ctx, i); err != nil {
return
}
}
return
}

View File

@ -614,6 +614,12 @@ func (Schema) AutomationSessions() *Table {
ColumnDef("error", ColumnTypeText),
AddIndex("workflow", IColumn("rel_workflow")),
AddIndex("event_type", IFieldFull(&IField{Field: "event_type", Length: handleLength})),
AddIndex("resource_type", IFieldFull(&IField{Field: "resource_type", Length: handleLength})),
AddIndex("status", IColumn("status")),
AddIndex("created_at", IColumn("created_at")),
AddIndex("completed_at", IColumn("completed_at")),
AddIndex("suspended_at", IColumn("suspended_at")),
)
}