
In the process, realised that using appId as a foreign key is worse than packageName, because appId can get removed and added again, but it will be different when the same app is inserted a second time. In order to maintain the association of which apps have preferences stored against them, they need to be stored against something with a bit more semantic meaning. Thus, join onto package name instead.