Example #1
0
        public async Task Copies_All_Rows_Between_DbContexts()
        {
            using var from = await GetDbContext();

            using var to = await GetDbContext();

            await AddData(from);

            Assert.AreNotEqual(await from.Logs.CountAsync(), await to.Logs.CountAsync());

            var dbDataCopyHandler = new DbDataCopyHandler();
            await dbDataCopyHandler.CopyDatas(from, to);

            Assert.AreEqual(await from.Logs.CountAsync(), 3);
            Assert.AreEqual(await from.GuildsSettings.FirstAsync(), await to.GuildsSettings.FirstAsync());
            Assert.AreEqual(await from.Logs.CountAsync(), await to.Logs.CountAsync());
            Assert.AreEqual((await from.TimedActions.FirstAsync()).Id, (await to.TimedActions.FirstAsync()).Id);
        }
Example #2
0
        public async Task ConvertSqliteToPostgres(string sqliteConnectionString, string postgresConnectionString)
        {
            using var sqliteDbContext   = GetSqliteDbContext(sqliteConnectionString);
            using var postgresDbContext = GetPostgresDbContext(postgresConnectionString);

            if (!await sqliteDbContext.Database.CanConnectAsync())
            {
                await ReplyErrorAsync(string.Format(ModuleTexts.ConnectionStringInvalid, "Sqlite", sqliteConnectionString));
            }
            if (!await postgresDbContext.Database.CanConnectAsync())
            {
                await ReplyErrorAsync(string.Format(ModuleTexts.ConnectionStringInvalid, "Postgres", postgresConnectionString));
            }

            await postgresDbContext.Database.MigrateAsync();

            var copyHandler = new DbDataCopyHandler();
            await copyHandler.CopyDatas(sqliteDbContext, postgresDbContext);
        }