Opt-in table rebuilds in generated migrations instead of failing `ALTER TABLE`
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
Start from the migration generator in ash_sqlite that emits ALTER TABLE statements; the linked commit ccdc18861a8e32b15bff9589dffcbf1867c6857a shows the failing case (dropping a foreign key). Read the linked SQLite 12-step rebuild procedure and the issue's single comment for any maintainer direction before choosing the Django-style (from snapshot) vs Rails-style (from live table) approach. Done looks like a --rebuild-tables flag that, only when passed, emits the rebuild_table block with the trigger comment as shown, while default generated output is unchanged.
Written by the indexing model from the issue text.
Description
Code of Conduct
- I agree to follow this project's Code of Conduct
AI Policy
- I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.
Is your feature request related to a problem? Please describe.
Some operations like dropping a foreign key constraint are not supported by sqlite https://github.com/ash-project/ash_sqlite/commit/ccdc18861a8e32b15bff9589dffcbf1867c6857a
We need to handle such operations manually
Describe the solution you'd like
Opt-in (e.g. --rebuild-tables, like --drop-columns): when a table needs a change not supported by sqlite, recreate the table and move the data in the generated migration, following sqlite documented procedure. Default behaviour would not change.
The migration could show the new table shape with a comment saying what triggered the rebuild:
def up do
...
# SQLite cannot change `comments` in place, so it is rebuilt from the resource's
# snapshot. Anything on the table that the resource does not describe (a column,
# index or trigger added by hand) is not kept. Changes:
# - dropping the foreign key comments_post_id_fkey
rebuild_table :comments do
add :id, :uuid, null: false, primary_key: true
add :post_id, :uuid
end
...
end
Describe alternatives you've considered
Saw two main approaches:
- Django: rebuilding from the model definition (simpler probably)
- Rails: rebuilding from the live table
Native ALTER: SQLite 3.53 has improved support but not for foreign keys
Also doing it manually since automating it is a headache from what I could see 😅
Would that be something you would consider in this project?
Additional context
No response
- Dominant language
- Elixir
- Stars
- 32
- Forks
- 37
- Avg merge
- 6h 40m
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Similar issues
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenextPossibly taken @Huyvux12 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
software-mansion/popcorn#929 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
ash-project/ash#3127 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
intellij-elixir/intellij-elixir#4705 ·
Maintainers usually reply within 1 day
-
Bug: Table layout and date column are cut off on mobile screens on the Tournaments -> History pageOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
hexlet-codebattle/codebattle#2375 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wintermeyer/vutuv#2388 ·
Maintainers usually reply within 1 day