Use a transaction when creating an artifact.

Signed-off-by: Blaž Hrastnik <blaz.hrast@gmail.com>
I don't think reusing the `tx` here will work as it will have been automatically rolled back by the error.