        dataset.created,
        dataset.modified,
        dataset.id,
+       dataset.author,
        dataset_version.created AS "updated",
        dataset_version.columns,
        dataset_version.transformations

WITH
failed_imports AS (
  --TODO name->title
  SELECT j.id, d.spec->>'name' AS name, j.error_log->>0 AS error_log, j.status, j.created, j.modified
    FROM data_source d, job_execution j
   WHERE j.data_source_id = d.id
     AND j.type = 'IMPORT'

     AND d.spec->'source'->>'kind' != 'GEOTIFF'
),
pending_imports AS (
  SELECT j.id, d.spec->>'name' AS name, j.status, j.created, j.modified, '{}'::jsonb AS author
    FROM data_source d, job_execution j
   WHERE j.data_source_id = d.id
     AND j.type = 'IMPORT'
     AND j.status = 'PENDING'
     AND d.spec->'source'->>'kind' != 'GEOTIFF'
)
SELECT id, name, error_log as reason, status, modified, created, '{}'::jsonb AS author
  FROM failed_imports
 UNION
SELECT id, name, NULL, status, modified, created, '{}'::jsonb AS author
  FROM pending_imports
 UNION
SELECT id, title, NULL, 'OK', modified, created, author
  FROM dataset;

-- :name insert-dataset :! :n
-- :doc Insert new dataset
INSERT INTO dataset(id, title, description, author)
VALUES (:id, :title, :description, :author);

-- :name delete-dataset-by-id :! :n
-- :doc delete dataset
