Check if all migrations al
(migrations []*migrate.Migration)
| 101 | |
| 102 | // Check if all migrations al |
| 103 | func (s *SQL) checkAlreadyApplied(migrations []*migrate.Migration) bool { |
| 104 | // make map (set) of ids for fast search |
| 105 | migrationsIDs := make(map[string]struct{}) |
| 106 | for _, migration := range migrations { |
| 107 | migrationsIDs[migration.Id] = struct{}{} |
| 108 | } |
| 109 | |
| 110 | // get list of applied migrations |
| 111 | migrate.SetDisableCreateTable(true) |
| 112 | records, err := migrate.GetMigrationRecords(s.db.DB, postgreSQLDialect) |
| 113 | migrate.SetDisableCreateTable(false) |
| 114 | if err != nil { |
| 115 | s.Logger().Debug("failed to get migration records", slog.Any("error", err)) |
| 116 | return false |
| 117 | } |
| 118 | |
| 119 | for _, record := range records { |
| 120 | if _, ok := migrationsIDs[record.Id]; ok { |
| 121 | s.Logger().Debug("found previous migration", "id", record.Id, "appliedAt", record.AppliedAt) |
| 122 | delete(migrationsIDs, record.Id) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | // check if all migrations applied |
| 127 | if len(migrationsIDs) != 0 { |
| 128 | for id := range migrationsIDs { |
| 129 | s.Logger().Debug("find unapplied migration", "id", id) |
| 130 | } |
| 131 | return false |
| 132 | } |
| 133 | return true |
| 134 | } |
| 135 | |
| 136 | func (s *SQL) ensureDBSetup() error { |
| 137 |