扩展neutron的数据库

来源:互联网 发布:ubuntu caffe 编辑:程序博客网 时间:2024/06/07 22:23
neutron添加数据库中的表:

1.先运行:
    neutron-db-manage --config-file /etc/neutron/neutron.conf --config-file alembic_migrations/alembic.ini revision -m 'add test_table' --expand

2.上述命令运行完后,会在expand目录下生成数据新的版本文件,如下:
    neutron/db/migration/alembic_migrations/versions/newton/expand/86e5afb09760_add_test_table.py

修改新生成的文件,修改upgrade函数,添加要加入的表
    op.create_table(
        'test_table',
        sa.Column('id', sa.String(length=255), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=True),
        sa.Column('address', sa.String(length=64), nullable=True),
        sa.Column('tunnel_type', sa.String(length=32), nullable=True),
        sa.Column('description', sa.String(length=255), nullable=True),
        sa.Column('status', sa.String(length=16), nullable=True),
        sa.PrimaryKeyConstraint('id'))

3.保存退出后再运行:
    neutron-db-manage upgrade –expand

4.然后检查neutron数据库是否多了test_table表。

说明:neutron数据库是有版本的,每次对表进行增删改查就会生成一个版本,版本信息会存在数据库里,所以如果涉及到回滚,只回滚到以前的代码是不行的,数据库也要回滚。

数据库中表的信息如下:




0 0
原创粉丝点击