Skip to content

Commit

Permalink
fix: add unique constraint to index
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiebens committed Dec 29, 2023
1 parent d9fafdc commit 038c0af
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions internal/database/migration/m202312290900_machine_indeces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package migration

import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)

func m202312290900_machine_indeces() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "202312290900",
Migrate: func(db *gorm.DB) error {
type Machine struct {
Name string `gorm:"index:idx_tailnet_id_name,unique,priority:2"`
NameIdx uint64 `gorm:"index:idx_tailnet_id_name,unique,sort:desc,priority:3"`
}

db.Migrator().DropIndex(&Machine{}, "idx_tailnet_id_name")

return db.AutoMigrate(
&Machine{},
)
},
Rollback: nil,
}
}
1 change: 1 addition & 0 deletions internal/database/migration/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func Migrations() []*gormigrate.Migration {
m202212201300_add_user_id_column(),
m202212270800_machine_indeces(),
m202312271200_account_last_authenticated(),
m202312290900_machine_indeces(),
}
return migrations
}

0 comments on commit 038c0af

Please sign in to comment.