コード例 #1
0
        public void LessThanOrEqualToFalse()
        {
            var mv1 = new MigrationVersion(new DateTime(2002, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2001, 1, 1), "test");

            (mv1 <= mv2).Should().BeFalse();
        }
コード例 #2
0
        public void GreaterThanFalse()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2002, 1, 1), "test");

            (mv1 > mv2).Should().BeFalse();
        }
コード例 #3
0
        public void GreaterThanOrEqualToTrue()
        {
            var mv1 = new MigrationVersion(new DateTime(2002, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2001, 1, 1), "test");

            (mv1 >= mv2).Should().BeTrue();
        }
コード例 #4
0
        public void LessThanChecksTimestampInverted()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2000, 1, 1), "test");

            (mv1 < mv2).Should().BeFalse();
        }
コード例 #5
0
        public void LessThanChecksNameInverted()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "beta");
            var mv2 = new MigrationVersion(new DateTime(2001, 1, 1), "alpha");

            (mv1 < mv2).Should().BeFalse();
        }
コード例 #6
0
        public void NotEquals()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "alpha");
            var mv2 = new MigrationVersion(new DateTime(2001, 1, 1), "beta");

            (mv1 != mv2).Should().BeTrue();
        }
コード例 #7
0
        public void LessThanChecksTimestamp()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2002, 1, 1), "test");

            (mv1 < mv2).Should().BeTrue();
        }
コード例 #8
0
        public void EqualsChecksAll()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "alpha");
            var mv2 = new MigrationVersion(new DateTime(2001, 1, 1), "alpha");

            (mv1 == mv2).Should().BeTrue();
        }
コード例 #9
0
        public void EqualsChecksName()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "alpha");
            var mv2 = new MigrationVersion(new DateTime(2001, 1, 1), "beta");

            mv1.Equals(mv2).Should().BeFalse();
        }
コード例 #10
0
        public void EqualsChecksTimestamp()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2002, 1, 1), "test");

            mv1.Equals(mv2).Should().BeFalse();
        }
コード例 #11
0
        public void CompareToLess()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2002, 1, 1), "test");

            mv1.CompareTo(mv2).Should().Be(-1);
        }
コード例 #12
0
        public void EqualsOtherObjectFalse()
        {
            var mv = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            var o  = new object();

            mv.Equals(o).Should().BeFalse();
        }
コード例 #13
0
 protected Migration(
     MigrationVersion version,
     string description)
 {
     Version     = version;
     Description = description;
 }
コード例 #14
0
        public void ConstructGood()
        {
            var version = new MigrationVersion("M20010304050607_alpha");

            version.Timestamp.Should().Be(new DateTime(2001, 3, 4, 5, 6, 7));
            version.Name.Should().Be("alpha");
        }
コード例 #15
0
        public void EqualityTest()
        {
            var v1 = new MigrationVersion("2_1_2_4");
            var v2 = new MigrationVersion("2_1_2_4");

            Assert.True(v1.Equals(v2));
        }
コード例 #16
0
        public void NoEqualityTest()
        {
            var v1 = new MigrationVersion("2_1_2");
            var v2 = new MigrationVersion("2_1_2_1");

            Assert.False(v1.Equals(v2));
        }
コード例 #17
0
 public virtual void MarkUpToVersion(MigrationVersion version)
 {
     _Runner.MigrationLocator.GetAllMigrations()
         .Where(m => m.Version <= version)
         .ToList()
         .ForEach(m => MarkVersion(m.Version));
 }
コード例 #18
0
        public void ComparisonWithNullTest()
        {
            var v1 = new MigrationVersion("1");
            MigrationVersion v2 = null;

            Assert.Equal(1, v1.CompareTo(v2));
        }
コード例 #19
0
        public void EqualsNullObjectFalse()
        {
            var    mv = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            object o  = null;

            mv.Equals(o).Should().BeFalse();
        }
コード例 #20
0
 internal static IEnumerable <Migration> GetMigrationsToBeAppliedAscending(
     MigrationVersion lastVersionApplied,
     IEnumerable <Migration> allMigrationsToBeApplied)
 {
     return(allMigrationsToBeApplied
            .Where(migration => migration.Version > lastVersionApplied)
            .OrderBy(migration => migration.Version));
 }
コード例 #21
0
        public void ConstructExplicitComponents()
        {
            var dt = new DateTime(2012, 9, 24, 11, 46, 12);
            var mv = new MigrationVersion(dt, "test");

            mv.Timestamp.Should().Be(dt);
            mv.Name.Should().Be("test");
        }
コード例 #22
0
 public static AppliedMigration MarkerOnly(MigrationVersion version) {
     return new AppliedMigration {
         Version = version,
         Description = ManuallyMarked,
         StartedOn = DateTime.Now,
         CompletedOn = DateTime.Now
     };
 }
コード例 #23
0
        public void AddMigrationError(MigrationVersion version, DocumentMigrationError documentMigrationError) {
            var d = new Dictionary<string, object> {
                { "DocumentId", new BsonString(documentMigrationError.DocumentId) },
                { "Error", new BsonString(documentMigrationError.Error) }
            };

            GetMigrationsCollection().Update(Query.EQ("_id", new BsonString(version.ToString())), Update.Push("FailedMigrations", new BsonDocument(d)));
        }
コード例 #24
0
        public FileSystemMigrationProvider(string directory)
        {
            // List all migration files.
            var migrations = new SortedSet <MigrationInfo>();
            var path       = new DirectoryInfo(directory);

            foreach (var file in path.EnumerateFiles("*.cql"))
            {
                // Get file version.
                var name = file.Name;
                var sep  = name.IndexOf('.', StringComparison.Ordinal);
                var ext  = name.LastIndexOf('.');

                if (sep == ext || sep == 0)
                {
                    throw new ArgumentException($"File {name} has invalid name.", nameof(directory));
                }

                int major, minor;

                try
                {
                    major = short.Parse(name.Substring(0, sep), NumberStyles.None, CultureInfo.InvariantCulture);
                    minor = short.Parse(name.Substring(sep + 1, ext - sep - 1), NumberStyles.None, CultureInfo.InvariantCulture);
                }
                catch (Exception ex) when(ex is FormatException || ex is OverflowException)
                {
                    throw new ArgumentException($"File {name} has invalid name.", nameof(directory), ex);
                }

                // Store metadata.
                MigrationVersion version;

                try
                {
                    version = new MigrationVersion(major, minor);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    throw new ArgumentException($"File {name} has invalid name.", nameof(directory), ex);
                }

                if (!migrations.Add(new(version, file.FullName)))
                {
                    throw new ArgumentException($"File {name} has duplicated version with other file.", nameof(directory));
                }
            }

            // Create lookup table.
            var i = 0;

            this.migrations = new MigrationInfo[migrations.Count];

            foreach (var info in migrations)
            {
                this.migrations[i++] = info;
            }
        }
コード例 #25
0
        public virtual void UpdateTo(MigrationVersion updateToVersion) {
            var currentVersion = DatabaseStatus.GetLastAppliedMigration();
            Trace.TraceInformation("Updating migration \"{0}\" for version {1} to database \"{2}\".", currentVersion, updateToVersion, Database.Name);

            var migrations = MigrationLocator.GetMigrationsAfter(currentVersion)
                .Where(m => m.Version <= updateToVersion);

            ApplyMigrations(migrations);
        }
コード例 #26
0
        public async Task GetAsync_WithExistsMigration_ShouldReturnThatMigration()
        {
            var version = new MigrationVersion(1, 0);

            await using var result = await this.subject.GetAsync(version);

            Assert.NotNull(result);
            Assert.Equal(version, result !.Version);
        }
コード例 #27
0
        public virtual void UpdateTo(MigrationVersion updateToVersion)
        {
            var currentVersion = DatabaseStatus.GetLastAppliedMigration();
            Log.Info(new {Message = "Updating", currentVersion, updateToVersion, DatabaseName = Database.Name});

            var migrations = MigrationLocator.GetMigrationsAfter(currentVersion)
                .Where(m => m.Version <= updateToVersion);

            ApplyMigrations(migrations);
        }
コード例 #28
0
        public virtual void UpdateTo(MigrationVersion updateToVersion)
        {
            var currentVersion = DatabaseStatus.GetLastAppliedMigration();
            Console.WriteLine(new {Message = WhatWeAreUpdating(), currentVersion, updateToVersion, DatabaseName = Database.Name});

            var migrations = MigrationLocator.GetMigrationsAfter(currentVersion)
                                             .Where(m => m.Version <= updateToVersion);

            ApplyMigrations(migrations);
        }
コード例 #29
0
 /// <summary>
 /// Creates a manually marked migration
 /// </summary>
 /// <param name="version">The version.</param>
 /// <returns>Manually marked migration</returns>
 public static AppliedMigration MarkerOnly(MigrationVersion version)
 {
     return(new AppliedMigration
     {
         Version = version,
         Description = ManuallyMarked,
         StartedOn = DateTime.Now,
         CompletedOn = DateTime.Now
     });
 }
コード例 #30
0
            public TestContext SetupMigrationTarget()
            {
                _serverAddresses            = Guid.NewGuid().ToString();
                _databaseName               = Guid.NewGuid().ToString();
                _latestVersion              = GenerateRandomVersion();
                _migrationTargetDescription = Guid.NewGuid().ToString();
                _migrationTarget.Setup(x => x.ToString()).Returns(_migrationTargetDescription);
                _migrationTarget.SetupGet(x => x.ServerAddresses).Returns(_serverAddresses);
                _migrationTarget.SetupGet(x => x.DatabaseName).Returns(_databaseName);

                return(this);
            }
コード例 #31
0
        public void GetHashCodeReturnsSameCodesForSamePoints()
        {
            var mv1 = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            var mv2 = new MigrationVersion(new DateTime(2001, 1, 1), "test");
            int h1  = mv1.GetHashCode();

            h1.Should().NotBe(0);
            var h2 = mv2.GetHashCode();

            h2.Should().NotBe(0);
            h1.Should().Be(h2);
        }
コード例 #32
0
        /// <summary>
        /// Initialise the database schema, optionally running in preview mode.
        /// </summary>
        /// <param name="preview">The preview mode flag.</param>
        public void InitSchema(bool preview)
        {
            var source     = new AssemblyMigrationLoader(typeof(InitialSchema).Assembly);
            var provider   = GetProviderType(this.unitOfWork.Context.DataProvider);
            var connection = this.unitOfWork.Context.ConnectionString;
            var version    = MigrationVersion.FromString("20140806081722");

            var migrator = Migrator.CreateMigrator(source, provider, connection, version, preview);

            migrator.Execute();

            //Migrator.Migrate(source, provider, connection, null);
        }
コード例 #33
0
        /// <summary>
        /// Drop all UserAuth tables.
        /// </summary>
        private void DropTables()
        {
            var source     = new AssemblyMigrationLoader(typeof(InitialSchema).Assembly);
            var provider   = GetProviderType(this.unitOfWork.Context.DataProvider);
            var connection = this.unitOfWork.Context.ConnectionString;
            var version    = MigrationVersion.FromString("0");

            var migrator = Migrator.CreateMigrator(source, provider, connection, version, false);

            migrator.Execute();

            //Migrator.Migrate(source, provider, connection, null);
        }
コード例 #34
0
        public void UpFact()
        {
            // Arrange
            var migration = new Mock <IMigration>();

            migration.Setup(x => x.Up());
            var versionedMigration = new VersionedMigration(migration.Object, MigrationVersion.Max(null));

            // Act
            versionedMigration.Up();

            // Assert
            migration.VerifyAll();
        }
コード例 #35
0
        public void DownFact()
        {
            // Arrange
            var migration = new Mock <IMigration>();

            migration.Setup(x => x.Down());
            var version            = AutoFixture.Long();
            var versionedMigration = new VersionedMigration(migration.Object, MigrationVersion.Min(null));

            // Act
            versionedMigration.Down();

            // Assert
            migration.VerifyAll();
        }
コード例 #36
0
        public async Task <IEnumerable <MigrationHistory> > ListHistoryAsync(int majorVersion, CancellationToken cancellationToken = default)
        {
            var prepare = await this.session.PrepareAsync("SELECT major, minor, time FROM migrations WHERE major = ? ORDER BY minor ASC");

            var statement = prepare.Bind(Convert.ToInt16(majorVersion));
            var histories = new List <MigrationHistory>();

            foreach (var row in await this.session.ExecuteAsync(statement))
            {
                var version = new MigrationVersion(row.GetValue <short>("major"), row.GetValue <short>("minor"));
                var time    = row.GetValue <DateTimeOffset>("time");

                histories.Add(new MigrationHistory(version, time.UtcDateTime));
            }

            return(histories);
        }
コード例 #37
0
 public virtual void MarkVersion(MigrationVersion version) {
     var appliedMigration = AppliedMigration.MarkerOnly(version);
     GetMigrationsCollection().Insert(appliedMigration);
 }
コード例 #38
0
 public virtual void SetMigrationLastId(MigrationVersion version, string id) {
     GetMigrationsCollection().Update(Query.EQ("_id", new BsonString(version.ToString())), Update.Set("LastCompletedId", id));
 }
コード例 #39
0
 public virtual void MarkVersion(MigrationVersion version)
 {
     var appliedMigration = AppliedMigration.MarkerOnly(version);
     GetMigrationsApplied().ReplaceOne(x => x.Version == appliedMigration.Version, appliedMigration);
 }
コード例 #40
0
 protected Migration(MigrationVersion version)
 {
     Version = version;
 }
コード例 #41
0
 public CollectionMigration(MigrationVersion version, string collectionName)
     : base(version)
 {
     CollectionName = collectionName;
 }