Merge authors:
  Siegfried Gevatter (rainct)
Related merge proposals:
  https://code.launchpad.net/~rainct/zeitgeist/schema6/+merge/92519
  proposed by: Siegfried Gevatter (rainct)
  review: Needs Information - Michal Hruby (mhr3)
------------------------------------------------------------
revno: 398 [merge]
committer: Siegfried-Angel Gevatter Pujals <siegfr...@gevatter.com>
branch nick: bluebird
timestamp: Sun 2012-02-12 21:52:37 +0100
message:
  Merge lp:~rainct/zeitgeist/schema6:
  
   - Change HTTP(S) mapping from RemoteDataObject to WebDataObject
   - Fix some bad stuff in mimetypes.py
modified:
  NEWS
  python/mimetypes.py
  src/mimetype.vala
  src/sql-schema.vala


--
lp:zeitgeist
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird

Your team Zeitgeist Framework Team is subscribed to branch lp:zeitgeist.
To unsubscribe from this branch go to 
https://code.launchpad.net/~zeitgeist/zeitgeist/bluebird/+edit-subscription
=== modified file 'NEWS'
--- NEWS	2012-02-12 20:08:32 +0000
+++ NEWS	2012-02-12 20:52:37 +0000
@@ -6,6 +6,8 @@
  - The FTS module in Python has been replaced with a C/C++ implementation.
  - Pre-process events *before* they are send to extensions (LP: #628804).
  - Minor fixes.
+ - Introduced new DB schema (version 6); cached tables may no longer
+   re-use row IDs.
 
 Python API:
  - Fixed signal/monitor reconnection to avoid duplicated notifications.

=== modified file 'python/mimetypes.py'
--- python/mimetypes.py	2012-02-12 20:08:32 +0000
+++ python/mimetypes.py	2012-02-12 20:52:37 +0000
@@ -218,8 +218,8 @@
 
 SCHEMES = tuple((
     ("file://", Manifestation.FILE_DATA_OBJECT),
-    ("http://";, Manifestation.REMOTE_DATA_OBJECT),
-    ("https://";, Manifestation.REMOTE_DATA_OBJECT),
+    ("http://";, Manifestation.WEB_DATA_OBJECT),
+    ("https://";, Manifestation.WEB_DATA_OBJECT),
     ("ssh://", Manifestation.REMOTE_DATA_OBJECT),
     ("sftp://";, Manifestation.REMOTE_DATA_OBJECT),
     ("ftp://";, Manifestation.REMOTE_DATA_OBJECT),

=== modified file 'src/mimetype.vala'
--- src/mimetype.vala	2012-01-25 12:52:46 +0000
+++ src/mimetype.vala	2012-02-10 19:28:47 +0000
@@ -333,8 +333,8 @@
             return;
 
         register_uri_scheme ("file://", NFO.FILE_DATA_OBJECT);
-        register_uri_scheme ("http://";, NFO.REMOTE_DATA_OBJECT);
-        register_uri_scheme ("https://";, NFO.REMOTE_DATA_OBJECT);
+        register_uri_scheme ("http://";, NFO.WEB_DATA_OBJECT);
+        register_uri_scheme ("https://";, NFO.WEB_DATA_OBJECT);
         register_uri_scheme ("ssh://", NFO.REMOTE_DATA_OBJECT);
         register_uri_scheme ("sftp://";, NFO.REMOTE_DATA_OBJECT);
         register_uri_scheme ("ftp://";, NFO.REMOTE_DATA_OBJECT);

=== modified file 'src/sql-schema.vala'
--- src/sql-schema.vala	2012-02-06 16:11:53 +0000
+++ src/sql-schema.vala	2012-02-10 16:52:57 +0000
@@ -35,7 +35,7 @@
     {
 
         public const string CORE_SCHEMA = "core";
-        public const int CORE_SCHEMA_VERSION = 5;
+        public const int CORE_SCHEMA_VERSION = 6;
 
         public static void ensure_schema (Sqlite.Database database)
             throws EngineError
@@ -48,19 +48,55 @@
                 // most likely a new DB
                 create_schema (database);
             }
-            else if (schema_version == 4)
+            else if (schema_version == 4 || schema_version == 5)
             {
-                // DB from latest Python Zeitgeist, which we can "upgrade"
-                try
-                {
-                  Utils.backup_database ();
-                }
-                catch (Error backup_error)
-                {
-                    var msg = "Database backup failed: " + backup_error.message;
-                    throw new EngineError.BACKUP_FAILED (msg);
-                }
+                backup_database ();
+
+                string[] tables = { "interpretation", "manifestation",
+                    "mimetype", "actor" };
+
+                // Rename old tables that need to be replaced
+                foreach (unowned string table in tables)
+                {
+                    exec_query (database,
+                        "ALTER TABLE %s RENAME TO %s_old".printf (table, table));
+                }
+
+                // Create any missing tables and indices
                 create_schema (database);
+
+                // Migrate data to the new tables and delete the old ones
+                foreach (unowned string table in tables)
+                {
+                    exec_query (database,
+                        "INSERT INTO %s SELECT id, value FROM %s_old".printf (
+                        table, table));
+
+                    exec_query (database, "DROP TABLE %s_old".printf (table));
+                }
+
+                // Ontology update
+                exec_query (database,
+                    "INSERT OR IGNORE INTO manifestation (value) VALUES ('%s')"
+                    .printf (NFO.WEB_DATA_OBJECT));
+                exec_query (database, """
+                    UPDATE event
+                    SET subj_manifestation=(
+                        SELECT id FROM manifestation WHERE value='""" +
+                            NFO.WEB_DATA_OBJECT + """')
+                    WHERE
+                        subj_manifestation=(
+                            SELECT id FROM manifestation WHERE value='""" +
+                                NFO.WEB_DATA_OBJECT + """')
+                        AND subj_id IN (
+                            SELECT id FROM uri
+                            WHERE
+                                value LIKE "http://%";
+                                OR value LIKE "https://%";
+                        )
+                    """);
+
+                message ("Upgraded database to schema version 6.");
             }
             else if (schema_version < CORE_SCHEMA_VERSION)
             {
@@ -70,6 +106,19 @@
             }
         }
 
+        private static void backup_database () throws EngineError
+        {
+            try
+            {
+              Utils.backup_database ();
+            }
+            catch (Error backup_error)
+            {
+                var msg = "Database backup failed: " + backup_error.message;
+                throw new EngineError.BACKUP_FAILED (msg);
+            }
+        }
+
         public static int get_schema_version (Sqlite.Database database)
         {
           var sql = "SELECT version FROM schema_version WHERE schema='core'";
@@ -116,7 +165,7 @@
             // Interpretation
             exec_query (database, """
                 CREATE TABLE IF NOT EXISTS interpretation (
-                    id INTEGER PRIMARY KEY,
+                    id INTEGER PRIMARY KEY AUTOINCREMENT,
                     value VARCHAR UNIQUE
                 )
                 """);
@@ -128,7 +177,7 @@
             // Manifestation
             exec_query (database, """
                 CREATE TABLE IF NOT EXISTS manifestation (
-                    id INTEGER PRIMARY KEY,
+                    id INTEGER PRIMARY KEY AUTOINCREMENT,
                     value VARCHAR UNIQUE
                 )
                 """);
@@ -140,7 +189,7 @@
             // Mime-Type
             exec_query (database, """
                 CREATE TABLE IF NOT EXISTS mimetype (
-                    id INTEGER PRIMARY KEY,
+                    id INTEGER PRIMARY KEY AUTOINCREMENT,
                     value VARCHAR UNIQUE
                 )
                 """);
@@ -152,7 +201,7 @@
             // Actor
             exec_query (database, """
                 CREATE TABLE IF NOT EXISTS actor (
-                    id INTEGER PRIMARY KEY,
+                    id INTEGER PRIMARY KEY AUTOINCREMENT,
                     value VARCHAR UNIQUE
                 )
                 """);

_______________________________________________
Mailing list: https://launchpad.net/~zeitgeist
Post to     : zeitgeist@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zeitgeist
More help   : https://help.launchpad.net/ListHelp

Reply via email to