Add V3 migration script
This commit is contained in:
145
src/main/kotlin/db/migration/V3__create_dictionaries.kt
Normal file
145
src/main/kotlin/db/migration/V3__create_dictionaries.kt
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
package db.migration
|
||||||
|
|
||||||
|
import dao.DictionaryDao
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import tables.*
|
||||||
|
import org.flywaydb.core.api.migration.BaseJavaMigration
|
||||||
|
import org.flywaydb.core.api.migration.Context
|
||||||
|
import org.jetbrains.exposed.dao.id.EntityID
|
||||||
|
import org.jetbrains.exposed.sql.*
|
||||||
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
class V3__create_dictionaries: BaseJavaMigration() {
|
||||||
|
override fun migrate(context: Context?) {
|
||||||
|
println(SharedData.hashDict)
|
||||||
|
//exitProcess(0)
|
||||||
|
for ((dbId,dict) in SharedData.hashDict) {
|
||||||
|
|
||||||
|
var dictTerms = SharedData.getListofTerms(dbId)
|
||||||
|
val dbName = "jdbc:h2:file:/Users/jaro/data/dict_${SharedData.hashLang[dict.lang1Id]?.shortName?.lowercase()}${SharedData.hashLang[dict.lang2Id]?.shortName?.lowercase()}"
|
||||||
|
println(dbName)
|
||||||
|
val db = Database.connect(dbName)
|
||||||
|
transaction (db) {
|
||||||
|
SchemaUtils.create(Dictionaries, Languages, Translations, TermsPronunciations, Pronunciations, PronunciationTypes, DictTypes, Suffixes, Terms)
|
||||||
|
|
||||||
|
for ((di, lang) in SharedData.hashLang) {
|
||||||
|
Languages.insert {
|
||||||
|
it[id] = lang.id
|
||||||
|
it[name] = lang.name
|
||||||
|
it[shortName] = lang.shortName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ((di, d) in SharedData.hashDict) {
|
||||||
|
Dictionaries.insert {
|
||||||
|
it[id] = d.id
|
||||||
|
it[lang1] = d.lang1Id
|
||||||
|
it[lang2] = d.lang2Id
|
||||||
|
it[name] = d.name
|
||||||
|
it[fullName] = d.fullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for ((di, trans) in SharedData.hashTransMap) {
|
||||||
|
Translations.insert {
|
||||||
|
it[id] = trans.id
|
||||||
|
it[lang1Id] = trans.lang1Id
|
||||||
|
it[lang2Id] = trans.lang2Id
|
||||||
|
it[dictionaryId] = trans.dictionaryId
|
||||||
|
it[langName1] = trans.lang1Name
|
||||||
|
it[langName2] = trans.lang2Name
|
||||||
|
it[direction] = trans.direction
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PronunciationTypes.insert {
|
||||||
|
it[id] = 1
|
||||||
|
it[name] = "English"
|
||||||
|
}
|
||||||
|
|
||||||
|
PronunciationTypes.insert {
|
||||||
|
it[id] = 2
|
||||||
|
it[name] = "American english"
|
||||||
|
}
|
||||||
|
|
||||||
|
PronunciationTypes.insert {
|
||||||
|
it[id] = 3
|
||||||
|
it[name] = "Business english"
|
||||||
|
}
|
||||||
|
|
||||||
|
for ((di, dt) in SharedData.hashDictType) {
|
||||||
|
DictTypes.insert {
|
||||||
|
it[id] = dt.id
|
||||||
|
it[shortName] = dt.shortName
|
||||||
|
it[fullName] = dt.fullName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var suffixMap : MutableMap<Int,Boolean> = mutableMapOf()
|
||||||
|
for (t in dictTerms) {
|
||||||
|
|
||||||
|
if (t.suffix1Id != null && !suffixMap.containsKey(t.suffix1Id)) {
|
||||||
|
val ss = SharedData.hashSuffix.getValue(t.suffix1Id)
|
||||||
|
Suffixes.insert {
|
||||||
|
it[id] = ss.id
|
||||||
|
it[text] = ss.text
|
||||||
|
}
|
||||||
|
suffixMap[ss.id] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t.suffix2Id != null && !suffixMap.containsKey(t.suffix2Id)) {
|
||||||
|
val ss = SharedData.hashSuffix.getValue(t.suffix2Id)
|
||||||
|
Suffixes.insert {
|
||||||
|
it[id] = ss.id
|
||||||
|
it[text] = ss.text
|
||||||
|
}
|
||||||
|
suffixMap[ss.id] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Terms.insert {
|
||||||
|
it[id] = t.id
|
||||||
|
it[string1] = t.string1
|
||||||
|
it[string2] = t.string2
|
||||||
|
it[suffix1] = t.suffix1Id
|
||||||
|
it[suffix2] = t.suffix2Id
|
||||||
|
it[type] = t.typeId
|
||||||
|
it[member] = t.member
|
||||||
|
it[order2] = t.order2
|
||||||
|
it[flags] = format.decodeFromString<IntArray?>(t.flags?.toString() ?:"[]")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SharedData.hashTermPron.containsKey(t.id)) {
|
||||||
|
|
||||||
|
for (pronId in SharedData.hashTermPron.getValue(t.id)){
|
||||||
|
val pron = SharedData.hashPron.getValue(pronId)
|
||||||
|
Pronunciations.upsert {
|
||||||
|
it[id] = pron.id
|
||||||
|
it[typeId] = pron.typeId
|
||||||
|
it[ipa] = pron.ipa
|
||||||
|
it[filename] = pron.filename
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (t in dictTerms) {
|
||||||
|
if (SharedData.hashTermPron.containsKey(t.id)) {
|
||||||
|
for (pronId in SharedData.hashTermPron.getValue(t.id)){
|
||||||
|
TermsPronunciations.insert {
|
||||||
|
it[term] = t.id
|
||||||
|
it[pronunciation] = pronId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dictTerms = listOf()
|
||||||
|
suffixMap = mutableMapOf()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user