From 754088d174ef8d97e213d14ef7c20c278466cee3 Mon Sep 17 00:00:00 2001 From: mikrise2 Date: Sun, 25 Feb 2024 04:49:56 +0100 Subject: [PATCH] Added unique index keys --- .../research/tasktracker/database/DatabaseFactory.kt | 2 +- .../research/tasktracker/database/models/data/ActivityData.kt | 4 ++++ .../research/tasktracker/database/models/data/DocumentData.kt | 4 ++++ .../tasktracker/database/models/data/FileEditorData.kt | 4 ++++ .../research/tasktracker/database/models/data/SurveyData.kt | 4 ++++ .../research/tasktracker/database/models/data/WebCamData.kt | 4 ++++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt index a3212b99..3be824d0 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt @@ -26,7 +26,7 @@ object DatabaseFactory { SurveyData, FileEditorData ).let { - SchemaUtils.create(tables = it) + SchemaUtils.createMissingTablesAndColumns(tables = it) } commit() } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt index b2b6da79..3efd5c5c 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt @@ -28,6 +28,10 @@ object ActivityData : DataTable() { */ val actionId = integer("action_id").nullable() + init { + uniqueIndex(date, type, info, selectedText, actionId) + } + override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { insertStatement[type] = iterator.next() insertStatement[info] = iterator.next() diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt index 8c216931..d1e40dbd 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt @@ -17,6 +17,10 @@ object DocumentData : DataTable() { */ val testMode = text("test_mode") + init { + uniqueIndex(date, timestamp, filename, fileHashCode, documentHashCode, fragment) + } + override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { insertStatement[timestamp] = iterator.next().toLong() insertStatement[filename] = iterator.next() diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt index a1665185..d4fcdfdc 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt @@ -22,6 +22,10 @@ object FileEditorData : DataTable() { */ val newFile = text("new_file").nullable() + init { + uniqueIndex(date, action, oldFile, newFile) + } + override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { insertStatement[action] = iterator.next() insertStatement[oldFile] = iterator.next() diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt index 702bb731..763a4cfd 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt @@ -19,6 +19,10 @@ object SurveyData : DataTable() { val option = text("option").nullable() val answer = text("answer") + init { + uniqueIndex(date, questionId, question, option, answer) + } + override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { insertStatement[questionId] = iterator.next().toInt() insertStatement[question] = iterator.next() diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt index f48ef50a..e7baefe9 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt @@ -23,6 +23,10 @@ object WebCamData : DataTable() { */ val scores = text("scores") + init { + uniqueIndex(date, emotionShown, isRegular, scores) + } + override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { insertStatement[emotionShown] = iterator.next() insertStatement[isRegular] = iterator.next().toBoolean()