private static bool CheckMigrationHistoryTable() { bool tableExists = false; using (var sqLiteDatabase = new SqLiteDatabase()) { sqLiteDatabase.OpenConnection(); string query = $"SELECT name FROM sqlite_master WHERE type='table' AND name='{_migrationTableName}';"; string value = sqLiteDatabase.ExecuteScalar(query); tableExists = !string.IsNullOrWhiteSpace(value); sqLiteDatabase.CloseConnection(); } return(tableExists); }
private static IEnumerable <KeyValuePair <int, string> > GetPendingMigrationsToApply() { int maxVersion = -1; try { using (var sqLiteDatabase = new SqLiteDatabase()) { sqLiteDatabase.OpenConnection(); string createquery = $"SELECT MAX(Version) FROM {_migrationTableName}; "; string maxVersionInDb = sqLiteDatabase.ExecuteScalar(createquery); maxVersion = string.IsNullOrWhiteSpace(maxVersionInDb) ? -1 : int.Parse(maxVersionInDb); sqLiteDatabase.CloseConnection(); } return(Migrations.migrationData.Where(x => x.Key > maxVersion).OrderBy(x => x.Key)); } catch (Exception) { return(null); } }