feat(schema): one migration + domain model for import/precision/identity (Phase 2, #671) #673
@@ -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_sender_text_length CHECK (length(sender_text) <= 10000);
|
||||||
ALTER TABLE documents ADD CONSTRAINT chk_receiver_text_length CHECK (length(receiver_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
|
-- Precision enum — added with a DB default of 'UNKNOWN', backfilled, then made NOT NULL.
|
||||||
-- backfill can populate existing rows before the constraint is enforced).
|
-- The DEFAULT serves two purposes: (1) existing rows get 'UNKNOWN' immediately, and
|
||||||
ALTER TABLE documents ADD COLUMN meta_date_precision varchar(16);
|
-- (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
|
UPDATE documents
|
||||||
SET meta_date_precision = CASE WHEN meta_date IS NOT NULL THEN 'DAY' ELSE 'UNKNOWN' END;
|
SET meta_date_precision = CASE WHEN meta_date IS NOT NULL THEN 'DAY' ELSE 'UNKNOWN' END;
|
||||||
|
|||||||
Reference in New Issue
Block a user