Skip to content

Commit

Permalink
Use a proper composite index that relies on Gorm's naming strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
jgiannuzzi committed Nov 15, 2023
1 parent 37fd158 commit c478eb5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/api/mlflow/dao/models/experiment.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
// Experiment represents model to work with `experiments` table.
type Experiment struct {
ID *int32 `gorm:"column:experiment_id;not null;primaryKey"`
Name string `gorm:"type:varchar(256);not null;index:idx_namespace_name,unique"`
Name string `gorm:"type:varchar(256);not null;index:,unique,composite:name"`
ArtifactLocation string `gorm:"type:varchar(256)"`
LifecycleStage LifecycleStage `gorm:"type:varchar(32);check:lifecycle_stage IN ('active', 'deleted')"`
CreationTime sql.NullInt64 `gorm:"type:bigint"`
LastUpdateTime sql.NullInt64 `gorm:"type:bigint"`
NamespaceID uint `gorm:"index:idx_namespace_name,unique"`
NamespaceID uint `gorm:"index:,unique,composite:name"`
Namespace Namespace
Tags []ExperimentTag `gorm:"constraint:OnDelete:CASCADE"`
Runs []Run `gorm:"constraint:OnDelete:CASCADE"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/database/migrations/v_0006/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Migrate(db *gorm.DB) error {
if err := tx.Migrator().AlterColumn(&Experiment{}, "Name"); err != nil {
return err
}
if err := tx.Migrator().CreateIndex(&Experiment{}, "idx_namespace_name"); err != nil {
if err := tx.Migrator().CreateIndex(&Experiment{}, "Name"); err != nil {
return err
}
return tx.Model(&SchemaVersion{}).
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/migrations/v_0006/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ type Namespace struct {

type Experiment struct {
ID *int32 `gorm:"column:experiment_id;not null;primaryKey"`
Name string `gorm:"type:varchar(256);not null;index:idx_namespace_name,unique"`
Name string `gorm:"type:varchar(256);not null;index:,unique,composite:name"`
ArtifactLocation string `gorm:"type:varchar(256)"`
LifecycleStage LifecycleStage `gorm:"type:varchar(32);check:lifecycle_stage IN ('active', 'deleted')"`
CreationTime sql.NullInt64 `gorm:"type:bigint"`
LastUpdateTime sql.NullInt64 `gorm:"type:bigint"`
NamespaceID uint `gorm:"index:idx_namespace_name,unique"`
NamespaceID uint `gorm:"index:,unique,composite:name"`
Namespace Namespace
Tags []ExperimentTag `gorm:"constraint:OnDelete:CASCADE"`
Runs []Run `gorm:"constraint:OnDelete:CASCADE"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ type Namespace struct {

type Experiment struct {
ID *int32 `gorm:"column:experiment_id;not null;primaryKey"`
Name string `gorm:"type:varchar(256);not null;index:idx_namespace_name,unique"`
Name string `gorm:"type:varchar(256);not null;index:,unique,composite:name"`
ArtifactLocation string `gorm:"type:varchar(256)"`
LifecycleStage LifecycleStage `gorm:"type:varchar(32);check:lifecycle_stage IN ('active', 'deleted')"`
CreationTime sql.NullInt64 `gorm:"type:bigint"`
LastUpdateTime sql.NullInt64 `gorm:"type:bigint"`
NamespaceID uint `gorm:"index:idx_namespace_name,unique"`
NamespaceID uint `gorm:"index:,unique,composite:name"`
Namespace Namespace
Tags []ExperimentTag `gorm:"constraint:OnDelete:CASCADE"`
Runs []Run `gorm:"constraint:OnDelete:CASCADE"`
Expand Down

0 comments on commit c478eb5

Please sign in to comment.