[dev][nova] How to add a column in table of Nova Database

Stephen Finucane stephenfin at redhat.com
Wed May 25 09:32:54 UTC 2022


On Sun, 2022-05-22 at 17:27 +0800, 韩光宇 wrote:
> Hi,
> 
> I'm a beginner in OpenStack development.
> 
> I would like to try modifying by adding a property to the 'Instances'
> database table. But I didn't find description in the documentation of
> the data model mechanism and how to extend the database.
> https://docs.openstack.org/nova/latest/
> 
> Now, I know that it involves versined object model and alembic.
> 
> My question is:
> What is the process of adding a column to a table in the database?
> 
> Could someone show me the process of modifying a database table or
> recommend me the relevant documentation
> 
> Best wishes,
> Han

This is pretty well documented:

https://docs.openstack.org/nova/latest/reference/database-migrations.html

The tl;dr: is a) make your changes to 'nova/db/{main|api}/models.py' then (b)
either auto-generate a schema using alembic's autogeneration functionality or
write one yourself. We have tests in place that will ensure the migrations and
models don't diverge.

You should know that making changes to the database schema will generally
require a spec. You can find information on the purpose of specs and how to
write one here:

https://specs.openstack.org/openstack/nova-specs/readme.html

Be careful not to treat this as a downstream-only thing (i.e. by forking nova).
If you do, you are likely to cause yourself a lot of pain in the future as the
database schema of upstream nova will invariably diverge.

If you have any questions, please ask here or (better) on #openstack-nova on
OFTC IRC.

Hope this helps,
Stephen




More information about the openstack-discuss mailing list