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.

ReplaceIndexInProjectBranches.java 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.platform.db.migration.version.v71;
  21. import java.sql.SQLException;
  22. import org.sonar.db.Database;
  23. import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
  24. import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
  25. import org.sonar.server.platform.db.migration.sql.DropIndexBuilder;
  26. import org.sonar.server.platform.db.migration.step.DdlChange;
  27. public class ReplaceIndexInProjectBranches extends DdlChange {
  28. static final String TABLE_NAME = "project_branches";
  29. private static final String OLD_INDEX_NAME = "project_branches_kee";
  30. static final String NEW_INDEX_NAME = "project_branches_kee_key_type";
  31. static final VarcharColumnDef PROJECT_UUID_COLUMN = VarcharColumnDef.newVarcharColumnDefBuilder()
  32. .setColumnName("project_uuid")
  33. .setIsNullable(false)
  34. .setLimit(50)
  35. .build();
  36. static final VarcharColumnDef KEE_COLUMN = VarcharColumnDef.newVarcharColumnDefBuilder()
  37. .setColumnName("kee")
  38. .setIsNullable(false)
  39. .setLimit(255)
  40. .build();
  41. static final VarcharColumnDef KEY_TYPE_COLUMN = VarcharColumnDef.newVarcharColumnDefBuilder()
  42. .setColumnName("key_type")
  43. .setIsNullable(false)
  44. .setLimit(12)
  45. .build();
  46. public ReplaceIndexInProjectBranches(Database db) {
  47. super(db);
  48. }
  49. @Override
  50. public void execute(Context context) throws SQLException {
  51. context.execute(new DropIndexBuilder(getDialect())
  52. .setTable(TABLE_NAME)
  53. .setName(OLD_INDEX_NAME)
  54. .build());
  55. context.execute(new CreateIndexBuilder(getDialect())
  56. .addColumn(PROJECT_UUID_COLUMN)
  57. .addColumn(KEE_COLUMN)
  58. .addColumn(KEY_TYPE_COLUMN)
  59. .setUnique(true)
  60. .setTable(TABLE_NAME)
  61. .setName(NEW_INDEX_NAME)
  62. .build()
  63. );
  64. }
  65. }