diff --git a/backend/src/main/resources/db/migration/V69__import_precision_attribution_identity_schema.sql b/backend/src/main/resources/db/migration/V69__import_precision_attribution_identity_schema.sql index 1c621656..bec01873 100644 --- a/backend/src/main/resources/db/migration/V69__import_precision_attribution_identity_schema.sql +++ b/backend/src/main/resources/db/migration/V69__import_precision_attribution_identity_schema.sql @@ -24,9 +24,12 @@ ALTER TABLE documents ADD CONSTRAINT chk_meta_date_raw_length CHECK (length(meta ALTER TABLE documents ADD CONSTRAINT chk_sender_text_length CHECK (length(sender_text) <= 10000); ALTER TABLE documents ADD CONSTRAINT chk_receiver_text_length CHECK (length(receiver_text) <= 10000); --- Precision enum — added nullable, backfilled, then made NOT NULL (in this order so the --- backfill can populate existing rows before the constraint is enforced). -ALTER TABLE documents ADD COLUMN meta_date_precision varchar(16); +-- Precision enum — added with a DB default of 'UNKNOWN', backfilled, then made NOT NULL. +-- The DEFAULT serves two purposes: (1) existing rows get 'UNKNOWN' immediately, and +-- (2) raw-SQL inserts that omit the column (test fixtures, ad-hoc data loads) get a sane, +-- CHECK-valid value instead of violating the NOT NULL constraint. JPA saves still set it +-- explicitly via the entity's @Builder.Default = DatePrecision.UNKNOWN. +ALTER TABLE documents ADD COLUMN meta_date_precision varchar(16) DEFAULT 'UNKNOWN'; UPDATE documents SET meta_date_precision = CASE WHEN meta_date IS NOT NULL THEN 'DAY' ELSE 'UNKNOWN' END;