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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 oslo_serialization import jsonutils
  21. import sqlalchemy as sa
  22. from nailgun.db.sqlalchemy.models import fields
  23. # revision identifiers, used by Alembic.
  24. revision = 'c6edea552f1e'
  25. down_revision = '3763c404ca48'
  26. def upgrade():
  27. upgrade_plugin_links_constraints()
  28. upgrade_release_required_component_types()
  29. def downgrade():
  30. downgrade_release_required_component_types()
  31. downgrade_plugin_links_constraints()
  32. def upgrade_plugin_links_constraints():
  33. connection = op.get_bind()
  34. # plugin links
  35. plugin_links_remove_duplicates_query = sa.text("""
  36. DELETE FROM plugin_links
  37. WHERE id
  38. NOT IN (
  39. SELECT MIN(id)
  40. FROM plugin_links
  41. GROUP BY url
  42. )
  43. """)
  44. connection.execute(plugin_links_remove_duplicates_query)
  45. op.create_unique_constraint(
  46. 'plugin_links_url_uc',
  47. 'plugin_links',
  48. ['url'])
  49. # cluster plugin links
  50. cluster_plugin_links_remove_duplicates_query = sa.text("""
  51. DELETE FROM cluster_plugin_links
  52. WHERE id
  53. NOT IN (
  54. SELECT MIN(id)
  55. FROM cluster_plugin_links
  56. GROUP BY cluster_id,url
  57. )
  58. """)
  59. connection.execute(cluster_plugin_links_remove_duplicates_query)
  60. op.create_unique_constraint(
  61. 'cluster_plugin_links_cluster_id_url_uc',
  62. 'cluster_plugin_links',
  63. ['cluster_id', 'url'])
  64. def downgrade_plugin_links_constraints():
  65. op.drop_constraint('cluster_plugin_links_cluster_id_url_uc',
  66. 'cluster_plugin_links')
  67. op.drop_constraint('plugin_links_url_uc', 'plugin_links')
  68. def upgrade_release_required_component_types():
  69. op.add_column(
  70. 'releases',
  71. sa.Column(
  72. 'required_component_types',
  73. fields.JSON(),
  74. nullable=False,
  75. server_default='[]'
  76. )
  77. )
  78. connection = op.get_bind()
  79. connection.execute(
  80. sa.sql.text(
  81. "UPDATE releases SET required_component_types = :required_types"),
  82. required_types=jsonutils.dumps(['hypervisor', 'network', 'storage'])
  83. )
  84. def downgrade_release_required_component_types():
  85. op.drop_column('releases', 'required_component_types')