Axiom is an ORM'ish layer on top of SQLite in Python. Due to unfortunate
historic reasons, Axiom relies on the implicit ROWID (actually "oid")
column present in every table in SQLite, without declaring an explicit
PRIMARY KEY; this, of course, means that VACUUMing an Axiom table will
corrupt it as some or all of the ROWIDs will change.

Over on the Axiom bug tracker[1], we're trying to figure out a way to
transition away from this unfortunate situation to using an explicit
PRIMARY KEY. Unfortunately, ALTER TABLE may not use a PRIMARY KEY
constraint, so it doesn't work for this purpose. However, the following
evil trick seems to work:

PRAGMA writable_schema=on;
UPDATE sqlite_master SET sql='CREATE TABLE some_table_name (..., storeID
INTEGER PRIMARY KEY)' WHERE tbl_name='some_table_name';

The following notebook session seems to demonstrate that it works:

http://nbviewer.jupyter.org/url/bucket.mithrandi.net/sqlite-vacuum-working.ipynb

and for completeness, here's a similar session demonstrating how VACUUM
changes the values without the schema trickery:

http://nbviewer.jupyter.org/url/bucket.mithrandi.net/sqlite-vacuum-broken.ipynb

However, the question is whether this is something we can and should be
relying on to function correctly. Are there any likely problems with this
trick?

[1] https://github.com/twisted/axiom/issues/35

Reply via email to