﻿using System;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Announcers;
using FluentMigrator.Runner.Initialization;
using FluentMigrator.Runner.Processors.SqlServer;

namespace BroadbandStats.Database.Migrations
{
    public sealed class Migrator
    {
        private readonly string connectionString;

        public Migrator(string connectionString)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            this.connectionString = connectionString;
        }

        public void MigrateToLatestSchema()
        {
            var todaysDate = DateTime.Today.ToString("yyyyMMdd");
            var todaysSchemaVersion = long.Parse(todaysDate);
            MigrateTo(todaysSchemaVersion);
        }

        private void MigrateTo(long targetVersion)
        {
            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var announcer = new NullAnnouncer();
            var processor = new SqlServer2012ProcessorFactory().Create(connectionString, announcer, options);
            var migrationContext = new RunnerContext(announcer) { Namespace = "BroadbandSpeedTests.Database.Migrations.Migrations" };

            var runner = new MigrationRunner(GetType().Assembly, migrationContext, processor);
            runner.MigrateUp(targetVersion, true);
        }
    }
}

﻿using System;
using BroadbandStats.Database.Migrations.Migrations;
using FluentMigrator.Runner;
using FluentMigrator.Runner.Announcers;
using FluentMigrator.Runner.Initialization;
using FluentMigrator.Runner.Processors.SqlServer;

namespace BroadbandStats.Database.Migrations
{
    public sealed class Migrator
    {
        private readonly string connectionString;

        public Migrator(string connectionString)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            this.connectionString = connectionString;
        }

        public void MigrateToLatestSchema()
        {
            var todaysDate = DateTime.Today.ToString("yyyyMMdd");
            var todaysSchemaVersion = long.Parse(todaysDate);
            MigrateTo(todaysSchemaVersion);
        }

        private void MigrateTo(long targetVersion)
        {
            var options = new MigrationOptions { PreviewOnly = false, Timeout = 60 };
            var announcer = new NullAnnouncer();
            var processor = new SqlServer2012ProcessorFactory().Create(connectionString, announcer, options);
            var migrationContext = new RunnerContext(announcer) { Namespace = typeof(InitialDatabase).Namespace };

            var runner = new MigrationRunner(GetType().Assembly, migrationContext, processor);
            runner.MigrateUp(targetVersion, true);
        }
    }
}

Fix the namespace following an earlier rename
Fix the namespace following an earlier rename
