Merge lp:~rainct/zeitgeist/schema6 into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Merged at revision: 398
Proposed branch: lp:~rainct/zeitgeist/schema6
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 212 lines (+81/-27)
5 files modified
NEWS (+4/-1)
python/mimetypes.py (+8/-8)
src/mimetype.vala (+2/-2)
src/sql-schema.vala (+65/-16)
src/utils.vala (+2/-0)
To merge this branch: bzr merge lp:~rainct/zeitgeist/schema6
Reviewer Review Type Date Requested Status
Michal Hruby (community) Needs Information
Review via email: mp+92519@code.launchpad.net
To post a comment you must log in.
lp:~rainct/zeitgeist/schema6 updated
396. By Siegfried Gevatter

 - Change HTTP(S) mapping from RemoteDataObject to WebDataObject
 - Fix some bad stuff in mimetypes.py

Revision history for this message
Michal Hruby (mhr3) wrote :

Although I generally like this, we are breaking existing clients - for example Synapse uses the RemoteDataObject interpretation to query for web stuff... Not sure how to handle this, ideas?

review: Needs Information
Revision history for this message
Siegfried Gevatter (rainct) wrote :

<mhr3> master seiflotfy said break, so break it

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2012-02-10 14:42:54 +0000
3+++ NEWS 2012-02-10 19:32:21 +0000
4@@ -6,6 +6,8 @@
5 - The FTS module in Python has been replaced with a C/C++ implementation.
6 - Pre-process events *before* they are send to extensions (LP: #628804).
7 - Minor fixes.
8+ - Introduced new DB schema (version 6); cached tables may no longer
9+ re-use row IDs.
10
11 Python API:
12 - Fixed signal/monitor reconnection to avoid duplicated notifications.
13@@ -42,9 +44,10 @@
14
15 Engine:
16
17- - The language for extensions has changes from Python to Vala.
18+ - Changed the language for extensions from Python to Vala.
19 - The post_get_events hook is no longer supported.
20 - The FTS and Histogram extensions are now shipped together with Zeitgeist.
21+ - Introduced new DB schema (version 5).
22
23 ---------------------------------------------------------------------
24 ---------------------------------------------------------------------
25
26=== modified file 'python/mimetypes.py'
27--- python/mimetypes.py 2012-02-06 10:11:17 +0000
28+++ python/mimetypes.py 2012-02-10 19:32:21 +0000
29@@ -218,12 +218,12 @@
30
31 SCHEMES = tuple((
32 ("file://", Manifestation.FILE_DATA_OBJECT),
33- ("http://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
34- ("https://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
35- ("ssh://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
36- ("sftp://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
37- ("ftp://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
38- ("dav://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
39- ("davs://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
40- ("smb://", Manifestation.FILE_DATA_OBJECT.REMOTE_DATA_OBJECT),
41+ ("http://", Manifestation.WEB_DATA_OBJECT),
42+ ("https://", Manifestation.WEB_DATA_OBJECT),
43+ ("ssh://", Manifestation.REMOTE_DATA_OBJECT),
44+ ("sftp://", Manifestation.REMOTE_DATA_OBJECT),
45+ ("ftp://", Manifestation.REMOTE_DATA_OBJECT),
46+ ("dav://", Manifestation.REMOTE_DATA_OBJECT),
47+ ("davs://", Manifestation.REMOTE_DATA_OBJECT),
48+ ("smb://", Manifestation.REMOTE_DATA_OBJECT),
49 ))
50
51=== modified file 'src/mimetype.vala'
52--- src/mimetype.vala 2012-01-25 12:52:46 +0000
53+++ src/mimetype.vala 2012-02-10 19:32:21 +0000
54@@ -333,8 +333,8 @@
55 return;
56
57 register_uri_scheme ("file://", NFO.FILE_DATA_OBJECT);
58- register_uri_scheme ("http://", NFO.REMOTE_DATA_OBJECT);
59- register_uri_scheme ("https://", NFO.REMOTE_DATA_OBJECT);
60+ register_uri_scheme ("http://", NFO.WEB_DATA_OBJECT);
61+ register_uri_scheme ("https://", NFO.WEB_DATA_OBJECT);
62 register_uri_scheme ("ssh://", NFO.REMOTE_DATA_OBJECT);
63 register_uri_scheme ("sftp://", NFO.REMOTE_DATA_OBJECT);
64 register_uri_scheme ("ftp://", NFO.REMOTE_DATA_OBJECT);
65
66=== modified file 'src/sql-schema.vala'
67--- src/sql-schema.vala 2012-02-06 16:11:53 +0000
68+++ src/sql-schema.vala 2012-02-10 19:32:21 +0000
69@@ -35,7 +35,7 @@
70 {
71
72 public const string CORE_SCHEMA = "core";
73- public const int CORE_SCHEMA_VERSION = 5;
74+ public const int CORE_SCHEMA_VERSION = 6;
75
76 public static void ensure_schema (Sqlite.Database database)
77 throws EngineError
78@@ -48,19 +48,55 @@
79 // most likely a new DB
80 create_schema (database);
81 }
82- else if (schema_version == 4)
83+ else if (schema_version == 4 || schema_version == 5)
84 {
85- // DB from latest Python Zeitgeist, which we can "upgrade"
86- try
87- {
88- Utils.backup_database ();
89- }
90- catch (Error backup_error)
91- {
92- var msg = "Database backup failed: " + backup_error.message;
93- throw new EngineError.BACKUP_FAILED (msg);
94- }
95+ backup_database ();
96+
97+ string[] tables = { "interpretation", "manifestation",
98+ "mimetype", "actor" };
99+
100+ // Rename old tables that need to be replaced
101+ foreach (unowned string table in tables)
102+ {
103+ exec_query (database,
104+ "ALTER TABLE %s RENAME TO %s_old".printf (table, table));
105+ }
106+
107+ // Create any missing tables and indices
108 create_schema (database);
109+
110+ // Migrate data to the new tables and delete the old ones
111+ foreach (unowned string table in tables)
112+ {
113+ exec_query (database,
114+ "INSERT INTO %s SELECT id, value FROM %s_old".printf (
115+ table, table));
116+
117+ exec_query (database, "DROP TABLE %s_old".printf (table));
118+ }
119+
120+ // Ontology update
121+ exec_query (database,
122+ "INSERT OR IGNORE INTO manifestation (value) VALUES ('%s')"
123+ .printf (NFO.WEB_DATA_OBJECT));
124+ exec_query (database, """
125+ UPDATE event
126+ SET subj_manifestation=(
127+ SELECT id FROM manifestation WHERE value='""" +
128+ NFO.WEB_DATA_OBJECT + """')
129+ WHERE
130+ subj_manifestation=(
131+ SELECT id FROM manifestation WHERE value='""" +
132+ NFO.WEB_DATA_OBJECT + """')
133+ AND subj_id IN (
134+ SELECT id FROM uri
135+ WHERE
136+ value LIKE "http://%"
137+ OR value LIKE "https://%"
138+ )
139+ """);
140+
141+ message ("Upgraded database to schema version 6.");
142 }
143 else if (schema_version < CORE_SCHEMA_VERSION)
144 {
145@@ -70,6 +106,19 @@
146 }
147 }
148
149+ private static void backup_database () throws EngineError
150+ {
151+ try
152+ {
153+ Utils.backup_database ();
154+ }
155+ catch (Error backup_error)
156+ {
157+ var msg = "Database backup failed: " + backup_error.message;
158+ throw new EngineError.BACKUP_FAILED (msg);
159+ }
160+ }
161+
162 public static int get_schema_version (Sqlite.Database database)
163 {
164 var sql = "SELECT version FROM schema_version WHERE schema='core'";
165@@ -116,7 +165,7 @@
166 // Interpretation
167 exec_query (database, """
168 CREATE TABLE IF NOT EXISTS interpretation (
169- id INTEGER PRIMARY KEY,
170+ id INTEGER PRIMARY KEY AUTOINCREMENT,
171 value VARCHAR UNIQUE
172 )
173 """);
174@@ -128,7 +177,7 @@
175 // Manifestation
176 exec_query (database, """
177 CREATE TABLE IF NOT EXISTS manifestation (
178- id INTEGER PRIMARY KEY,
179+ id INTEGER PRIMARY KEY AUTOINCREMENT,
180 value VARCHAR UNIQUE
181 )
182 """);
183@@ -140,7 +189,7 @@
184 // Mime-Type
185 exec_query (database, """
186 CREATE TABLE IF NOT EXISTS mimetype (
187- id INTEGER PRIMARY KEY,
188+ id INTEGER PRIMARY KEY AUTOINCREMENT,
189 value VARCHAR UNIQUE
190 )
191 """);
192@@ -152,7 +201,7 @@
193 // Actor
194 exec_query (database, """
195 CREATE TABLE IF NOT EXISTS actor (
196- id INTEGER PRIMARY KEY,
197+ id INTEGER PRIMARY KEY AUTOINCREMENT,
198 value VARCHAR UNIQUE
199 )
200 """);
201
202=== modified file 'src/utils.vala'
203--- src/utils.vala 2012-02-06 16:19:27 +0000
204+++ src/utils.vala 2012-02-10 19:32:21 +0000
205@@ -124,6 +124,8 @@
206 original = File.new_for_path (get_database_file_path ());
207 destination = File.new_for_path (get_database_file_backup_path ());
208
209+ message ("Backing up database to \"%s\" for schema upgrade...",
210+ get_database_file_backup_path ());
211 original.copy (destination, FileCopyFlags.OVERWRITE, null, null);
212 }
213

Subscribers

People subscribed via source and target branches