<div dir="ltr">Jay, <div><br></div><div>I should probably share to you about our work around DB.</div><div><br></div><div>Migrations should be run only in production and only for production backends (e.g. psql and mysql) </div>
<div>In tests we should use Schemas created by Models (BASE.metadata.create_all())</div><div><br></div><div>We are not able to use in this approach in moment  because we don't have any mechanism to check that MODELS and SCHEMAS are EQUAL. </div>
<div>And actually MODELS and SCHEMAS are DIFFERENT. </div><div><br></div><div>E.g. in Celiometer we have BP that syncs models and migration <a href="https://blueprints.launchpad.net/ceilometer/+spec/ceilometer-db-sync-models-with-migrations">https://blueprints.launchpad.net/ceilometer/+spec/ceilometer-db-sync-models-with-migrations</a></div>
<div>(in other projects we are doing the same)</div><div><br></div><div>And also we are working around (oslo) generic tests that checks that models and migrations are equal: </div><div><a href="https://review.openstack.org/#/c/42307/">https://review.openstack.org/#/c/42307/</a><br>
</div><div><br></div><div><br></div><div>So in our roadmap (in this case is):</div><div>1) Soft switch to alembic (with code that allows to have sqla-migrate and alembic migration in the same time)</div><div>2) Sync Models and Migrations (fix DB schemas also)</div>
<div>3) Add from oslo generic test that checks all this stuff</div><div>4) Use BASE.create_all() for Schema creation instead of migrations. </div><div><br></div><div><br></div><div>But in OpenStack is not so simple to implement such huge changes, so it take some time=)</div>
<div><br></div><div><br></div><div>Best regards,</div><div>Boris Pavlovic</div><div>---</div><div>Mirantis Inc. </div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 27, 2013 at 12:02 AM, Jay Pipes <span dir="ltr"><<a href="mailto:jaypipes@gmail.com" target="_blank">jaypipes@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 08/26/2013 03:40 PM, Herndon, John Luke (HPCS - Ft. Collins) wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Jay -<br>
<br>
It looks there is an error in the migration script that causes it to abort:<br>
<br>
AttributeError: 'ForeignKeyConstraint' object has no attribute 'drop'<br>
<br>
My guess is the migration runs on the first test, creates event types<br>
table fine, but exits with the above error, so migration is not<br>
"complete". Thus every subsequent test tries to migrate the db, and<br>
notices that event types already exists.<br>
</blockquote>
<br></div>
I'd corrected that particular mistake and pushed an updated migration script.<br>
<br>
Best,<br>
-jay<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-john<br>
<br>
On 8/26/13 1:15 PM, "Jay Pipes" <<a href="mailto:jaypipes@gmail.com" target="_blank">jaypipes@gmail.com</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I just noticed that every single test case for SQL-driver storage is<br>
executing every single migration upgrade before every single test case<br>
run:<br>
<br>
<a href="https://github.com/openstack/ceilometer/blob/master/ceilometer/tests/db.py" target="_blank">https://github.com/openstack/<u></u>ceilometer/blob/master/<u></u>ceilometer/tests/db.py</a><br>
#L46<br>
<br>
<a href="https://github.com/openstack/ceilometer/blob/master/ceilometer/storage/imp" target="_blank">https://github.com/openstack/<u></u>ceilometer/blob/master/<u></u>ceilometer/storage/imp</a><br>
l_sqlalchemy.py#L153<br>
<br>
instead of simply creating a new database schema from the models in the<br>
current source code base using a call to sqlalchemy.MetaData.create_<u></u>all().<br>
<br>
This results in re-running migrations over and over again, instead of<br>
having dedicated migration tests that would test each migration<br>
individually, as is the case in projects like Glance...<br>
<br>
Is this intentional?<br>
<br>
Best,<br>
-jay<br>
<br>
On 08/26/2013 02:59 PM, Sandy Walsh wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm getting the same problem with a different migration (mine is<br>
complaining that a column already exists)<br>
<br>
<a href="http://paste.openstack.org/show/44512/" target="_blank">http://paste.openstack.org/<u></u>show/44512/</a><br>
<br>
I've compared it to the other migrations and it seems fine.<br>
<br>
-S<br>
<br>
On 08/26/2013 02:34 PM, Jay Pipes wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hey all,<br>
<br>
I'm trying to figure out what is going wrong with my code for this<br>
patch:<br>
<br>
<a href="https://review.openstack.org/41316" target="_blank">https://review.openstack.org/<u></u>41316</a><br>
<br>
I had previously added a sqlalchemy-migrate migration script to add an<br>
event_type table, and had that working, but then was asked to instead<br>
use Alembic for migrations. So, I removed the sqlalchemy-migrate<br>
migration file and added an Alembic migration [1].<br>
<br>
Unfortunately, I am getting the following error when running tests:<br>
<br>
OperationalError: (OperationalError) table event_type already exists<br>
u'\nCREATE TABLE event_type (\n\tid INTEGER NOT NULL, \n\t"desc"<br>
VARCHAR(255), \n\tPRIMARY KEY (id), \n\tUNIQUE ("desc")\n)\n\n' ()<br>
<br>
The migration adds the event_type table. I've seen this error occur<br>
before when using SQLite due to SQLite's ALTER TABLE statement not<br>
allowing the rename of a column. In the sqlalchemy-migrate migration, I<br>
had a specialized SQLite migration upgrade [2] and downgrade [3]<br>
script,<br>
but I'm not sure how I am supposed to handle this in Alembic. Could<br>
someone help me out?<br>
<br>
Thanks,<br>
-jay<br>
<br>
[1]<br>
<br>
<a href="https://review.openstack.org/#/c/41316/16/ceilometer/storage/sqlalchemy/" target="_blank">https://review.openstack.org/#<u></u>/c/41316/16/ceilometer/<u></u>storage/sqlalchemy/</a><br>
alembic/versions/49036daaaafd_<u></u>add_event_types.py<br>
<br>
[2]<br>
<br>
<a href="https://review.openstack.org/#/c/41316/14/ceilometer/storage/sqlalchemy/" target="_blank">https://review.openstack.org/#<u></u>/c/41316/14/ceilometer/<u></u>storage/sqlalchemy/</a><br>
migrate_repo/versions/013_<u></u>sqlite_upgrade.sql<br>
<br>
[3]<br>
<br>
<a href="https://review.openstack.org/#/c/41316/14/ceilometer/storage/sqlalchemy/" target="_blank">https://review.openstack.org/#<u></u>/c/41316/14/ceilometer/<u></u>storage/sqlalchemy/</a><br>
migrate_repo/versions/013_<u></u>sqlite_downgrade.sql<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>
</blockquote></blockquote>
<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>
<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>
</blockquote></blockquote>
<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>
</div></div></blockquote></div><br></div>