Skip to content

Commit be13377

Browse files
committed
fix(db): Resolve the execution table through search_path in the revision guard
The guard added in #924 tested information_schema against current_schema(), which is only the first entry in search_path. On a connection whose search_path puts another schema first, an execution table in a later schema makes the predicate false while the unqualified ALTER below it resolves to that same later table, so the widening is skipped without a word and execution.revision silently stays integer. Resolve the relation with to_regclass and read its type from pg_attribute, so the guard and the ALTER always agree on which table they are talking about. to_regclass returns NULL when no execution table is reachable at all, which leaves the guard false as before. Reported by the cubic review bot on #924, after that PR had merged. Signed-off-by: Prasanth Baskar <prasanth@8gears.com>
1 parent 48e574d commit be13377

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

make/migrations/postgresql/harbor_next.sql

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,19 @@ WHERE m.id = ranked.id AND m.rank <> ranked.rn;
138138
-- Guarded on the current type so repeat runs never rewrite the table.
139139
DO $$
140140
BEGIN
141+
-- Resolve the schema from the same relation the unqualified ALTER below
142+
-- resolves to. current_schema() is only the first entry in search_path, so
143+
-- it would miss an execution table living in a later one and skip the
144+
-- widening without a word. to_regclass returns NULL when there is no
145+
-- execution table at all, which leaves the guard false, as it should.
141146
IF EXISTS (
142147
SELECT 1
143-
FROM information_schema.columns
144-
WHERE table_schema = current_schema()
145-
AND table_name = 'execution'
146-
AND column_name = 'revision'
147-
AND data_type <> 'bigint'
148+
FROM pg_attribute a
149+
WHERE a.attrelid = to_regclass('execution')
150+
AND a.attname = 'revision'
151+
AND a.attnum > 0
152+
AND NOT a.attisdropped
153+
AND a.atttypid <> 'bigint'::regtype
148154
) THEN
149155
ALTER TABLE execution ALTER COLUMN revision TYPE bigint;
150156
END IF;

0 commit comments

Comments
 (0)