ash-project / ash-project/ash_postgres
mix ash.codegen --check, fails
- Dominant language
- Elixir
- Stars
- 189
- Forks
- 168
- Avg merge
- 13h 1m
- Merged PRs (30d)
- 22
Description
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
### AI Policy
- [x] I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.
### Versions
ash_postgres: 2.11.0
ash: 3.31.3
Elixir: 1.20.1
Erlang/OTP: 28.5.0.2
### Operating system
NixOS, Linux x86_64
### Current Behavior
mix ash.codegen --check raises an internal error when a Resource has multiple removed attributes and multiple added attributes.
In this case, _dev migrations also remain. The command should report the existing _dev migration error. It instead crashes before it reaches that check:
```text
** (RuntimeError) Could not get matching name after 3 attempts.
```
Relevant call stack:
```text
Mix.Tasks.Ash.Codegen.run/1
AshPostgres.DataLayer.codegen/1
Mix.Tasks.AshPostgres.GenerateMigrations.run/1
AshPostgres.MigrationGenerator.generate/2
create_migrations/5
fetch_operations/2
do_fetch_operations/5
attribute_operations/4
resolve_renames/4
renaming?/3
yes?/2
get_new_attribute/3
prompt/2
```
In --check mode, yes?/2 returns true, while prompt/2 returns "response".
The generator therefore confirms that a removed attribute is a rename, but then cannot find an added attribute named "response". It retries three times and raises.
The _dev migration check occurs after operation and rename inference, so the command never reaches this intended message:
```text
Codegen check failed.
You have migrations remaining that were generated with the --dev flag.
Run `mix ash.codegen ` to remove the dev migrations and replace them
with production-ready migrations.
### Reproduction
1. Create a Resource with these persisted attributes:
```text
old_a
old_b
old_c
old_d
```
2. Generate a production-ready migration and snapshot:
```bash
mix ash.codegen initial_attributes
mix ash.migrate
```
3. Replace those attributes with:
```text
new_a
new_b
```
4. Generate development codegen:
```bash
mix ash.codegen --dev
mix ash.migrate
```
5. Run the automated check:
```bash
mix ash.codegen --check
```
The command deterministically raises:
```text
Could not get matching name after 3 attempts.
```
The relevant state is:
```text
attributes_to_remove = [old_a, old_b, old_c, old_d]
attributes_to_add = [new_a, new_b]
check = true
dev = false
```
### Expected Behavior
- When _dev migrations remain, it should report the existing _dev migration message.
- For ambiguous changes without _dev migrations, it should report pending codegen without inventing a rename.
Contributor guide
Research direction
Start with Mix.Tasks.Ash.Codegen.run/1 and follow the reported path through AshPostgres.MigrationGenerator.generate/2, especially attribute_operations/4 and resolve_renames/4. Reproduce the issue with the listed attribute changes and mix ash.codegen --check. Done means remaining --dev migrations produce the existing check message, while ambiguous changes without them report pending codegen instead of inventing a rename.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100