From aab5144691386b4ca260815daf5d5d4677b80b6a Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Mon, 2 Oct 2023 15:00:04 +0200 Subject: [PATCH] SONAR-20630 Add column creation_method in projects table --- server/sonar-db-dao/src/schema/schema-sq.ddl | 3 +- ...ddCreationMethodColumnInProjectsTable.java | 53 +++++++++++++ .../migration/version/v103/DbVersion103.java | 7 +- ...tionMethodColumnInProjectsNotNullable.java | 46 +++++++++++ ...teCreationMethodColumnInProjectsTable.java | 42 ++++++++++ ...eationMethodColumnInProjectsTableTest.java | 51 +++++++++++++ ...MethodColumnInProjectsNotNullableTest.java | 51 +++++++++++++ ...eationMethodColumnInProjectsTableTest.java | 76 +++++++++++++++++++ .../schema.sql | 15 ++++ .../schema.sql | 16 ++++ .../schema.sql | 16 ++++ 11 files changed, 374 insertions(+), 2 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullable.java create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTable.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest/schema.sql create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest/schema.sql diff --git a/server/sonar-db-dao/src/schema/schema-sq.ddl b/server/sonar-db-dao/src/schema/schema-sq.ddl index 3c513e7c904..ad95d37ad35 100644 --- a/server/sonar-db-dao/src/schema/schema-sq.ddl +++ b/server/sonar-db-dao/src/schema/schema-sq.ddl @@ -755,7 +755,8 @@ CREATE TABLE "PROJECTS"( "TAGS" CHARACTER VARYING(500), "CREATED_AT" BIGINT, "UPDATED_AT" BIGINT NOT NULL, - "NCLOC" BIGINT + "NCLOC" BIGINT, + "CREATION_METHOD" CHARACTER VARYING(50) NOT NULL ); ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID"); CREATE UNIQUE NULLS DISTINCT INDEX "UNIQ_PROJECTS_KEE" ON "PROJECTS"("KEE" NULLS FIRST); diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTable.java new file mode 100644 index 00000000000..94a45b3a062 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTable.java @@ -0,0 +1,53 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v103; + +import java.sql.Connection; +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.db.DatabaseUtils; +import org.sonar.server.platform.db.migration.def.ColumnDef; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class AddCreationMethodColumnInProjectsTable extends DdlChange { + static final String PROJECTS_TABLE_NAME = "projects"; + static final String PROJECTS_CREATION_METHOD_COLUMN_NAME = "creation_method"; + static final int PROJECTS_CREATION_METHOD_COLUMN_SIZE = 50; + + public AddCreationMethodColumnInProjectsTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + try (Connection connection = getDatabase().getDataSource().getConnection()) { + if (!DatabaseUtils.tableColumnExists(connection, PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME)) { + ColumnDef columnDef = VarcharColumnDef.newVarcharColumnDefBuilder() + .setColumnName(PROJECTS_CREATION_METHOD_COLUMN_NAME) + .setLimit(PROJECTS_CREATION_METHOD_COLUMN_SIZE) + .setIsNullable(true) + .build(); + context.execute(new AddColumnsBuilder(getDialect(), PROJECTS_TABLE_NAME).addColumn(columnDef).build()); + } + } + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/DbVersion103.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/DbVersion103.java index bdf5f98b304..8ec81d7fd70 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/DbVersion103.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/DbVersion103.java @@ -45,6 +45,11 @@ public class DbVersion103 implements DbVersion { .add(10_3_001, "Add table 'github_perms_mapping'", CreateGithubPermissionsMappingTable.class) .add(10_3_002, "Create unique index on 'github_perms_mapping'", CreateUniqueIndexForGithubPermissionsMappingTable.class) .add(10_3_003, "Add default mappings to 'github_perms_mapping'", PopulateGithubPermissionsMapping.class) - .add(10_3_004, "Add 'clean_code_attribute' column in 'issues' table", AddCleanCodeAttributeColumnInIssuesTable.class); + .add(10_3_004, "Add 'clean_code_attribute' column in 'issues' table", AddCleanCodeAttributeColumnInIssuesTable.class) + + .add(10_3_005, "Add 'creation_method' column in 'projects' table", AddCreationMethodColumnInProjectsTable.class) + .add(10_3_006, "Populate 'creation_method' column in 'projects' table", PopulateCreationMethodColumnInProjectsTable.class) + .add(10_3_007, "Make 'creation_method' column in 'projects' table non-nullable", MakeCreationMethodColumnInProjectsNotNullable.class) + ; } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullable.java new file mode 100644 index 00000000000..8294f56a46b --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullable.java @@ -0,0 +1,46 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v103; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.def.VarcharColumnDef; +import org.sonar.server.platform.db.migration.sql.AlterColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; + +public class MakeCreationMethodColumnInProjectsNotNullable extends DdlChange { + + public MakeCreationMethodColumnInProjectsNotNullable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + VarcharColumnDef columnDef = VarcharColumnDef.newVarcharColumnDefBuilder(PROJECTS_CREATION_METHOD_COLUMN_NAME) + .setIsNullable(false) + .setLimit(PROJECTS_CREATION_METHOD_COLUMN_SIZE) + .build(); + context.execute(new AlterColumnsBuilder(getDialect(), PROJECTS_TABLE_NAME).updateColumn(columnDef).build()); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTable.java new file mode 100644 index 00000000000..69ddcb27500 --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTable.java @@ -0,0 +1,42 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v103; + +import java.sql.SQLException; +import org.sonar.db.Database; +import org.sonar.server.platform.db.migration.step.DataChange; +import org.sonar.server.platform.db.migration.step.Upsert; + +public class PopulateCreationMethodColumnInProjectsTable extends DataChange { + + private static final String UPDATE_QUERY = """ + update projects set creation_method='unknown' + """; + + public PopulateCreationMethodColumnInProjectsTable(Database db) { + super(db); + } + @Override + protected void execute(Context context) throws SQLException { + Upsert upsert = context.prepareUpsert(UPDATE_QUERY); + upsert.execute().commit(); + } + +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java new file mode 100644 index 00000000000..b88c1b3ecda --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static java.sql.Types.VARCHAR; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_SIZE; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; + +public class AddCreationMethodColumnInProjectsTableTest { + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(AddCreationMethodColumnInProjectsTableTest.class, "schema.sql"); + + private final AddCreationMethodColumnInProjectsTable underTest = new AddCreationMethodColumnInProjectsTable(db.database()); + + @Test + public void execute_whenColumnDoesNotExist_shouldCreateColumn() throws SQLException { + db.assertColumnDoesNotExist(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME); + underTest.execute(); + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, PROJECTS_CREATION_METHOD_COLUMN_SIZE, true); + } + + @Test + public void execute_whenColumnsAlreadyExists_shouldNotFail() throws SQLException { + underTest.execute(); + assertThatCode(underTest::execute).doesNotThrowAnyException(); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java new file mode 100644 index 00000000000..56093c72eeb --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest.java @@ -0,0 +1,51 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static java.sql.Types.VARCHAR; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_CREATION_METHOD_COLUMN_NAME; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; + +public class MakeCreationMethodColumnInProjectsNotNullableTest { + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(MakeCreationMethodColumnInProjectsNotNullableTest.class, "schema.sql"); + + private final MakeCreationMethodColumnInProjectsNotNullable underTest = new MakeCreationMethodColumnInProjectsNotNullable(db.database()); + + @Test + public void user_local_column_is_not_null() throws SQLException { + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, true); + underTest.execute(); + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, false); + } + + @Test + public void migration_is_reentrant() throws SQLException { + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, true); + underTest.execute(); + underTest.execute(); + db.assertColumnDefinition(PROJECTS_TABLE_NAME, PROJECTS_CREATION_METHOD_COLUMN_NAME, VARCHAR, null, false); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java new file mode 100644 index 00000000000..17d29ea0119 --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest.java @@ -0,0 +1,76 @@ +/* + * SonarQube + * Copyright (C) 2009-2023 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.server.platform.db.migration.version.v103; + +import java.sql.SQLException; +import org.junit.Rule; +import org.junit.Test; +import org.sonar.db.CoreDbTester; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.server.platform.db.migration.version.v103.AddCreationMethodColumnInProjectsTable.PROJECTS_TABLE_NAME; + +public class PopulateCreationMethodColumnInProjectsTableTest { + + @Rule + public final CoreDbTester db = CoreDbTester.createForSchema(PopulateCreationMethodColumnInProjectsTableTest.class, "schema.sql"); + + private final PopulateCreationMethodColumnInProjectsTable underTest = new PopulateCreationMethodColumnInProjectsTable(db.database()); + + @Test + public void execute_whenProjectsTableIsEmpty_shouldDoNothing() throws SQLException { + underTest.execute(); + + assertThat(db.select("select creation_method from projects")).isEmpty(); + } + + @Test + public void execute_whenProjectsExist_shouldPopulateCreationMethodColumn() throws SQLException { + insertProject("uuid-1"); + insertProject("uuid-2"); + + underTest.execute(); + + assertThat(db.select("select creation_method from projects")) + .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD")) + .containsExactlyInAnyOrder("unknown", "unknown"); + } + + @Test + public void execute_isReentrant() throws SQLException { + insertProject("uuid-1"); + + underTest.execute(); + underTest.execute(); + + assertThat(db.select("select creation_method from projects")) + .extracting(stringObjectMap -> stringObjectMap.get("CREATION_METHOD")) + .containsExactlyInAnyOrder("unknown"); + } + + private void insertProject(String uuid) { + db.executeInsert(PROJECTS_TABLE_NAME, + "UUID", uuid, + "KEE", uuid, + "QUALIFIER", "TRK", + "PRIVATE", true, + "UPDATED_AT", 1); + } +} diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest/schema.sql new file mode 100644 index 00000000000..8d4b017f15f --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/AddCreationMethodColumnInProjectsTableTest/schema.sql @@ -0,0 +1,15 @@ +CREATE TABLE "PROJECTS"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "KEE" CHARACTER VARYING(400) NOT NULL, + "QUALIFIER" CHARACTER VARYING(10) NOT NULL, + "NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "PRIVATE" BOOLEAN NOT NULL, + "TAGS" CHARACTER VARYING(500), + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT NOT NULL, + "NCLOC" BIGINT +); +ALTER TABLE "PROJECTS" ADD CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID"); +CREATE UNIQUE NULLS DISTINCT INDEX "UNIQ_PROJECTS_KEE" ON "PROJECTS"("KEE" NULLS FIRST); +CREATE INDEX "IDX_QUALIFIER" ON "PROJECTS"("QUALIFIER" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest/schema.sql new file mode 100644 index 00000000000..abf4cecb344 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/MakeCreationMethodColumnInProjectsNotNullableTest/schema.sql @@ -0,0 +1,16 @@ +create TABLE "PROJECTS"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "KEE" CHARACTER VARYING(400) NOT NULL, + "QUALIFIER" CHARACTER VARYING(10) NOT NULL, + "NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "PRIVATE" BOOLEAN NOT NULL, + "TAGS" CHARACTER VARYING(500), + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT NOT NULL, + "NCLOC" BIGINT, + "CREATION_METHOD" CHARACTER VARYING(50) +); +alter table "PROJECTS" add CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID"); +create unique NULLS DISTINCT INDEX "UNIQ_PROJECTS_KEE" on "PROJECTS"("KEE" NULLS FIRST); +create index "IDX_QUALIFIER" on "PROJECTS"("QUALIFIER" NULLS FIRST); diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest/schema.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest/schema.sql new file mode 100644 index 00000000000..abf4cecb344 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v103/PopulateCreationMethodColumnInProjectsTableTest/schema.sql @@ -0,0 +1,16 @@ +create TABLE "PROJECTS"( + "UUID" CHARACTER VARYING(40) NOT NULL, + "KEE" CHARACTER VARYING(400) NOT NULL, + "QUALIFIER" CHARACTER VARYING(10) NOT NULL, + "NAME" CHARACTER VARYING(2000), + "DESCRIPTION" CHARACTER VARYING(2000), + "PRIVATE" BOOLEAN NOT NULL, + "TAGS" CHARACTER VARYING(500), + "CREATED_AT" BIGINT, + "UPDATED_AT" BIGINT NOT NULL, + "NCLOC" BIGINT, + "CREATION_METHOD" CHARACTER VARYING(50) +); +alter table "PROJECTS" add CONSTRAINT "PK_NEW_PROJECTS" PRIMARY KEY("UUID"); +create unique NULLS DISTINCT INDEX "UNIQ_PROJECTS_KEE" on "PROJECTS"("KEE" NULLS FIRST); +create index "IDX_QUALIFIER" on "PROJECTS"("QUALIFIER" NULLS FIRST); -- 2.39.5