kaaveland / eugene

Careful With that Lock, Eugene
MIT License
32 stars 1 forks source link

Recognize patterns where better solutions exist #9

Closed kaaveland closed 7 months ago

kaaveland commented 7 months ago

The documentation for https://github.com/ankane/strong_migrations is awesome and it might be possible to recognize a bunch of the same things, either by parsing the sql with a proper parser, or by inspecting the locks and potentially generate some recommendations or "fixing up" the migration programmatically.

kaaveland commented 7 months ago

It seems like the easiest way to do this is to snapshot queries against pg_attribute and pg_constraint, similarly to how we snapshot pg_class. We'd want to track:

This should let us match against these patterns from the strong migrations documentation:

kaaveland commented 7 months ago

type_change_requires_table_rewrite needs to be fixed to actually understand what type changes that forces a rewrite.

kaaveland commented 7 months ago

We should definitely make it possible to "fail the trace" if we find some of these patterns, because at that point, we know of better ways to do the migration.

kaaveland commented 7 months ago

We need to track indexes too, so we can recommend to add them concurrently. There's also a nice hint we could give if people add a unique constraint, where it's safer if they create a unique index concurrently.

kaaveland commented 7 months ago

Altering a check constraint body is probably often not safe. 🤔

kaaveland commented 7 months ago

32 brings us up to 8 patterns/rules, which is enough for me to close this one.