Use a transaction when creating an artifact.

Signed-off-by: Blaž Hrastnik <blaz.hrast@gmail.com>
To take advantage of putting this in a transaction, I think we need to add `FOR UPDATE` to the end of the query.