Commit 30261f9
committed
refactor(delta): simplify after multi-agent review pass
Net: 77 fewer lines, same behavior, same tests green.
Code reuse
----------
* `Reducer.add_to_coll/5`, `remove_from_coll/4`, `replace_in_coll/5` —
collapse 14 near-duplicate Add/Remove/Alter/Rename apply_op clauses
into uniform one-liners. Each helper accepts a thunk for the error
message so inspect-heavy strings only build on the failure path.
* `MigrationGenerator.snapshot_filename?/2` and
`dev_snapshot_filename?/1` — single source of truth for the
`YYYYMMDDHHMMSS[_dev].json` convention. Previously defined inline
in 5 places (2× squash, 1× migrate_snapshots, 2× migration_generator).
* `ash_postgres.squash_snapshots.ex apply_squash(..., :delta)` — drop
the `maybe_hydrate_context/2` helper. `Reducer.apply_op(CreateTable)`
already sets table/schema/multitenancy/repo/create_table_options, so
the hand-hydration was both redundant and less complete than what
the Reducer does.
* `Codec.decode_atom/1` — subsumes the identical
`decode_optional_atom/1`.
Quality / efficiency
--------------------
* `Reducer`: drop the dead `state_empty?/1` final-override pass on
`load_reduced_state/2`. Inline `empty?` writes already track
correctness for every consumer of the returned state
(`pkey_operations/4`).
* `Reducer.list_delta_files/2`: replace the 3-syscall
`File.exists?`/`File.dir?`/`File.ls!` dance with a single
`File.ls/1` pattern match. Also closes the TOCTOU gap.
* `ash_postgres.migrate_snapshots.ex find_legacy_directories/1`:
return pre-classified `{dir, all_files, legacy_files}` tuples so
`migrate_directory/5` doesn't re-read every file via `v2?/1`. Each
file is now read exactly once during discovery.
* `migration_generator.ex move_rename_snapshots/3`: drop the
`File.exists?(old_dir)` + `File.exists?(dst)` guards in favor of a
single `File.ls/1`. Rename detection guarantees `new_dir` is empty,
so the per-file guard was a defensive no-op.1 parent ae1f9be commit 30261f9
5 files changed
Lines changed: 218 additions & 295 deletions
File tree
- lib
- migration_generator
- operation
- mix/tasks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
204 | 226 | | |
205 | 227 | | |
206 | 228 | | |
| |||
3252 | 3274 | | |
3253 | 3275 | | |
3254 | 3276 | | |
3255 | | - | |
3256 | | - | |
3257 | | - | |
3258 | | - | |
| 3277 | + | |
3259 | 3278 | | |
3260 | 3279 | | |
3261 | 3280 | | |
| |||
3306 | 3325 | | |
3307 | 3326 | | |
3308 | 3327 | | |
3309 | | - | |
3310 | | - | |
3311 | | - | |
3312 | | - | |
3313 | | - | |
| 3328 | + | |
| 3329 | + | |
| 3330 | + | |
3314 | 3331 | | |
3315 | 3332 | | |
3316 | 3333 | | |
| |||
3683 | 3700 | | |
3684 | 3701 | | |
3685 | 3702 | | |
3686 | | - | |
3687 | | - | |
3688 | | - | |
3689 | | - | |
3690 | | - | |
3691 | | - | |
3692 | | - | |
3693 | | - | |
3694 | | - | |
3695 | | - | |
3696 | | - | |
3697 | | - | |
3698 | | - | |
3699 | | - | |
3700 | | - | |
3701 | | - | |
3702 | | - | |
3703 | | - | |
3704 | | - | |
3705 | | - | |
3706 | | - | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
| 3710 | + | |
| 3711 | + | |
| 3712 | + | |
| 3713 | + | |
| 3714 | + | |
| 3715 | + | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
3707 | 3719 | | |
3708 | 3720 | | |
3709 | 3721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
935 | 935 | | |
936 | 936 | | |
937 | 937 | | |
938 | | - | |
939 | | - | |
| 938 | + | |
| 939 | + | |
940 | 940 | | |
941 | 941 | | |
942 | 942 | | |
943 | 943 | | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | 944 | | |
948 | 945 | | |
949 | 946 | | |
| |||
0 commit comments