Opt-in table rebuilds in generated migrations instead of failing `ALTER TABLE`

Open
#239 2 comments 0 reactions 0 assignees View on GitHub

@a-nassim is already working on this.

Since Oct 10, 2026.

  • #241 by @a-nassim — open

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
elixir, sqlite
Domain
databases, tooling

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

enhancement
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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Similar issues

More Elixir issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.