feat(db): Add table for census upload job status

This commit is contained in:
Michael Gaffney committed 2023-06-05 11:32:26 -04:00
1 parent 8bf80e0544
commit 053e74f66c
3 files changed
+52

No files matched your search

@@ -0,0 +1,20 @@
-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: MPL-2.0
begin;
create table census_last_uploaded (
last_uploaded_at wt_timestamp primary key
);
comment on table census_last_uploaded is
'census_last_uploaded is a table with 1 row which contains '
'the timestamp of the last time census data was uploaded.';
-- This index ensures that there will only ever be one row in the table.
-- See: https://www.postgresql.org/docs/current/indexes-expressional.html
create unique index census_last_uploaded_one_row
on census_last_uploaded((last_uploaded_at is not null));
insert into census_last_uploaded(last_uploaded_at) values('-infinity');
commit;
+1
View File
@@ -27,6 +27,7 @@ TESTS ?= tests/setup/*.sql \
tests/target/*.sql \
tests/controller/*.sql \
tests/hcp/*/*.sql \
tests/census/*.sql \
tests/kms/*.sql \
tests/storage/*.sql \
tests/domain/*.sql \
@@ -0,0 +1,31 @@
-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: MPL-2.0
begin;
select plan(6);
select has_table('census_last_uploaded');
select is(count(*), 1::bigint, 'census_last_uploaded should have only 1 row') from census_last_uploaded;
select ok(not isfinite(last_uploaded_at)) from census_last_uploaded;
prepare insert_row as
insert into census_last_uploaded
(last_uploaded_at)
values
(now());
select throws_ok('insert_row', '23505',
'duplicate key value violates unique constraint "census_last_uploaded_one_row"',
'insert into census_last_uploaded should fail');
prepare update_census_last_uploaded as
update census_last_uploaded
set last_uploaded_at = now();
select lives_ok('update_census_last_uploaded');
select ok(isfinite(last_uploaded_at)) from census_last_uploaded;
select * from finish();
rollback;