public virtual void MarkUpToVersion(MigrationVersion version)
 {
     _Runner.MigrationLocator.GetAllMigrations()
     .Where(m => m.Version <= version)
     .ToList()
     .ForEach(m => MarkVersion(m.Version));
 }
        /// <inheritdoc />
        public virtual void MarkVersion(MigrationVersion version)
        {
            var appliedMigration = AppliedMigration.MarkerOnly(version);

            GetAppliedMigrationsCollection()
            .InsertOne(appliedMigration);
        }
        public virtual Task MarkVersionAsync(MigrationVersion version,
                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            var appliedMigration = AppliedMigration.MarkerOnly(version);

            return(GetMigrationsApplied().InsertOneAsync(appliedMigration,
                                                         null, cancellationToken));
        }
        public virtual MigrationVersion GetVersion()
        {
            var lastAppliedMigration = GetLastAppliedMigration();

            return(lastAppliedMigration == null
                                ? MigrationVersion.Default()
                                : lastAppliedMigration.Version);
        }
Exemplo n.º 5
0
        public virtual MigrationVersion LatestVersion()
        {
            if (!GetAllMigrations().Any())
            {
                return(MigrationVersion.Default());
            }

            return(GetAllMigrations().Max(m => m.Version));
        }
        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)));
        }
Exemplo n.º 7
0
 public static AppliedMigration MarkerOnly(MigrationVersion version)
 {
     return(new AppliedMigration {
         Version = version,
         Description = ManuallyMarked,
         StartedOn = DateTime.Now,
         CompletedOn = DateTime.Now
     });
 }
        /// <summary>
        /// Updates to a specific version.
        /// </summary>
        /// <param name="updateToVersion">The update to version.</param>
        public virtual void UpdateTo(MigrationVersion updateToVersion)
        {
            var currentVersion = _databaseStatus.GetLastAppliedMigration();

            _logger.LogInformation($"Updating server(s) \"{_migrationTarget.ServerAddresses}\" for database \"{_migrationTarget.DatabaseName}\", from version {currentVersion} to version {updateToVersion}");

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

            ApplyMigrations(migrations);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public virtual void UpdateTo(MigrationVersion updateToVersion)
        {
            var currentVersion = DatabaseStatus.GetLastAppliedMigration();

            Console.WriteLine(new { Message = WhatWeAreUpdating(), currentVersion, updateToVersion, Database.DatabaseNamespace.DatabaseName });

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

            ApplyMigrations(migrations);
        }
        public virtual async Task MarkUpToVersionAsync(MigrationVersion version,
                                                       CancellationToken cancellationToken = default(CancellationToken))
        {
            var migrations = _Runner.MigrationLocator
                             .GetAllMigrations()
                             .Where(m => m.Version <= version);

            foreach (var migration in migrations)
            {
                await MarkVersionAsync(migration.Version, cancellationToken);
            }
        }
Exemplo n.º 12
0
        public virtual MigrationVersion LatestVersion()
        {
            var allMigrations = this.GetAllMigrations().ToList();

            if (!allMigrations.Any())
            {
                return(MigrationVersion.Default());
            }

            return(allMigrations
                   .Max(m => m.Version));
        }
Exemplo n.º 13
0
        public virtual async Task UpdateToAsync(MigrationVersion updateToVersion,
                                                CancellationToken cancellationToken = default(CancellationToken))
        {
            var unapplied = await DatabaseStatus.GetUnappliedMigrationsAsync(
                cancellationToken);

            var first = unapplied.FirstOrDefault();

            if (first == null)
            {
                return;
            }

            _logger.LogInformation(new
            {
                Message        = WhatWeAreUpdating(),
                firstUnapplied = first,
                updateToVersion,
                DatabaseName
            }.ToString());;

            await ApplyMigrationsAsync(unapplied, cancellationToken);
        }
Exemplo n.º 14
0
        public virtual void UpdateTo(MigrationVersion updateToVersion)
        {
            var currentVersion = DatabaseStatus.GetLastAppliedMigration();
            var migrations     = MigrationLocator.GetMigrationsAfter(currentVersion).Where(m => m.Version <= updateToVersion).ToList();

            if (migrations.Count == 0)
            {
                return;
            }

            // if the migration collection didn't exist, assume it's a new db that is already up to date.
            if (currentVersion == null)
            {
                foreach (var migration in migrations)
                {
                    DatabaseStatus.MarkVersion(migration.Version);
                }

                return;
            }

            Trace.TraceInformation("Updating migration \"{0}\" for version {1} to database \"{2}\".", currentVersion, updateToVersion, Database.Name);
            ApplyMigrations(migrations);
        }
        public virtual void MarkVersion(MigrationVersion version)
        {
            var appliedMigration = AppliedMigration.MarkerOnly(version);

            Task.WaitAll(GetMigrationsApplied().InsertOneAsync(appliedMigration));
        }
 public CollectionMigration(MigrationVersion version, string collectionName) : base(version)
 {
     CollectionName = collectionName;
 }
Exemplo n.º 17
0
 protected Migration(MigrationVersion version)
 {
     this.Version = version;
 }
 public virtual void SetMigrationLastId(MigrationVersion version, string id)
 {
     GetMigrationsCollection().Update(Query.EQ("_id", new BsonString(version.ToString())), Update.Set("LastCompletedId", id).Inc("CompletedCount", 1));
 }
Exemplo n.º 19
0
        public virtual void MarkVersion(MigrationVersion version)
        {
            var appliedMigration = AppliedMigration.MarkerOnly(version);

            GetMigrationsApplied().Insert(appliedMigration);
        }
 protected Migration(string description = null)
 {
     Description = description;
     Version     = new MigrationVersion(GetType().Name);
 }
Exemplo n.º 21
0
 protected Migration(MigrationVersion version)
 {
     Version = version;
 }
Exemplo n.º 22
0
 public CollectionMigration(MigrationVersion version, string collectionName, FilterDefinition <BsonDocument> filter = null) : base(version)
 {
     CollectionName = collectionName;
     this.Filter    = filter ?? Builders <BsonDocument> .Filter.Empty;
 }