[banshee] [Banshee.Database] Fail fast if using a database version for a newer banshee



commit 74a313e367549696fd7a086a20e1dce23516d5cb
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Mon Apr 5 16:04:05 2010 +0200

    [Banshee.Database] Fail fast if using a database version for a newer banshee
    
    From now on it will fail with a friendlier exception that indicates
    the current database version being used and the version that banshee
    expects (BGO #614809)

 .../Banshee.Database/BansheeDbFormatMigrator.cs    |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
index 93aa331..c8123b0 100644
--- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbFormatMigrator.cs
@@ -135,7 +135,9 @@ namespace Banshee.Database
         {
             try {
 
-                if (DatabaseVersion < CURRENT_VERSION) {
+                if (DatabaseVersion > CURRENT_VERSION) {
+                    throw new DatabaseVersionTooHigh (CURRENT_VERSION, DatabaseVersion);
+                } else if (DatabaseVersion < CURRENT_VERSION) {
                     Execute ("BEGIN");
                     InnerMigrate ();
                     Execute ("COMMIT");
@@ -148,6 +150,8 @@ namespace Banshee.Database
                 if (DatabaseVersion == CURRENT_VERSION && metadata_version < CURRENT_METADATA_VERSION) {
                     ServiceManager.ServiceStarted += OnServiceStarted;
                 }
+            } catch (DatabaseVersionTooHigh) {
+                throw;
             } catch (Exception) {
                 Log.Warning ("Rolling back database migration");
                 Execute ("ROLLBACK");
@@ -1412,6 +1416,20 @@ namespace Banshee.Database
 
 #endregion
 
+        class DatabaseVersionTooHigh : ApplicationException
+        {
+            internal DatabaseVersionTooHigh (int currentVersion, int databaseVersion)
+                : base (String.Format (
+                "This version of Banshee was prepared to work with older database versions (=< {0}) thus it is too old to support the current version of the database ({1}).",
+                currentVersion, databaseVersion))
+            {
+            }
+
+            private DatabaseVersionTooHigh ()
+            {
+            }
+        }
+
     }
 
     [SqliteFunction (Name = "BANSHEE_MIGRATE_PARTIAL", FuncType = FunctionType.Scalar, Arguments = 2)]



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]