I'm working with a legacy database that never had any FOREIGN KEY
s defined and not very many NOT NULL
constraints, even where they are obviously applicable. I've been manually adding these in where the migrations are cheap and the applicability is obvious.
However, I'd really like a systematic way to identify some appropriate targets instead of stumbling around.
I'm wondering if it's possible to write a query (as slow as it might be) to run on a snapshot of the database that would identify every table.column
which is not NOT NULL
but which doesn't have any (or perhaps has very few NULL
s.
I saw https://stackoverflow.com/a/17688833/56690 which is kind of the inverse problem but I am not really familiar enough with this kind of meta-SQL to know how reasonable it is to accomplish what I'm hoping.