Fuel UI
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fuel_10_0.py 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. # Copyright 2016 Mirantis, Inc.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. # not use this file except in compliance with the License. You may obtain
  5. # a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  11. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  12. # License for the specific language governing permissions and limitations
  13. # under the License.
  14. """Fuel 10.0
  15. Revision ID: c6edea552f1e
  16. Revises: 675105097a69
  17. Create Date: 2016-04-08 15:20:43.989472
  18. """
  19. from alembic import op
  20. from nailgun.db.sqlalchemy.models import fields
  21. from nailgun.utils.migration import upgrade_enum
  22. from oslo_serialization import jsonutils
  23. import sqlalchemy as sa
  24. # revision identifiers, used by Alembic.
  25. revision = 'c6edea552f1e'
  26. down_revision = '3763c404ca48'
  27. cluster_changes_old = (
  28. 'networks',
  29. 'attributes',
  30. 'disks',
  31. 'interfaces',
  32. 'vmware_attributes'
  33. )
  34. cluster_changes_new = (
  35. 'networks',
  36. 'attributes',
  37. 'disks',
  38. 'interfaces',
  39. )
  40. def upgrade():
  41. upgrade_plugin_links_constraints()
  42. upgrade_release_required_component_types()
  43. upgrade_remove_vmware()
  44. def downgrade():
  45. downgrade_remove_vmware()
  46. downgrade_release_required_component_types()
  47. downgrade_plugin_links_constraints()
  48. def upgrade_plugin_links_constraints():
  49. connection = op.get_bind()
  50. # plugin links
  51. plugin_links_remove_duplicates_query = sa.text("""
  52. DELETE FROM plugin_links
  53. WHERE id
  54. NOT IN (
  55. SELECT MIN(id)
  56. FROM plugin_links
  57. GROUP BY url
  58. )
  59. """)
  60. connection.execute(plugin_links_remove_duplicates_query)
  61. op.create_unique_constraint(
  62. 'plugin_links_url_uc',
  63. 'plugin_links',
  64. ['url'])
  65. # cluster plugin links
  66. cluster_plugin_links_remove_duplicates_query = sa.text("""
  67. DELETE FROM cluster_plugin_links
  68. WHERE id
  69. NOT IN (
  70. SELECT MIN(id)
  71. FROM cluster_plugin_links
  72. GROUP BY cluster_id,url
  73. )
  74. """)
  75. connection.execute(cluster_plugin_links_remove_duplicates_query)
  76. op.create_unique_constraint(
  77. 'cluster_plugin_links_cluster_id_url_uc',
  78. 'cluster_plugin_links',
  79. ['cluster_id', 'url'])
  80. def downgrade_plugin_links_constraints():
  81. op.drop_constraint('cluster_plugin_links_cluster_id_url_uc',
  82. 'cluster_plugin_links')
  83. op.drop_constraint('plugin_links_url_uc', 'plugin_links')
  84. def upgrade_release_required_component_types():
  85. op.add_column(
  86. 'releases',
  87. sa.Column(
  88. 'required_component_types',
  89. fields.JSON(),
  90. nullable=False,
  91. server_default='[]'
  92. )
  93. )
  94. connection = op.get_bind()
  95. connection.execute(
  96. sa.sql.text(
  97. "UPDATE releases SET required_component_types = :required_types"),
  98. required_types=jsonutils.dumps(['hypervisor', 'network', 'storage'])
  99. )
  100. def downgrade_release_required_component_types():
  101. op.drop_column('releases', 'required_component_types')
  102. def upgrade_remove_vmware():
  103. connection = op.get_bind()
  104. op.drop_constraint(
  105. 'vmware_attributes_cluster_id_fkey',
  106. 'vmware_attributes',
  107. type_='foreignkey'
  108. )
  109. op.drop_table('vmware_attributes')
  110. op.drop_column('releases', 'vmware_attributes_metadata')
  111. delete = sa.sql.text(
  112. """DELETE FROM cluster_changes
  113. WHERE name = 'vmware_attributes'""")
  114. connection.execute(delete)
  115. upgrade_enum(
  116. "cluster_changes", # table
  117. "name", # column
  118. "possible_changes", # ENUM name
  119. cluster_changes_old, # old options
  120. cluster_changes_new # new options
  121. )
  122. def downgrade_remove_vmware():
  123. op.add_column(
  124. 'releases',
  125. sa.Column('vmware_attributes_metadata', fields.JSON(), nullable=True))
  126. op.create_table(
  127. 'vmware_attributes',
  128. sa.Column('id', sa.Integer(), nullable=False),
  129. sa.Column('cluster_id', sa.Integer()),
  130. sa.Column('editable', fields.JSON()),
  131. sa.ForeignKeyConstraint(['cluster_id'], ['clusters.id'], ),
  132. sa.PrimaryKeyConstraint('id'))
  133. upgrade_enum(
  134. "cluster_changes", # table
  135. "name", # column
  136. "possible_changes", # ENUM name
  137. cluster_changes_new, # new options
  138. cluster_changes_old # old options
  139. )
  140. op.drop_constraint(
  141. 'vmware_attributes_cluster_id_fkey',
  142. 'vmware_attributes',
  143. type_='foreignkey'
  144. )
  145. op.create_foreign_key(
  146. 'vmware_attributes_cluster_id_fkey',
  147. 'vmware_attributes', 'clusters',
  148. ['cluster_id'], ['id'],
  149. ondelete='CASCADE'
  150. )