1 /*
2  *  Make.org Core API
3  *  Copyright (C) 2018 Make.org
4  *
5  * This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU Affero General Public License as
7  *  published by the Free Software Foundation, either version 3 of the
8  *  License, or (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU Affero General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Affero General Public License
16  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17  *
18  */
19 
20 package org.make.api.migrations.db
21 
22 import java.sql.Connection
23 import java.util.UUID
24 
25 class V130_1__Add_auto_mails_templates_values extends Migration {
26   private def nextId(): String = UUID.randomUUID().toString
27 
28   private val isProd = System.getenv("ENV_NAME") == "prod"
29 
30   private val voteOnlyNoticeIds: (String, String) =
31     ("3971766", "3990233")
32 
33   private val endConsultationNoticeIds: (String, String) =
34     ("3990183", "3990245")
35 
36   private def voteOnlyNoticeTemplateRow: String = {
37     val (preprod, prod) = voteOnlyNoticeIds
38     s"('${nextId()}', 'VoteOnlyNotice', 'fr', '${if (isProd) prod else preprod}')"
39   }
40 
41   private def endConsultationNoticeTemplateRow: String = {
42     val (preprod, prod) = endConsultationNoticeIds
43     s"('${nextId()}', 'EndConsultationNotice', 'fr', '${if (isProd) prod else preprod}')"
44   }
45 
46   @SuppressWarnings(Array("org.wartremover.warts.While", "org.wartremover.warts.MutableDataStructures"))
47   override def migrate(connection: Connection): Unit = {
48 
49     def insertTplRow(row: String): Unit =
50       connection
51         .prepareStatement(s"INSERT INTO crm_language_template (id, kind, language, template) VALUES $row")
52         .execute()
53 
54     insertTplRow(voteOnlyNoticeTemplateRow)
55     insertTplRow(endConsultationNoticeTemplateRow)
56   }
57 
58 }
Line Stmt Id Pos Tree Symbol Tests Code
26 20701 930 - 956 Apply java.util.UUID.toString org.make.api.databasetest java.util.UUID.randomUUID().toString()
28 19721 981 - 1016 Apply java.lang.Object.== org.make.api.databasetest java.lang.System.getenv("ENV_NAME").==("prod")
31 21807 1074 - 1096 Apply scala.Tuple2.apply org.make.api.databasetest scala.Tuple2.apply[String, String]("3971766", "3990233")
34 20826 1161 - 1183 Apply scala.Tuple2.apply org.make.api.databasetest scala.Tuple2.apply[String, String]("3990183", "3990245")
37 19785 1246 - 1246 Select scala.Tuple2._1 org.make.api.databasetest x$1._1
37 21485 1255 - 1255 Select scala.Tuple2._2 org.make.api.databasetest x$1._2
42 20419 1437 - 1437 Select scala.Tuple2._1 org.make.api.databasetest x$2._1
42 19969 1446 - 1446 Select scala.Tuple2._2 org.make.api.databasetest x$2._2
52 21641 1785 - 1921 Apply java.sql.PreparedStatement.execute org.make.api.databasetest connection.prepareStatement(("INSERT INTO crm_language_template (id, kind, language, template) VALUES ".+(row): String)).execute()
52 20683 1919 - 1919 Literal <nosymbol> org.make.api.databasetest ()
54 21731 1927 - 1966 Apply org.make.api.migrations.db.V130_1__Add_auto_mails_templates_values.insertTplRow org.make.api.databasetest insertTplRow(V130_1__Add_auto_mails_templates_values.this.voteOnlyNoticeTemplateRow)
54 19730 1940 - 1965 Select org.make.api.migrations.db.V130_1__Add_auto_mails_templates_values.voteOnlyNoticeTemplateRow org.make.api.databasetest V130_1__Add_auto_mails_templates_values.this.voteOnlyNoticeTemplateRow
55 19812 1971 - 2017 Apply org.make.api.migrations.db.V130_1__Add_auto_mails_templates_values.insertTplRow org.make.api.databasetest insertTplRow(V130_1__Add_auto_mails_templates_values.this.endConsultationNoticeTemplateRow)
55 20782 1984 - 2016 Select org.make.api.migrations.db.V130_1__Add_auto_mails_templates_values.endConsultationNoticeTemplateRow org.make.api.databasetest V130_1__Add_auto_mails_templates_values.this.endConsultationNoticeTemplateRow