-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from NDLANO/move-ai-config-to-backend
Add config for ai enabled
- Loading branch information
Showing
4 changed files
with
82 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...cala/no/ndla/learningpathapi/db/migrationwithdependencies/V33__AiDefaultEnabledOrgs.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Part of NDLA learningpath-api | ||
* Copyright (C) 2023 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.learningpathapi.db.migrationwithdependencies | ||
|
||
import io.circe.Json | ||
import io.circe.syntax._ | ||
import no.ndla.common.model.NDLADate | ||
import no.ndla.learningpathapi.LearningpathApiProperties | ||
import org.flywaydb.core.api.migration.{BaseJavaMigration, Context} | ||
import org.postgresql.util.PGobject | ||
import scalikejdbc.{DB, DBSession, _} | ||
|
||
class V33__AiDefaultEnabledOrgs(properties: LearningpathApiProperties) extends BaseJavaMigration { | ||
|
||
override def migrate(context: Context): Unit = DB(context.getConnection) | ||
.autoClose(false) | ||
.withinTx { implicit session => | ||
insertConfig | ||
} | ||
|
||
private def insertConfig(implicit session: DBSession): Unit = { | ||
val document = Json.obj( | ||
"key" -> Json.fromString("AI_ENABLED_ORGS"), | ||
"value" -> Json.obj("value" -> Json.fromValues(orgs.map(Json.fromString))), | ||
"updatedAt" -> NDLADate.now().asJson, | ||
"updatedBy" -> Json.fromString("System") | ||
) | ||
|
||
val dataObject = new PGobject() | ||
dataObject.setType("jsonb") | ||
dataObject.setValue(document.noSpaces) | ||
|
||
val inserted = sql""" | ||
INSERT INTO configtable(configkey, value) | ||
VALUES ( | ||
'AI_ENABLED_ORGS', | ||
$dataObject | ||
) | ||
""".update.apply() | ||
|
||
if (inserted != 1) throw new RuntimeException("Failed to insert AI_ENABLED_ORGS") | ||
} | ||
|
||
private def orgs: List[String] = properties.Environment match { | ||
case "local" | "test" => | ||
List( | ||
"Agder fylkeskommune", | ||
"Innlandet fylkeskommune", | ||
"Møre og Romsdal fylkeskommune", | ||
"Nordland fylkeskommune", | ||
"Rogaland fylkeskommune", | ||
"Troms og Finnmark fylkeskommune", | ||
"Trøndelag fylkeskommune", | ||
"Vestfold og Telemark fylkeskommune", | ||
"Vestland fylkeskommune", | ||
"Viken fylkeskommune", | ||
"Universitetet i Rogn" | ||
) | ||
case "staging" | "prod" => | ||
List( | ||
"Agder fylkeskommune", | ||
"Nordland fylkeskommune", | ||
"Rogaland fylkeskommune", | ||
"Troms og Finnmark fylkeskommune", | ||
"Trøndelag fylkeskommune", | ||
"Vestland fylkeskommune" | ||
) | ||
case _ => List.empty | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters