github.com/kyleu/dbaudit@v0.0.2-0.20240321155047-ff2f2c940496/app/lib/database/migrate/migration.go (about) 1 // Package migrate - Content managed by Project Forge, see [projectforge.md] for details. 2 package migrate 3 4 import ( 5 "time" 6 7 "github.com/samber/lo" 8 ) 9 10 type Migration struct { 11 Idx int `json:"idx"` 12 Title string `json:"title"` 13 Src string `json:"src"` 14 Created time.Time `json:"created"` 15 } 16 17 type migrationRow struct { 18 Idx int `db:"idx"` 19 Title string `db:"title"` 20 Src string `db:"src"` 21 Created time.Time `db:"created"` 22 } 23 24 func (r *migrationRow) toMigration() *Migration { 25 return &Migration{ 26 Idx: r.Idx, 27 Title: r.Title, 28 Src: r.Src, 29 Created: r.Created, 30 } 31 } 32 33 func toMigrations(rs []*migrationRow) Migrations { 34 return lo.Map(rs, func(r *migrationRow, _ int) *Migration { 35 return r.toMigration() 36 }) 37 } 38 39 type Migrations []*Migration 40 41 func (m Migrations) GetByIndex(idx int) *Migration { 42 return lo.FindOrElse(m, nil, func(x *Migration) bool { 43 return x.Idx == idx 44 }) 45 }