private void CreateMain(string connectionString, MigrationContext migrationContext) { try { _restoreDatabaseService.Restore(); _migrationController.Migrate(connectionString, migrationContext); } catch (SQLiteException e) { var fileName = _connectionStringFactory.GetDatabasePath(connectionString); if (OsInfo.IsOsx) { throw new CorruptDatabaseException("Database file: {0} is corrupt, restore from backup if available. See: https://wiki.servarr.com/sonarr/faq#i-use-sonarr-on-a-mac-and-it-suddenly-stopped-working-what-happened", e, fileName); } throw new CorruptDatabaseException("Database file: {0} is corrupt, restore from backup if available. See: https://wiki.servarr.com/sonarr/faq#i-am-getting-an-error-database-disk-image-is-malformed", e, fileName); } }
private void CreateMain(string connectionString, MigrationContext migrationContext) { try { _restoreDatabaseService.Restore(); _migrationController.Migrate(connectionString, migrationContext); } catch (SQLiteException e) { var fileName = _connectionStringFactory.GetDatabasePath(connectionString); if (OsInfo.IsOsx) { throw new CorruptDatabaseException("Database file: {0} is corrupt, restore from backup if available. See: https://wiki.servarr.com/Sonarr_FAQ#I_use_Sonarr_on_a_Mac_and_it_suddenly_stopped_working_What_happened", e, fileName); } throw new CorruptDatabaseException("Database file: {0} is corrupt, restore from backup if available. See: https://wiki.servarr.com/Sonarr_FAQ#I_am_getting_an_error_Database_disk_image_is_malformed", e, fileName); } }
public Database(IConfiguration config, IMigrationController migrationController, ILogger <Database> logger) { _connectionString = config.GetConnectionString("Database"); _logger = logger; var context = new MigrationContext(); migrationController.Migrate(_connectionString, context); TableMapping.Map(); }
public IDatabase Create(MigrationContext migrationContext) { string connectionString; switch (migrationContext.MigrationType) { case MigrationType.Main: { connectionString = _connectionStringFactory.MainDbConnectionString; break; } case MigrationType.Log: { connectionString = _connectionStringFactory.LogDbConnectionString; break; } default: { throw new ArgumentException("Invalid MigrationType"); } } _migrationController.Migrate(connectionString, migrationContext); var db = new Database(migrationContext.MigrationType.ToString(), () => { var dataMapper = new DataMapper(SQLiteFactory.Instance, connectionString) { SqlMode = SqlModes.Text, }; return(dataMapper); }); return(db); }
public IDatabase Create(MigrationContext migrationContext) { string connectionString; switch (migrationContext.MigrationType) { case MigrationType.Main: { connectionString = _connectionStringFactory.MainDbConnectionString; break; } case MigrationType.Log: { connectionString = _connectionStringFactory.LogDbConnectionString; break; } default: { throw new ArgumentException("Invalid MigrationType"); } } try { _migrationController.Migrate(connectionString, migrationContext); } catch (SQLiteException ex) { var fileName = _connectionStringFactory.GetDatabasePath(connectionString); if (migrationContext.MigrationType == MigrationType.Log) { Logger.Error(ex, "Logging database is corrupt, attempting to recreate it automatically"); try { _diskProvider.DeleteFile(fileName + "-shm"); _diskProvider.DeleteFile(fileName + "-wal"); _diskProvider.DeleteFile(fileName + "-journal"); _diskProvider.DeleteFile(fileName); } catch (Exception) { Logger.Error("Unable to recreate logging database automatically. It will need to be removed manually."); } _migrationController.Migrate(connectionString, migrationContext); } else { if (OsInfo.IsOsx) { throw new CorruptDatabaseException("Database file: {0} is corrupt, restore from backup if available. See: https://github.com/Radarr/Radarr/wiki/FAQ#i-use-radarr-on-a-mac-and-it-suddenly-stopped-working-what-happened", ex, fileName); } throw new CorruptDatabaseException("Database file: {0} is corrupt, restore from backup if available. See: https://github.com/Radarr/Radarr/wiki/FAQ#i-am-getting-an-error-database-disk-image-is-malformed", ex, fileName); } } catch (Exception e) { throw new RadarrStartupException(e, "Error creating main or log database"); } var db = new Database(migrationContext.MigrationType.ToString(), () => { var dataMapper = new DataMapper(SQLiteFactory.Instance, connectionString) { SqlMode = SqlModes.Text, }; return(dataMapper); }); return(db); }