lablup / lablup/backend.ai

sessionresult coexistence downgrade fails: column default blocks the enum type change

Open
#12,911 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
17h 7m
Merged PRs (30d)
358

Description

## Objective

Make the downgrade of 0b1efbb2db84 (fix sessionresult enum type coexistence) drop the column default before changing the column type, so it stops aborting the downgrade chain.

## Background

The downgrade recreates the plural sessionresults type and then runs ALTER TABLE sessions ALTER COLUMN result TYPE sessionresults USING result::text::sessionresults. sessions.result carries a default, and PostgreSQL cannot cast an existing default across two unrelated enum types, so the statement aborts with DatatypeMismatchError: default for column result cannot be cast automatically to type sessionresults (SQLSTATE 42804).

The migration guards its DDL with a try/except that tolerates a list of expected divergence SQLSTATEs, but 42804 is not among them, so the error is reraised and the whole downgrade chain stops here.

The correct sequence already exists in this repository. dec0deba5893 does the same kind of conversion via _convert_to_sessionresult, which calls _drop_column_default, then _alter_column_to_sessionresult, then _set_column_default_undefined_sessionresult – and it succeeds. 0b1efbb2db84 simply omits the default handling.

Reproduced on a database built at head by mgr schema oneshot and downgraded with no skipped revisions: 150 downgrade steps run cleanly, then dec0deba5893's downgrade recreates the singular sessionresult type and converts sessions.result to it, and the next crossing of 0b1efbb2db84 takes the has_singular and not has_plural branch and aborts. Confirmed by hand that DROP DEFAULT, then ALTER COLUMN TYPE, then SET DEFAULT completes and leaves result as sessionresults with default 'UNDEFINED'::sessionresults.

The upgrade path has the same shape – it runs ALTER TABLE sessions ALTER COLUMN result TYPE sessionresult on databases where both types coexist, with no default handling – so it is worth fixing symmetrically.

Related: BA-6899, BA-6913, and BA-6914 are earlier walls found on the same downgrade survey.

## Acceptance Criteria

- Downgrading across 0b1efbb2db84 completes when sessions.result carries a default.
- The default is restored after the type change, not silently dropped.
- The upgrade path handles the default the same way.
- Verified against a local DB, not only by static reading.
- pants fmt / lint / check pass.

JIRA Issue: BA-6915

Contributor guide

Open the contributing guide

Research direction

Locate revisions 0b1efbb2db84 and dec0deba5893, then compare the upgrade and downgrade paths with _convert_to_sessionresult, _drop_column_default, and _set_column_default_undefined_sessionresult. Reproduce with `mgr schema oneshot` and a full downgrade, then verify both directions preserve the default and run `pants fmt / lint / check`.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.