<div dir="ltr"><div><div><div>Matt -<br><br></div>Could a test be added that goes through the models and checks these things? Other projects could use this too.<br><br></div>Here's an example of a test that checks if the tables are all InnoDB: <a href="http://git.openstack.org/cgit/openstack/nova/tree/nova/tests/db/test_migrations.py?id=6e455cd97f04bf26bbe022be17c57e089cf502f4#n430">http://git.openstack.org/cgit/openstack/nova/tree/nova/tests/db/test_migrations.py?id=6e455cd97f04bf26bbe022be17c57e089cf502f4#n430</a><br>
</div><div><br></div>- Brant<br><div><br><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Dec 18, 2013 at 11:27 AM, Matt Riedemann <span dir="ltr"><<a href="mailto:mriedem@linux.vnet.ibm.com" target="_blank">mriedem@linux.vnet.ibm.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've seen this come up a few times in reviews and was thinking we should put something in the general review checklist wiki for it [1].<br>

<br>
Basically I have three things I'd like to have in the list for DB migrations:<br>
<br>
1. Unique constraints should be named. Different DB engines and SQLAlchemy dialects automatically name the constraint their own way, which can be troublesome for universal migrations. We should avoid this by enforcing that UCs are named when they are created. This means not using the unique=True arg in UniqueConstraint if the name arg isn't provided.<br>

<br>
2. Foreign keys should be named for the same reasons in #1.<br>
<br>
3. Foreign keys shouldn't be created against nullable columns. Some DB engines don't allow unique constraints over nullable columns and if you can't create the unique constraint you can't create the foreign key, so we should avoid this. If you need the FK, then the pre-req is to make the target column non-nullable. Think of the instances.uuid column in nova for example.<br>

<br>
Unless anyone has a strong objection to this, I'll update the review checklist wiki with these items.<br>
<br>
[1] <a href="https://wiki.openstack.org/wiki/ReviewChecklist" target="_blank">https://wiki.openstack.org/<u></u>wiki/ReviewChecklist</a><span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
<br>
Thanks,<br>
<br>
Matt Riedemann<br>
<br>
<br>
______________________________<u></u>_________________<br>
OpenStack-dev mailing list<br>
<a href="mailto:OpenStack-dev@lists.openstack.org" target="_blank">OpenStack-dev@lists.openstack.<u></u>org</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/<u></u>cgi-bin/mailman/listinfo/<u></u>openstack-dev</a><br>
</font></span></blockquote></div><br></div>