public void Pattern_Should_Handle_Yyymmdd_hhmm_minor_Version() { var parseResult = DbVersion.TryParse("20201208-1850.02", out var version); parseResult.Should().BeTrue("it's correct version"); version.Major.Should().Be(202012081850, "version contains major version"); version.Minor.Should().Be(2, "version contains minor version"); }
public void TryParse_Numeric_Major_Version() { var parseResult = DbVersion.TryParse("1", out var version); parseResult.Should().BeTrue("it's correct version"); version.Major.Should().Be(1, "version contains only major version"); version.Minor.Should().Be(0, "version contains only minor version"); }
public void Pattern_Should_Handle_Numeric_Major_Minor_2_Version() { var parseResult = DbVersion.TryParse("10001.020", out var version); parseResult.Should().BeTrue("it's correct version"); version.Major.Should().Be(10001, "version contains major version"); version.Minor.Should().Be(20, "version contains minor version"); }
/// <inheritdoc /> public async Task <IReadOnlyCollection <DbVersion> > GetAppliedMigrationVersionAsync(CancellationToken token = default) { // actual version is made by last migration because downgrade can decrease version var query = $"SELECT version FROM \"{_options.MigrationHistoryTableName}\""; var command = NpgsqlConnection.CreateCommand(); command.CommandText = query; try { _sqLogger?.LogInformation(query); var appliedMigrations = new List <DbVersion>(); using (var reader = await command.ExecuteReaderAsync(token)) { if (!reader.HasRows) { return(Array.Empty <DbVersion>()); } while (await reader.ReadAsync(token)) { var stringVersion = reader.GetString(0); if (!DbVersion.TryParse(stringVersion, out var version)) { throw new InvalidOperationException($"Incorrect migration version (source value = {stringVersion})."); } appliedMigrations.Add(version); } return(appliedMigrations.OrderBy(x => x).ToArray()); } } catch (PostgresException e) { // Migration table does not exist. if (e.SqlState == "42P01") { return(Array.Empty <DbVersion>()); } throw; } }