diff --git a/aggregator_core/src/datastore.rs b/aggregator_core/src/datastore.rs index 197d91740..e57b5c617 100644 --- a/aggregator_core/src/datastore.rs +++ b/aggregator_core/src/datastore.rs @@ -100,7 +100,7 @@ macro_rules! supported_schema_versions { // version is seen, [`Datastore::new`] fails. // // Note that the latest supported version must be first in the list. -supported_schema_versions!(1); +supported_schema_versions!(2); /// Datastore represents a datastore for Janus, with support for transactional reads and writes. /// In practice, Datastore instances are currently backed by a PostgreSQL database. diff --git a/db/00000000000001_initial_schema.down.sql b/db/00000000000001_initial_schema.down.sql index d2d870567..6a1156840 100644 --- a/db/00000000000001_initial_schema.down.sql +++ b/db/00000000000001_initial_schema.down.sql @@ -25,7 +25,6 @@ DROP INDEX client_reports_task_and_timestamp_unaggregated_index CASCADE; DROP TABLE client_reports CASCADE; DROP TABLE task_hpke_keys CASCADE; DROP INDEX task_id_index CASCADE; -DROP TABLE task_upload_counters CASCADE; DROP TABLE tasks CASCADE; DROP TABLE taskprov_aggregator_auth_tokens; DROP TABLE taskprov_collector_auth_tokens; diff --git a/db/00000000000001_initial_schema.up.sql b/db/00000000000001_initial_schema.up.sql index 8ffa65dd7..3b9f203c7 100644 --- a/db/00000000000001_initial_schema.up.sql +++ b/db/00000000000001_initial_schema.up.sql @@ -133,26 +133,6 @@ CREATE TABLE tasks( ); CREATE INDEX task_id_index ON tasks(task_id); --- Per task report upload counters. -CREATE TABLE task_upload_counters( - id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, -- artificial ID, internal-only - task_id BIGINT NOT NULL, - - interval_collected BIGINT NOT NULL DEFAULT 0, -- Reports submitted for an interval that was already collected. - report_decode_failure BIGINT NOT NULL DEFAULT 0, -- Reports which failed to decode. - report_decrypt_failure BIGINT NOT NULL DEFAULT 0, -- Reports which failed to decrypt. - report_expired BIGINT NOT NULL DEFAULT 0, -- Reports that were older than the task's report_expiry_age. - report_outdated_key BIGINT NOT NULL DEFAULT 0, -- Reports that were encrypted with an unknown or outdated HPKE key. - report_success BIGINT NOT NULL DEFAULT 0, -- Reports that were successfully uploaded. - report_too_early BIGINT NOT NULL DEFAULT 0, -- Reports whose timestamp is too far in the future. - task_expired BIGINT NOT NULL DEFAULT 0, -- Reports sent to the task while it is expired. - - ord BIGINT NOT NULL, -- Index of this task_upload_counters shard. - - CONSTRAINT fk_task_id FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE, - CONSTRAINT task_upload_counters_unique UNIQUE(task_id, ord) -); - -- The HPKE public keys (aka configs) and private keys used by a given task. CREATE TABLE task_hpke_keys( id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, -- artificial ID, internal-only diff --git a/db/00000000000002_task_upload_counters.down.sql b/db/00000000000002_task_upload_counters.down.sql new file mode 100644 index 000000000..8ce78e06a --- /dev/null +++ b/db/00000000000002_task_upload_counters.down.sql @@ -0,0 +1 @@ +DROP TABLE task_upload_counters; diff --git a/db/00000000000002_task_upload_counters.up.sql b/db/00000000000002_task_upload_counters.up.sql new file mode 100644 index 000000000..76d0c12d7 --- /dev/null +++ b/db/00000000000002_task_upload_counters.up.sql @@ -0,0 +1,19 @@ +-- Per task report upload counters. +CREATE TABLE task_upload_counters( + id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, -- artificial ID, internal-only + task_id BIGINT NOT NULL, + + interval_collected BIGINT NOT NULL DEFAULT 0, -- Reports submitted for an interval that was already collected. + report_decode_failure BIGINT NOT NULL DEFAULT 0, -- Reports which failed to decode. + report_decrypt_failure BIGINT NOT NULL DEFAULT 0, -- Reports which failed to decrypt. + report_expired BIGINT NOT NULL DEFAULT 0, -- Reports that were older than the task's report_expiry_age. + report_outdated_key BIGINT NOT NULL DEFAULT 0, -- Reports that were encrypted with an unknown or outdated HPKE key. + report_success BIGINT NOT NULL DEFAULT 0, -- Reports that were successfully uploaded. + report_too_early BIGINT NOT NULL DEFAULT 0, -- Reports whose timestamp is too far in the future. + task_expired BIGINT NOT NULL DEFAULT 0, -- Reports sent to the task while it is expired. + + ord BIGINT NOT NULL, -- Index of this task_upload_counters shard. + + CONSTRAINT fk_task_id FOREIGN KEY(task_id) REFERENCES tasks(id) ON DELETE CASCADE, + CONSTRAINT task_upload_counters_unique UNIQUE(task_id, ord) +);