Skip to content

Commit 13a605e

Browse files
authored
Merge pull request #47 from pretix/sqldelight
First steps to move to SQLDelight
2 parents 1c968fa + 7321934 commit 13a605e

File tree

293 files changed

+11165
-4373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

293 files changed

+11165
-4373
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,7 @@ on:
88

99
jobs:
1010
test:
11-
strategy:
12-
matrix:
13-
java: [ '11' ]
14-
15-
name: test with java ${{ matrix.java }}
16-
11+
name: test
1712
runs-on: ubuntu-latest
1813

1914
steps:
@@ -22,13 +17,13 @@ jobs:
2217
- name: Set up JDK
2318
uses: actions/setup-java@v3
2419
with:
25-
java-version: ${{ matrix.java }}
20+
java-version: '17'
2621
distribution: 'temurin'
2722

2823
- name: Run Gradle
2924
uses: gradle/gradle-build-action@v2
3025
with:
31-
arguments: clean check test build jar jacocoTestReport
26+
arguments: clean check test build jar jacocoTestReport -x verifyMainSyncDatabaseMigration
3227
build-root-directory: libpretixsync
3328

3429
- name: Codecov

libpretixsync/build-postgres.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ plugins {
66
id 'jacoco'
77
id 'org.jetbrains.kotlin.jvm'
88
id 'org.jetbrains.kotlin.kapt'
9-
id 'com.google.protobuf' version '0.9.4'
9+
id 'com.google.protobuf'
1010
id 'com.github.gmazzo.buildconfig' version "5.3.5"
1111
id 'org.gradle.idea'
12+
id 'app.cash.sqldelight'
1213
}
1314
apply from: 'versions.gradle'
1415

@@ -107,6 +108,8 @@ dependencies {
107108
implementation "net.i2p.crypto:eddsa:$eddsa_version"
108109
implementation "com.google.protobuf:protobuf-javalite:$protobuf_version"
109110

111+
implementation "app.cash.sqldelight:jdbc-driver:$sqldelight_version"
112+
110113
kapt "io.requery:requery-processor:$requery_version"
111114
annotationProcessor "javax.annotation:jsr250-api:$jsr250_version"
112115

@@ -121,3 +124,13 @@ task copyTestResources(type: Copy) {
121124
into "${buildDir}/classes/test"
122125
}
123126
processTestResources.dependsOn copyTestResources
127+
128+
sqldelight {
129+
databases {
130+
SyncDatabase {
131+
packageName = "eu.pretix.libpretixsync.sqldelight"
132+
dialect "app.cash.sqldelight:postgresql-dialect:$sqldelight_version"
133+
srcDirs('src/main/sqldelight/postgres', 'src/main/sqldelight/common', 'src/main/sqldelight/migrations')
134+
}
135+
}
136+
}

libpretixsync/build.gradle

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ plugins {
44
id 'jacoco'
55
id 'org.jetbrains.kotlin.jvm'
66
id 'org.jetbrains.kotlin.kapt'
7-
id 'com.google.protobuf' version '0.9.4'
7+
id 'com.google.protobuf'
88
id 'com.github.gmazzo.buildconfig' version '5.3.5'
99
id 'org.gradle.idea'
10+
id 'app.cash.sqldelight'
1011
}
1112
apply from: 'versions.gradle'
1213

@@ -104,6 +105,8 @@ dependencies {
104105
implementation "net.i2p.crypto:eddsa:$eddsa_version"
105106
implementation "com.google.protobuf:protobuf-javalite:$protobuf_version"
106107

108+
implementation "app.cash.sqldelight:sqlite-driver:$sqldelight_version"
109+
107110
kapt "io.requery:requery-processor:$requery_version"
108111
annotationProcessor "javax.annotation:jsr250-api:$jsr250_version"
109112

@@ -118,3 +121,30 @@ task copyTestResources(type: Copy) {
118121
into "${buildDir}/classes/test"
119122
}
120123
processTestResources.dependsOn copyTestResources
124+
125+
sqldelight {
126+
databases {
127+
SyncDatabase {
128+
packageName = "eu.pretix.libpretixsync.sqldelight"
129+
srcDirs('src/main/sqldelight/sqlite', 'src/main/sqldelight/common', 'src/main/sqldelight/migrations')
130+
131+
// SQLDelight supports migration validation by running the migrations against a database file from a
132+
// previous version and comparing the result against the current schema.
133+
//
134+
// The database dumps can be generated with the Gradle task `generateMainSyncDatabaseSchema`, which will
135+
// place a .db file in `schemaOutputDirectory` (e.g. 100.db for schema version 100).
136+
//
137+
// Unfortunately, the validation is buggy for complex schemas (see https://github.com/sqldelight/sqldelight/issues/4759)
138+
// and will hang or run out of memory in the current release.
139+
//
140+
// Running the `verifyMainSyncDatabaseMigration` is still helpful to check the syntax of the migrations.
141+
schemaOutputDirectory.set(file("src/main/sqldelight/sqlite"))
142+
143+
144+
// Oldest dialect supported by SQLDelight 2.0.2
145+
// In Android projects, it will auto-select based on SDK
146+
// but not go lower than 3.18 (Android 9 is still on 3.8)
147+
dialect "app.cash.sqldelight:sqlite-3-18-dialect:$sqldelight_version"
148+
}
149+
}
150+
}

libpretixsync/settings.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pluginManagement {
1212
// but building it inside the multi module project doesn't exit with "unknown version already on classpath" error
1313
plugins {
1414
id "org.jetbrains.kotlin.jvm" version "1.9.23" apply false
15+
id "com.google.protobuf" version "0.9.4" apply false
16+
id "app.cash.sqldelight" version "2.0.2" apply false
1517
}
1618

1719
rootProject.name = 'eu.pretix.libpretixsync'
18-

libpretixsync/src/main/java/eu/pretix/libpretixsync/api/PretixApi.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import eu.pretix.libpretixsync.DummySentryImplementation
44
import eu.pretix.libpretixsync.SentryInterface
55
import eu.pretix.libpretixsync.config.ConfigStore
66
import eu.pretix.libpretixsync.db.Answer
7-
import eu.pretix.libpretixsync.db.Question
8-
import eu.pretix.libpretixsync.db.QueuedCheckIn
7+
import eu.pretix.libpretixsync.models.Question
8+
import eu.pretix.libpretixsync.models.QueuedCheckIn
99
import eu.pretix.libpretixsync.utils.NetUtils
1010
import eu.pretix.libpretixsync.utils.URLFragmentEncoder
1111
import okhttp3.MediaType
@@ -73,9 +73,9 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
7373
"pdf" -> "application/pdf".toMediaTypeOrNull()!!
7474
else -> "application/unknown".toMediaTypeOrNull()!!
7575
}, a.value.split("/").last())
76-
answerbody.put("" + (a.question as Question).getServer_id(), fileid)
76+
answerbody.put("" + (a.question as Question).serverId, fileid)
7777
} else {
78-
answerbody.put("" + (a.question as Question).getServer_id(), a.value)
78+
answerbody.put("" + (a.question as Question).serverId, a.value)
7979
}
8080
}
8181
}
@@ -120,9 +120,9 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
120120
"pdf" -> "application/pdf".toMediaTypeOrNull()!!
121121
else -> "application/unknown".toMediaTypeOrNull()!!
122122
}, a.value.split("/").last())
123-
answerbody.put("" + (a.question as Question).getServer_id(), fileid)
123+
answerbody.put("" + (a.question as Question).serverId, fileid)
124124
} else {
125-
answerbody.put("" + (a.question as Question).getServer_id(), a.value)
125+
answerbody.put("" + (a.question as Question).serverId, a.value)
126126
}
127127
}
128128
}
@@ -314,7 +314,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
314314
}
315315

316316
@Throws(ApiException::class)
317-
open fun downloadFile(full_url: String): ApiResponse? {
317+
open fun downloadFile(full_url: String): ApiResponse {
318318
var request = Request.Builder()
319319
.url(full_url)
320320
.header("Authorization", "Device $key")
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package eu.pretix.libpretixsync.api
2+
3+
import eu.pretix.libpretixsync.db.Answer
4+
import eu.pretix.libpretixsync.db.QuestionOption
5+
import eu.pretix.libpretixsync.models.db.toModel
6+
import eu.pretix.libpretixsync.sqldelight.SyncDatabase
7+
8+
/**
9+
* API types for the pretixSCAN Proxy
10+
*
11+
* Used as common types between the ProxyCheckProvider and the Proxy API endpoints.
12+
*
13+
* They replicate the field names of the old requery models, which were sent in the requests before the SQLDelight
14+
* migration. This should provide reasonable backwards compatibility.
15+
*/
16+
17+
data class MultiCheckInput(
18+
val events_and_checkin_lists: Map<String, Long>,
19+
val ticketid: String,
20+
val answers: List<CheckInputAnswer>?,
21+
val ignore_unpaid: Boolean,
22+
val with_badge_data: Boolean,
23+
val type: String?,
24+
val source_type: String?,
25+
26+
// TODO: Check unused values
27+
val allowQuestions: Boolean,
28+
val nonce: String?
29+
)
30+
31+
data class CheckInput(
32+
val ticketid: String,
33+
val answers: List<CheckInputAnswer>?,
34+
val ignore_unpaid: Boolean,
35+
val with_badge_data: Boolean,
36+
val type: String?,
37+
val source_type: String?
38+
)
39+
40+
data class CheckInputAnswer(
41+
var question: CheckInputQuestion,
42+
var value: String,
43+
var options: List<QuestionOption>? = null
44+
) {
45+
fun toAnswer(db: SyncDatabase): Answer {
46+
val q = db.questionQueries.selectByServerId(question.server_id).executeAsOne().toModel()
47+
return Answer(q, value, options)
48+
}
49+
}
50+
51+
data class CheckInputQuestion(
52+
val server_id: Long,
53+
)
54+
55+
data class SearchInput(
56+
val query: String,
57+
val page: Int,
58+
59+
// TODO: Check unused values
60+
val events_and_checkin_lists: Map<String, Long>,
61+
)

0 commit comments

Comments
 (0)