private void Initialize(IDatabase database)
        {
            if (database.CreateDatabase())
            {
                ScriptRunner scriptRunner = new ScriptRunner(database);

                // create table structure
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "schema_sqlite.sql"));

                // insert maps
                foreach (MapSetting mapSetting in _settingRepository.map.Values)
                {
                    MapData mapData = new MapData();
                    mapData.id      = mapSetting.id;
                    mapData.country = mapSetting.country;
                    if (mapData.country == null)
                    {
                        mapData.country = "";
                    }
                    mapData.area = mapSetting.area;
                    if (mapData.area == null)
                    {
                        mapData.area = "";
                    }
                    mapData.place = mapSetting.place;
                    if (mapData.place == null)
                    {
                        mapData.place = "";
                    }
                    mapData.x           = mapSetting.x;
                    mapData.y           = mapSetting.y;
                    mapData.z           = mapSetting.z;
                    mapData.orientation = mapSetting.orientation;
                    if (!database.InsertMap(mapData))
                    {
                        _Logger.Error($"MapId: {mapData.id} - failed to insert`");
                        return;
                    }
                }

                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_account.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_npc_spawn.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_monster_spawn.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_skill.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_union.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_auction.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_gimmick.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_maptransition.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_ggate.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_item_library.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_item_instance.sql"));
                scriptRunner.Run(Path.Combine(_setting.databaseSettings.scriptFolder, "data_shortcut_bar.sql"));
            }

            SqlMigrator migrator = new SqlMigrator(database);

            migrator.Migrate(Path.Combine(_setting.databaseSettings.scriptFolder, "Migrations/"));
        }
Exemplo n.º 2
0
        private void TestValid(IDatabase db)
        {
            SqlMigrator migrator = new SqlMigrator(db);

            migrator.Migrate(MIGRATION_DIR);
            /* Highest migration version = 2. */
            Assert.Equal(2, db.version);
            db.version = 0;
            Assert.Equal(0, db.version);
        }
Exemplo n.º 3
0
        private void TestInvalid(IDatabase db)
        {
            SqlMigrator migrator = new SqlMigrator(db);

            /* FAIL_DUPLICATE migration file is a version duplicate. */
            Create(FAIL_DUPLICATE);
            Assert.Throws <ArgumentException>(() => { migrator.Migrate(MIGRATION_DIR); });
            File.Delete(FAIL_DUPLICATE);

            /* FAIL_NOVERSION migration file has an invalid name, with no version. */
            Create(FAIL_NOVERSION);
            Assert.Throws <FormatException>(() => { migrator.Migrate(MIGRATION_DIR); });
            File.Delete(FAIL_NOVERSION);
        }
Exemplo n.º 4
0
        private async Task <SqlMigrator <int> > GetMigratorAsync(SqlConnection dest)
        {
            var result = await SqlMigrator <int> .InitializeAsync(dest);

            // ignore PK violations, but throw all others
            result.OnInsertException = AnalyzeInsertExceptionAsync;

            // in AH4 when mapping from dbo.Customer, if the sourceId is negative, it's being used as a Folder.ParentId.
            // I didn't have a way to do this delcaratively within the migration model, so it's hardcoded into the migrator.
            result.OnMappingException = async(exc, cn, obj, sourceId, txn) =>
            {
                if (sourceId < 0 && obj.Equals(DbObject.Parse("dbo.Customer")))
                {
                    return(await result.GetNewIdAsync(cn, obj, sourceId * -1, txn));
                }

                ConsoleMessage?.Invoke(this, $"Mapping exception: {exc.Message}");
                return(default);
 private void ShowProgress(object sender, SqlMigrator <int> .Progress e)
 {
     pbMain.Value     = e.PercentComplete;
     tslProgress.Text = $"{e.TotalRows:n0} total rows, {e.RowsMigrated:n0} migrated ({e.PercentComplete}%), {e.RowsSkipped:n0} skipped";
 }