getAppliedMigrations returns a map of already applied migration versions
(ctx context.Context)
| 49 | |
| 50 | // getAppliedMigrations returns a map of already applied migration versions |
| 51 | func (m *Migrator) getAppliedMigrations(ctx context.Context) (map[int]bool, error) { |
| 52 | query := "SELECT version FROM schema_migrations ORDER BY version" |
| 53 | rows, err := m.conn.Query(ctx, query) |
| 54 | if err != nil { |
| 55 | return nil, fmt.Errorf("failed to query applied migrations: %w", err) |
| 56 | } |
| 57 | defer rows.Close() |
| 58 | |
| 59 | applied := make(map[int]bool) |
| 60 | for rows.Next() { |
| 61 | var version int |
| 62 | if err := rows.Scan(&version); err != nil { |
| 63 | return nil, fmt.Errorf("failed to scan migration version: %w", err) |
| 64 | } |
| 65 | applied[version] = true |
| 66 | } |
| 67 | |
| 68 | return applied, rows.Err() |
| 69 | } |
| 70 | |
| 71 | // loadMigrations loads all migration files from the embedded filesystem |
| 72 | func (m *Migrator) loadMigrations() ([]Migration, error) { |