Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latest MigrationInfo is incorrect if all previous migrations have the same AppliedAt time stamp #10

Open
andreas-koenig opened this issue Oct 18, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@andreas-koenig
Copy link

Description

PR #8 solved #7 by correctly querying the most recently applied MigrationInfo in descending order:

var migrationInfos = await DataConnection.GetTable<TMigrationInfo>()
                                         .OrderByDescending(migrationInfo => migrationInfo.AppliedAt)
                                         .Take(Take)
                                         .ToListAsync(cancellationToken);
return migrationInfos.GetLatestMigrationInfo();

Unfortunately an incorrect migration is still returned in the following scenario:

  1. There are more than Take migrations (defaults to 100)
  2. All migrations are applied onto an empty database in a single run of MigrationEnginge.MigrateAsync(). All of the corresponding MigrationInfos are assigned the same time stamp
  3. During the next run of the MigrationEngine it is up to the database engine to determine the order as the AppliedAt values of all MigrationInfos are equal. In the case of MSSQL Server the first Take migrations are returned, not the last. Consequently, migration #Take is incorrectly identified as the last one and the engine tries to reapply the remaining migrations starting from Take + 1.

Possible Workarounds

  1. Use different timestamps for every pending migration. This does not solve the problem for existing databases, though.
  2. Order by the AppliedAt AND the Id column. This workaround depends on the ID generation for the MigrationInfos table.
@andreas-koenig andreas-koenig added the bug Something isn't working label Oct 18, 2022
@feO2x
Copy link
Contributor

feO2x commented Oct 19, 2022

Yep, we should order by AppliedAt and Id - this is the best solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants