aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-migration/src/main/java/org/sonar
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2017-06-09 17:35:22 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-06-20 04:10:53 -0700
commit0b4ea07b388078581dfec455e7a6a5d92e3ef117 (patch)
tree022dd82bbe43ea23e548ecd3a3ffcbece266c5c2 /server/sonar-db-migration/src/main/java/org/sonar
parentba3b4c92df55e2a876b72e615eabe37052126bfb (diff)
downloadsonarqube-0b4ea07b388078581dfec455e7a6a5d92e3ef117.tar.gz
sonarqube-0b4ea07b388078581dfec455e7a6a5d92e3ef117.zip
SONAR-9356 Add column USERS.ONBOARDED
Diffstat (limited to 'server/sonar-db-migration/src/main/java/org/sonar')
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java43
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java7
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java46
-rw-r--r--server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java54
4 files changed, 149 insertions, 1 deletions
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java
new file mode 100644
index 00000000000..7b6d202fcc1
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/AddUsersOnboarded.java
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v65;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class AddUsersOnboarded extends DdlChange {
+ public AddUsersOnboarded(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDialect(), "users")
+ .addColumn(newBooleanColumnDefBuilder()
+ .setColumnName("onboarded")
+ .setIsNullable(true)
+ .build())
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
index 75ac30953ab..5dd66b02490 100644
--- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/DbVersion65.java
@@ -17,6 +17,7 @@
* 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.v65;
import org.sonar.server.platform.db.migration.step.MigrationStepRegistry;
@@ -55,6 +56,10 @@ public class DbVersion65 implements DbVersion {
.add(1726, "Update org_qprofiles to reference built-in profiles", UpdateOrgQProfilesToPointToBuiltInProfiles.class)
.add(1727, "Delete rules_profiles orphans", DeleteOrphansFromRulesProfiles.class)
.add(1728, "Rename column qprofile_changes.qprofile_key to qprofile_changes.rules_profile_uuid", RenameQProfileKeyToRulesProfileUuidOnQProfileChanges.class)
- .add(1729, "Add index on qprofile_changes.rules_profile_uuid", AddIndexRulesProfileUuidOnQProfileChanges.class);
+ .add(1729, "Add index on qprofile_changes.rules_profile_uuid", AddIndexRulesProfileUuidOnQProfileChanges.class)
+ .add(1730, "Add USERS.ONBOARDED", AddUsersOnboarded.class)
+ .add(1731, "Populate USERS.ONBOARDED", PopulateUsersOnboarded.class)
+ .add(1732, "Make USERS.ONBOARDED not nullable", MakeUsersOnboardedNotNullable.class)
+ ;
}
}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java
new file mode 100644
index 00000000000..26f4a372bb8
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/MakeUsersOnboardedNotNullable.java
@@ -0,0 +1,46 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v65;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
+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.def.BooleanColumnDef.newBooleanColumnDefBuilder;
+
+public class MakeUsersOnboardedNotNullable extends DdlChange {
+
+ public MakeUsersOnboardedNotNullable(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ BooleanColumnDef column = newBooleanColumnDefBuilder()
+ .setColumnName("onboarded")
+ .setIsNullable(false)
+ .build();
+ context.execute(new AlterColumnsBuilder(getDialect(), "users")
+ .updateColumn(column)
+ .build());
+ }
+}
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java
new file mode 100644
index 00000000000..98d2c6c816b
--- /dev/null
+++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v65/PopulateUsersOnboarded.java
@@ -0,0 +1,54 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.v65;
+
+import java.sql.SQLException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.Select;
+
+public class PopulateUsersOnboarded extends DataChange {
+
+ private final System2 system2;
+
+ public PopulateUsersOnboarded(Database db, System2 system2) {
+ super(db);
+ this.system2 = system2;
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.prepareUpsert("update users set onboarded=?, updated_at=?")
+ .setBoolean(1, true)
+ .setLong(2, system2.now())
+ .execute()
+ .commit();
+ long users = context.prepareSelect("select count(u.id) from users u").get(Select.LONG_READER);
+ if (users == 1) {
+ context.prepareUpsert("update users set onboarded=?, updated_at=? where login=?")
+ .setBoolean(1, false)
+ .setLong(2, system2.now())
+ .setString(3, "admin")
+ .execute()
+ .commit();
+ }
+ }
+}