Exemple #1
0
        private async Task RunAfterMigrationAsync(AppCoreMigration migration, DatabaseVersionModel databaseVersion)
        {
            // Check Actual DatabaseVersion against the migration version
            // Don't run unless the MigrationVersion is 1 more than DatabaseVersion
            if (databaseVersion.IsAfterMigrationComplete == false)
            {
                await migration.RunOrderedMigrationAsync(MigrationStep.AfterMigrate, _dbProvider).ConfigureAwait(false);

                if (_systemRole == SystemRole.Server)
                {
                    await migration.RunOrderedMigrationAsync(MigrationStep.ServerAfterMigrate, _dbProvider).ConfigureAwait(false);
                }
                if (_systemRole == SystemRole.Client)
                {
                    await migration.RunOrderedMigrationAsync(MigrationStep.ClientAfterMigrate, _dbProvider).ConfigureAwait(false);
                }

                // UpdateAsync the database version to show the after migration has been run
                databaseVersion.IsAfterMigrationComplete = true;
                await _dbProvider.Query <DatabaseVersionModel>()
                .Where(dbv => dbv.VersionNumber == migration.MigrationVersion)
                .UpdateAsync(databaseVersion)
                .ConfigureAwait(false);
            }
        }
Exemple #2
0
        public async Task RunAsync(SystemRole systemRole, AppCoreMigration migration)
        {
            _systemRole = systemRole;

            var databaseVersion = await GetMigrationInformationAsync(migration).ConfigureAwait(false);

            await RunBeforeMigrationAsync(migration, databaseVersion).ConfigureAwait(false);
            await RunMigrationAsync(migration, databaseVersion).ConfigureAwait(false);
            await RunAfterMigrationAsync(migration, databaseVersion).ConfigureAwait(false);
        }
Exemple #3
0
        private async Task <DatabaseVersionModel> GetMigrationInformationAsync(AppCoreMigration migration)
        {
            var databaseVersions = await _dbProvider.Query <DatabaseVersionModel>()
                                   .Where(dbv => dbv.VersionNumber == migration.MigrationVersion)
                                   .OrderBy(v => v.VersionNumber, OrderDirection.Descending)
                                   .SelectAsync()
                                   .ConfigureAwait(false);

            var databaseVersion = databaseVersions.FirstOrDefault();

            if (databaseVersion == null)
            {
                databaseVersion = new DatabaseVersionModel
                {
                    VersionNumber = migration.MigrationVersion,
                    MigrationDate = DateTime.UtcNow
                };
                await _dbProvider.CreateAsync(databaseVersion).ConfigureAwait(false);
            }

            return(databaseVersion);
        }
Exemple #4
0
 public void Run(SystemRole systemRole, AppCoreMigration migrations) => RunAsync(systemRole, migrations).Wait();