Columns must not carry DEFAULT clauses. The DEFAULT only backfills existing rows when the non-nullable column is added, so drop it in the same migration; inserts already supply enrichment_attempts explicitly. Signed-off-by: Émile Ré <emile@probo.com>
36 lines
1.4 KiB
SQL
36 lines
1.4 KiB
SQL
-- Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
|
--
|
|
-- Permission to use, copy, modify, and/or distribute this software for any
|
|
-- purpose with or without fee is hereby granted, provided that the above
|
|
-- copyright notice and this permission notice appear in all copies.
|
|
--
|
|
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
-- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
-- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
-- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
-- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
-- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
-- PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
ALTER TABLE
|
|
common_third_parties
|
|
ADD
|
|
COLUMN enrichment_requested_at TIMESTAMP WITH TIME ZONE,
|
|
ADD
|
|
COLUMN enrichment JSONB,
|
|
ADD
|
|
COLUMN enrichment_attempts INTEGER NOT NULL DEFAULT 0;
|
|
|
|
-- The DEFAULT only backfills existing rows; drop it so inserts must
|
|
-- supply the value explicitly.
|
|
ALTER TABLE
|
|
common_third_parties
|
|
ALTER COLUMN
|
|
enrichment_attempts DROP DEFAULT;
|
|
|
|
-- Partial index backs the enrichment worker's claim query, which polls
|
|
-- only rows currently queued for enrichment.
|
|
CREATE INDEX common_third_parties_enrichment_requested_at_idx
|
|
ON common_third_parties (enrichment_requested_at)
|
|
WHERE enrichment_requested_at IS NOT NULL;
|