use tx instead of r.db

Signed-off-by: Blaž Hrastnik <blaz.hrast@gmail.com>
Add a test for app recreation.

Signed-off-by: Blaž Hrastnik <blaz.hrast@gmail.com>