MCPcopy Create free account
hub / github.com/daodst/chat / ExecutedMigrations

Method ExecutedMigrations

internal/sqlutil/migrate.go:122–142  ·  view source on GitHub ↗

ExecutedMigrations returns a map with already executed migrations in addition to creating the migrations table, if it doesn't exist.

(ctx context.Context)

Source from the content-addressed store, hash-verified

120// ExecutedMigrations returns a map with already executed migrations in addition to creating the
121// migrations table, if it doesn't exist.
122func (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}

Callers 2

Test_migrations_UpFunction · 0.95
UpMethod · 0.95

Calls 2

QueryContextMethod · 0.80
ErrMethod · 0.80

Tested by 1

Test_migrations_UpFunction · 0.76