Skip to content

Commit 2d95435

Browse files
committed
chore: use migrationName instead of migrationID
1 parent 125717b commit 2d95435

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

internal/dbtest/migrate_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,8 @@ func testRunMigration(t *testing.T, db *bun.DB) {
226226
require.NoError(t, err)
227227
require.Len(t, migrationsWithStatus, 2)
228228

229-
targetID := migrationsWithStatus[0].ID
230-
require.NotZero(t, targetID)
231-
232229
history = nil
233-
err = m.RunMigration(ctx, targetID)
230+
err = m.RunMigration(ctx, "20060102150405")
234231
require.NoError(t, err)
235232
require.Equal(t, []string{"up1"}, history)
236233

migrate/migrator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,15 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra
210210
// RunMigration runs the up migration with the given ID without marking it as applied.
211211
// It runs the migration even if it is already marked as applied.
212212
func (m *Migrator) RunMigration(
213-
ctx context.Context, migrationID int64, opts ...MigrationOption,
213+
ctx context.Context, migrationName string, opts ...MigrationOption,
214214
) error {
215215
cfg := newMigrationConfig(opts)
216216

217217
if err := m.validate(); err != nil {
218218
return err
219219
}
220-
if migrationID == 0 {
221-
return errors.New("migrate: migration id must be greater than zero")
220+
if migrationName == "" {
221+
return errors.New("migrate: migration name cannot be empty")
222222
}
223223

224224
migrations, _, err := m.migrationsWithStatus(ctx)
@@ -228,13 +228,13 @@ func (m *Migrator) RunMigration(
228228

229229
var migration *Migration
230230
for i := range migrations {
231-
if migrations[i].ID == migrationID {
231+
if migrations[i].Name == migrationName {
232232
migration = &migrations[i]
233233
break
234234
}
235235
}
236236
if migration == nil {
237-
return fmt.Errorf("migrate: migration with id %d not found", migrationID)
237+
return fmt.Errorf("migrate: migration with name %q not found", migrationName)
238238
}
239239
if migration.Up == nil {
240240
return fmt.Errorf("migrate: migration %s does not have up migration", migration.Name)

0 commit comments

Comments
 (0)