-- +goose Up
-- +goose StatementBegin
create table goqite (
  id text primary key default ('m_' || lower(hex(randomblob(16)))),
  created text not null default (strftime('%Y-%m-%dT%H:%M:%fZ')),
  updated text not null default (strftime('%Y-%m-%dT%H:%M:%fZ')),
  queue text not null,
  body blob not null,
  timeout text not null default (strftime('%Y-%m-%dT%H:%M:%fZ')),
  received integer not null default 0
) strict;

create trigger goqite_updated_timestamp after update on goqite begin
  update goqite set updated = strftime('%Y-%m-%dT%H:%M:%fZ') where id = old.id;
end;

create index goqite_queue_created_idx on goqite (queue, created);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE goqite
DROP INDEX goqite_queue_created_idx
DROP TRIGGER goqite_updated_timestamp
-- +goose StatementEnd
