ExecutedMigrations returns a map with already executed migrations in addition to creating the migrations table, if it doesn't exist.
(ctx context.Context)
| 120 | // ExecutedMigrations returns a map with already executed migrations in addition to creating the |
| 121 | // migrations table, if it doesn't exist. |
| 122 | func (m *Migrator) ExecutedMigrations(ctx context.Context) (map[string]struct{}, error) { |
| 123 | result := make(map[string]struct{}) |
| 124 | _, err := m.db.ExecContext(ctx, createDBMigrationsSQL) |
| 125 | if err != nil { |
| 126 | return nil, fmt.Errorf("unable to create db_migrations: %w", err) |
| 127 | } |
| 128 | rows, err := m.db.QueryContext(ctx, selectDBMigrationsSQL) |
| 129 | if err != nil { |
| 130 | return nil, fmt.Errorf("unable to query db_migrations: %w", err) |
| 131 | } |
| 132 | defer internal.CloseAndLogIfError(ctx, rows, "ExecutedMigrations: rows.close() failed") |
| 133 | var version string |
| 134 | for rows.Next() { |
| 135 | if err = rows.Scan(&version); err != nil { |
| 136 | return nil, fmt.Errorf("unable to scan version: %w", err) |
| 137 | } |
| 138 | result[version] = struct{}{} |
| 139 | } |
| 140 | |
| 141 | return result, rows.Err() |
| 142 | } |