Beispiel #1
0
        public static void Initialize(DatabaseConfig config)
        {
            s_connectionString = $"SslMode=none;Server={config.Host};Port={config.Port};Database={config.Database};Uid={config.Username};Pwd={config.Password};Pooling=true;";
            OrmConfiguration.DefaultDialect = SqlDialect.MySql;

            using (var con = Open())
            {
                if (con.QueryFirstOrDefault($"SHOW DATABASES LIKE \"{config.Database}\"") == null)
                {
                    throw new DatabaseNotFoundException(config.Database);
                }

                var databaseProvider = new MysqlDatabaseProvider(con)
                {
                    TableName = "__version"
                };
                var assemblyProvider = new AssemblyMigrationProvider(typeof(Base).Assembly, typeof(Base).Namespace);
                var migrator         = new SimpleMigrator(assemblyProvider, databaseProvider);
                migrator.Load();
                if (migrator.CurrentMigration.Version != migrator.LatestMigration.Version)
                {
                    if (config.RunMigration)
                    {
                        migrator.MigrateToLatest();
                    }
                    else
                    {
                        throw new DatabaseVersionMismatchException(migrator.CurrentMigration.Version, migrator.LatestMigration.Version);
                    }
                }
            }
        }
        public static void MigrateSqlDbData(string sqlConnectionString)
        {
            var migrationsAssembly = typeof(Program).Assembly;

            using (var connection = new MySqlConnection(sqlConnectionString))
            {
                var databaseProvider = new MysqlDatabaseProvider(connection);
                var migrator         = new SimpleMigrator(migrationsAssembly, databaseProvider);
                migrator.Load();
                migrator.MigrateTo(2018_10_18_00_45);
            }
        }
Beispiel #3
0
        public void Migrate(string[] args)
        {
            var options          = Cli.Parse <MigrateOptions>(args);
            var connectionString = $"SslMode=none;Server={options.Host};Port={options.Port};Database={options.Database};Uid={options.User};Pwd={options.Password};";

            using (var con = new MySqlConnection(connectionString))
            {
                con.Open();
                var databaseProvider = new MysqlDatabaseProvider(con)
                {
                    TableName = "__version"
                };
                AssemblyMigrationProvider assemblyProvider = null;
                switch (options.Schema.ToLower())
                {
                case "auth":
                    assemblyProvider = new AssemblyMigrationProvider(s_authType.Assembly, s_authType.Namespace);
                    break;

                case "game":
                    assemblyProvider = new AssemblyMigrationProvider(s_gameType.Assembly, s_gameType.Namespace);
                    break;

                default:
                    Error("Invalid schema");
                    break;
                }

                try
                {
                    var migrator = new SimpleMigrator(assemblyProvider, databaseProvider, new ConsoleLogger());
                    migrator.Load();
                    if (options.CurrentVersion > 0)
                    {
                        migrator.Baseline(options.CurrentVersion);
                    }

                    if (options.Version == 0)
                    {
                        migrator.MigrateToLatest();
                    }
                    else
                    {
                        migrator.MigrateTo(options.Version);
                    }
                }
                catch (MigrationNotFoundException ex)
                {
                    Error(ex.Message);
                }
            }
        }
        public static void Main(string[] args)
        {
            var migrationsAssembly = typeof(Program).GetTypeInfo().Assembly;
            var connectionString   = @"Server=; Port=; Database=; Uid = user; Pwd = pass;";

            using (var connection = new MySqlConnection(connectionString))
            {
                var databaseProvider = new MysqlDatabaseProvider(connection);
                var migrator         = new SimpleMigrator(migrationsAssembly, databaseProvider);

                ConsoleRunner consoleRunner = new ConsoleRunner(migrator);
                consoleRunner.Run(args);
            }
        }
Beispiel #5
0
    private static void DoMigration(string connectionString, Action <SimpleMigrator> act)
    {
        // Connection to database
        using var db = new MySqlConnection(connectionString);

        // Get migration objects
        var provider = new MysqlDatabaseProvider(db)
        {
            TableName = $"`{AuthDb.Schema}.version_info`"
        };
        var migrator = new SimpleMigrator(typeof(MySqlDbClient).Assembly, provider, new ConsoleLogger());

        // Get all the migrations
        migrator.Load();

        // Perform the migration
        act(migrator);
    }