Skip to content

Conversation

@ashb
Copy link
Member

@ashb ashb commented Apr 15, 2025

hrough some means I haven't been able to uncover, the FKs we end up with
when upgrading a DB from 2.10.5 are duplicated:

        CONSTRAINT ds_dsa_alias_id FOREIGN KEY(alias_id) REFERENCES dataset_alias (id) ON DELETE CASCADE,
        CONSTRAINT ds_dsa_dataset_id FOREIGN KEY(dataset_id) REFERENCES dataset (id) ON DELETE CASCADE,
        CONSTRAINT dataset_alias_dataset_alias_id_fkey FOREIGN KEY(alias_id) REFERENCES dataset_alias (id) ON DELETE CASCADE,
        CONSTRAINT dataset_alias_dataset_dataset_id_fkey FOREIGN KEY(dataset_id) REFERENCES dataset (id) ON DELETE CASCADE

SQLite doesn't even officially have DROP CONSTRAINT, let alone an IF EXISTS modifier on it, but with a little bit of work we can make it work with
the tools Alembic gives us.

Fixes #49296


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@ashb ashb force-pushed the sqlite2-10-to-3-upgrade branch from fae5393 to 63061de Compare April 15, 2025 16:15
@kaxil kaxil added priority:high High priority bug that should be patched quickly but does not require immediate new release affected_version:3.0.0rc labels Apr 15, 2025
Through some means I haven't been able to uncover, the FKs we end up with
when upgrading a DB from 2.10.5 are duplicated:

```
        CONSTRAINT ds_dsa_alias_id FOREIGN KEY(alias_id) REFERENCES dataset_alias (id) ON DELETE CASCADE,
        CONSTRAINT ds_dsa_dataset_id FOREIGN KEY(dataset_id) REFERENCES dataset (id) ON DELETE CASCADE,
        CONSTRAINT dataset_alias_dataset_alias_id_fkey FOREIGN KEY(alias_id) REFERENCES dataset_alias (id) ON DELETE CASCADE,
        CONSTRAINT dataset_alias_dataset_dataset_id_fkey FOREIGN KEY(dataset_id) REFERENCES dataset (id) ON DELETE CASCADE
```

SQLite doesn't even officially have `DROP CONSTRAINT`, let alone an `IF
EXISTS` modifier on it, but with a little bit of work we can make it work with
the tools Alembic gives us.
@ashb ashb force-pushed the sqlite2-10-to-3-upgrade branch from 63061de to 85bf552 Compare April 15, 2025 21:49
@ashb ashb requested review from eladkal, kaxil and sunank200 April 15, 2025 21:49
@ashb
Copy link
Member Author

ashb commented Apr 15, 2025

I've totally re-written this, so I've requested re-reviews

@ashb ashb merged commit 45b106a into apache:main Apr 15, 2025
51 checks passed
@ashb ashb deleted the sqlite2-10-to-3-upgrade branch April 15, 2025 23:05
kaxil pushed a commit that referenced this pull request May 19, 2025
## Why
`airflow db migrate` failed when I migrated an old airflow instance to 2.11.0rc1

## What
Following up #49301 and trying to fix some found issues

* `0093 upgrade, 0100 upgrade, 0060 downgrade, 0064 downgrade`: since SQite does not support constant drop, follow how #49301 deals with fk for SQlite
* `0110`: backport _drop_fkey_if_exists for handling fk in sqlite
* `0142`: Explicitly list down the column names when recreating dag_run table
* `0073`: add a safeguard to ensure we're not wrongly update the name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:db-migrations PRs with DB migration priority:high High priority bug that should be patched quickly but does not require immediate new release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migration breaking from 2.10.5 to 3.0.0 in sqlite

6 participants