f-spot r4605 - in trunk: . src



Author: sdelcroix
Date: Fri Nov 21 15:09:26 2008
New Revision: 4605
URL: http://svn.gnome.org/viewvc/f-spot?rev=4605&view=rev

Log:
update db schema to 16.5

2008-11-21  Lorenzo Milesi  <maxxer yetopen it>

	* src/Updater.cs:
	* src/PhotoStore.cs: update to 16.5: photo_versions md5 null by default

Modified:
   trunk/ChangeLog
   trunk/src/PhotoStore.cs
   trunk/src/Updater.cs

Modified: trunk/src/PhotoStore.cs
==============================================================================
--- trunk/src/PhotoStore.cs	(original)
+++ trunk/src/PhotoStore.cs	Fri Nov 21 15:09:26 2008
@@ -127,7 +127,7 @@
 			"	version_id	INTEGER, \n" +
 			"	name		STRING, \n" +
 			"	uri		STRING NOT NULL, \n" +
-			"	md5_sum		STRING NOT NULL, \n" +
+			"	md5_sum		TEXT NULL, \n" +
 			"	protected	BOOLEAN, \n" +
 			"	UNIQUE (photo_id, version_id)\n" +
 			")");
@@ -235,7 +235,7 @@
 #else
 			System.Uri uri = new System.Uri (reader["uri"].ToString (), true);
 #endif
-			string md5_sum = reader["md5_sum"].ToString ();
+			string md5_sum = reader["md5_sum"] != null ? reader ["md5_sum"].ToString () : null;
 			bool is_protected = Convert.ToBoolean (reader["protected"]);
 			photo.AddVersionUnsafely (version_id, uri, md5_sum, name, is_protected);
 		}
@@ -279,8 +279,8 @@
 #else
 				System.Uri uri = new System.Uri (reader["uri"].ToString (), true);
 #endif
-				string md5_sum = reader["md5_sum"].ToString ();
-				bool is_protected = Convert.ToBoolean (reader["protected"]);	
+				string md5_sum = reader["md5_sum"] != null ? reader ["md5_sum"].ToString () : null;
+				bool is_protected = Convert.ToBoolean (reader["protected"]);
 				photo.AddVersionUnsafely (version_id, uri, md5_sum, name, is_protected);
 			}
 

Modified: trunk/src/Updater.cs
==============================================================================
--- trunk/src/Updater.cs	(original)
+++ trunk/src/Updater.cs	Fri Nov 21 15:09:26 2008
@@ -464,6 +464,30 @@
 					"FROM {0}", temp_table));
 			});
 
+			// Update to version 16.5
+			AddUpdate (new Version (16,5), delegate () { //fix md5 null in photos and photo_versions table
+				string temp_table = MoveTableToTemp ("photo_versions");
+				Execute (
+					"CREATE TABLE photo_versions (\n"+
+					"	photo_id	INTEGER, \n" +
+					"	version_id	INTEGER, \n" +
+					"	name		STRING, \n" +
+					"	uri		STRING NOT NULL, \n" +
+					"	md5_sum		TEXT NULL, \n" +
+					"	protected	BOOLEAN, \n" +
+					"	UNIQUE (photo_id, version_id)\n" +
+					")");
+				Execute (String.Format (
+					"INSERT OR IGNORE INTO photo_versions (photo_id, version_id, name, uri, md5_sum, protected) " +
+					"SELECT photo_id, version_id, name, uri, md5_sum, protected " +
+					"FROM {0}", temp_table));
+
+				Execute ("CREATE INDEX idx_photo_versions_id ON photo_versions(photo_id)");
+
+				Execute ("UPDATE photos SET md5_sum = NULL WHERE md5_sum = ''");
+				Execute ("UPDATE photo_versions SET md5_sum = NULL WHERE md5_sum = ''");
+			});
+
 			// Update to version 17.0
 			//AddUpdate (new Version (14,0), delegate () {
 			//	do update here



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