<div dir="ltr"><div dir="ltr" class="gmail_msg">Henry, thanks for taking care of this!<br class="gmail_msg"><br class="gmail_msg">In my opinion, it is just safe to use raw values in migration, because migration is a strict point in time.<br><br>I remember how many patches I send in havana in Neutron for fixing synchronization issues. Usage constants everywhere can be good in this case, but ModelMigrationSyc did such check of this for us already.<br><br>If we want to have constants everywhere, we should guarantee that they are unchanged - have test in neutron-lib which verifies their values. <br><br></div><div class="gmail_msg"><br></div><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Sat, Oct 15, 2016 at 10:41 PM Henry Gessau <<a href="mailto:HenryG@gessau.net" class="gmail_msg" target="_blank">HenryG@gessau.net</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi neutrinos,<br class="gmail_msg">
<br class="gmail_msg">
In Neutron many attributes are stored in database fields. The size of these<br class="gmail_msg">
fields therefore determines the maximum length of the attribute values.<br class="gmail_msg">
<br class="gmail_msg">
I would like to get some consistency in place around how we define the<br class="gmail_msg">
constants and where they are used. Here are my thoughts...<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
1. Raw sizes in alembic migrations<br class="gmail_msg">
<br class="gmail_msg">
In the alembic migrations which build the DB schema, we should use the raw<br class="gmail_msg">
number value of the field size.<br class="gmail_msg">
<br class="gmail_msg">
2. FOO_FIELD_SIZE in the sqlalchemy models<br class="gmail_msg">
<br class="gmail_msg">
In the sqlalchemy models, we should use the <field>_FIELD_SIZE constants<br class="gmail_msg">
defined in neutron_lib/db/constants.py<br class="gmail_msg">
<br class="gmail_msg">
3. Everywhere else, use FOO_FIELD_SIZE, or another constant (like FOO_MAX_LEN)<br class="gmail_msg">
based on FOO_FIELD_SIZE.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
"Why raw numbers in alembic migrations?", you may ask. Well, we have tests<br class="gmail_msg">
that verify that the models match the schema generated by migrations. If both<br class="gmail_msg">
the models and the migrations use the constants then the tests would not<br class="gmail_msg">
detect if a patch changes the constant value.<br class="gmail_msg">
<br class="gmail_msg">
By using raw numbers in migrations, together with our rule of not allowing<br class="gmail_msg">
changes to existing migrations, we allow the tests to detect and fail on any<br class="gmail_msg">
attempt to alter a FIELD_SIZE constant.<br class="gmail_msg">
<br class="gmail_msg">
Let me know if this makes sense or if you think it's a terrible idea.<br class="gmail_msg">
<br class="gmail_msg">
If there are no objections, I intend to submit a patch or patches to:<br class="gmail_msg">
 - replace constants with numbers in existing migrations<br class="gmail_msg">
 - ensure all models use the appropriate constants<br class="gmail_msg">
<br class="gmail_msg">
Existing code uses FOO_MAX_LEN in a lot of places. In most of these places it<br class="gmail_msg">
would make sense to simply switch to using FOO_FIELD_SIZE. However, some code<br class="gmail_msg">
may be quite far removed from the DB and would look better by sticking to<br class="gmail_msg">
FOO_MAX_LEN. I added item 3. above to allow for that.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
__________________________________________________________________________<br class="gmail_msg">
OpenStack Development Mailing List (not for usage questions)<br class="gmail_msg">
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" rel="noreferrer" class="gmail_msg" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br class="gmail_msg">
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br class="gmail_msg">
</blockquote></div></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr">Regards,<br>Ann Taraday</div></div>