Skip to content

First steps to move to SQLDelight #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 154 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
2c3d7cc
Set up SQLDelight
antweb May 3, 2024
2df8dba
Set up SQLDelight database and initial queries
antweb May 3, 2024
189238d
Remove nullability from downloadFile response
antweb May 3, 2024
e78758f
Create base classes for SQLDelight sync adapters
antweb May 3, 2024
4fe3894
Convert Item sync adapter
antweb May 3, 2024
1566802
Convert Cashier sync adapter
antweb May 3, 2024
77cce26
Create extensions with JSON utilities
antweb May 3, 2024
f17afd7
Simplify ReceiptLine.toJSON()
antweb May 6, 2024
b3f2a7d
Create Item extensions
antweb May 7, 2024
bcb2d4f
Add additional tables
antweb May 8, 2024
cf3bc0b
Move Settings.fiscalJSON extension to core-pos-sdk
antweb May 16, 2024
85961f1
Enable SQLDelight database on Android
antweb May 16, 2024
167da15
Add additional generic queries
antweb May 17, 2024
c0eec9e
Create date adapter for Postgres
antweb May 17, 2024
7c9abca
Update to latest schema
antweb May 29, 2024
1641d25
Change to BigDecimal.valueOf() in BigDecimalAdapter
antweb Jun 10, 2024
a5bda6c
Add ItemAddOn.toJSON() method
antweb Jun 10, 2024
57b3617
Update Closing column type mapping
antweb Jun 10, 2024
5f30d47
Add additional tables
antweb Jun 10, 2024
edd98df
Update tests
antweb Jun 10, 2024
7665988
Add consistent handling of dates stored as text
antweb Jun 13, 2024
3903167
Convert Order sync adapter
antweb Jun 17, 2024
5bdff02
Fix Postgres/SQLite incompatibilities
antweb Jun 20, 2024
c47c06a
Set database version for Postgres builds
antweb Jun 22, 2024
b350d6d
Define foreign keys as column constraints instead of table constraints
antweb Jun 22, 2024
64539aa
Add missing foreign keys
antweb Jun 22, 2024
a3f56d1
Move BaseDatabaseTest out of testFixtures
antweb Jun 24, 2024
0a7bb86
Add remaining table definitions
antweb Jun 25, 2024
3fa0c91
Add query to truncate all tables
antweb Jun 26, 2024
c8b94b9
Update to latest schema
antweb Jun 27, 2024
6fa69d8
Add remaining CachedPdfImage queries
robbi5 Jul 15, 2024
b13a3f8
Convert BadgeLayout and TicketLayout
robbi5 Jul 15, 2024
305633f
Add OrderPosition.selectByServerId query
antweb Jul 23, 2024
eea9665
Tweak query parameter naming
antweb Jul 23, 2024
3423d94
Remove unused quota query
antweb Jul 23, 2024
8f5bcc2
Run tests with Java 17
antweb Jul 23, 2024
4c65a51
Move protobuf plugin version to settings.gradle
antweb Jul 24, 2024
1b3ce76
Fix CachedPdfImage query under Postgres
antweb Jul 24, 2024
77f79e2
Migrate ItemCategorySyncAdapter
antweb Jul 24, 2024
5e24e29
Migrate SettingsSyncAdapter / InvoiceSettingsSyncAdapter
antweb Jul 24, 2024
3c2ce78
Migrate EventSyncAdapter
antweb Jul 25, 2024
0c21064
Migrate SubEventSyncAdapter
antweb Jul 25, 2024
b213bc8
Use ID instead of server ID for updateFromJson queries
antweb Jul 25, 2024
7997270
Add back event slug filter to migrated runBatch queries
antweb Jul 25, 2024
095f070
Migrate TaxRuleSyncAdapter
antweb Jul 25, 2024
ccfe923
Re-arrange SqBaseConditionalSyncAdapter method order
antweb Jul 25, 2024
de3444c
Migrate QuestionSyncAdapter
antweb Jul 25, 2024
9c8ff68
Migrate CheckInListSyncAdapter
antweb Jul 25, 2024
abd810a
Migrate AllEventsSyncAdapter
antweb Jul 25, 2024
3250792
Migrate AllSubEventsSyncAdapter
antweb Jul 26, 2024
31981bf
Migrate BadgeLayoutSyncAdapter
antweb Jul 26, 2024
7569a6b
Migrate BadgeLayoutItemSyncAdapter
antweb Jul 26, 2024
a01c0ce
Migrate MediumKeySetSyncAdapter
antweb Jul 26, 2024
0e0bd3c
Use consistent column naming on CheckInList
antweb Jul 26, 2024
dd8d194
Migrate BlockedTicketSecretSyncAdapter
antweb Jul 26, 2024
a5ef373
Add not-null assertion to columns with inconsistent nullability
antweb Jul 26, 2024
1d1922c
Migrate RevokedTicketSecretSyncAdapter
antweb Jul 26, 2024
6848bcc
Migrate ReusableMediaSyncAdapter
antweb Jul 26, 2024
a2e8a20
Migrate TicketLayoutSyncAdapter
antweb Jul 27, 2024
173f423
Migrate QuotaSyncAdapter
antweb Jul 27, 2024
d900511
Clean up old base classes
antweb Jul 27, 2024
aec2480
Finalize sync adapter migration
antweb Jul 27, 2024
ce6e96d
Convert Quota.available to Boolean on Postgres
antweb Jul 31, 2024
b08027e
Use IllegalArgumentException for PostgresIdAdapter
antweb Jul 31, 2024
f544bf5
Fix build warnings
antweb Jul 31, 2024
472a3f7
Tidy up queryKnownIDs
antweb Jul 31, 2024
e2fc471
Validate scale in BigDecimalAdapter
antweb Aug 9, 2024
d1b297e
Move toScaledBigDecimal/toScaledBigDecimalOrZero to BigDecimalAdapter
antweb Aug 9, 2024
bbeba89
Move models to libpretixsync
antweb Aug 9, 2024
2eb593e
Add receipt ID to ReceiptLine modelAdd receipt ID to ReceiptLine model
antweb Aug 30, 2024
9a68913
Enable autoPersist for BlockedTicketSecretSyncAdapter
antweb Sep 20, 2024
d5cad8b
Remove autoPersist()
antweb Sep 20, 2024
20dba52
Remove database version from Gradle files
antweb Sep 20, 2024
0a4463b
Migrate Question usage
antweb Sep 7, 2024
e0327cc
Migrate remaining usage of BlockedTicketSecret and RevokedTicketSecret
antweb Sep 7, 2024
91e8e05
Migrate remaining usage of SubEvent
antweb Sep 20, 2024
09fa413
Migrate remaining usage of Event
antweb Sep 20, 2024
eb5c65b
Remove unused deleted counter
antweb Sep 20, 2024
9d26ac2
Create CheckIn model
antweb Sep 20, 2024
21c330a
Migrate remaining usage of CheckIn
antweb Sep 20, 2024
450ce71
Fix event slug in AllSubEventsSyncAdapter
antweb Sep 27, 2024
f3b9cca
Fix question dependencies
antweb Sep 27, 2024
975715e
Fix java.time to Joda conversion
antweb Sep 27, 2024
7ad4ee6
Migrate remaining usage of CheckInList
antweb Sep 27, 2024
0148e06
Migrate remaining usage of Item and ItemCategory
antweb Sep 27, 2024
34104f5
Expand wildcard imports in AsyncCheckProviderTest
antweb Sep 27, 2024
2d88158
Migrate remaining usage of ReusableMedium
antweb Oct 3, 2024
66d5e78
Migrate majority of OrderPosition in AsyncCheckProvider
antweb Oct 3, 2024
f97bb6a
Migrate search query in AsyncCheckProvider
antweb Oct 4, 2024
a514446
Expand wildcard import in OrderSyncTest
antweb Oct 4, 2024
e038275
Migrate remaining usage of ResourceSyncStatus
antweb Oct 4, 2024
3e2287f
Fix typing issue between SQLite and Postgres
antweb Oct 4, 2024
01c3fae
Fix now datetime override in tests
antweb Oct 18, 2024
7abbd2d
Migrate AsyncCheckProvider.status()
antweb Oct 18, 2024
4937a4a
Add missing listed_price to item variation
robbi5 Oct 23, 2024
2e399fd
Migrate OrderCleanup
antweb Oct 26, 2024
bb1cf20
Migrate remaining usage of Order / OrderPosition
antweb Oct 26, 2024
41150ea
Migrate remaining usage of QueuedCall
antweb Oct 26, 2024
51ea1e8
Migrate remaining usage of QueuedCheckIn
antweb Oct 27, 2024
6fb7d8d
Remove dataStore arg from check providers
antweb Oct 27, 2024
a7c0e29
Add query to select BadgeLayoutItem by event slug
antweb Oct 27, 2024
b95c50e
Migrate remaining usage of Closing
antweb Oct 27, 2024
52f3b3b
Migrate remaining usage of QueuedOrder
antweb Oct 27, 2024
9d1d180
Use 0/1 for booleans in the queries, the shipped sqlite version on an…
robbi5 Nov 13, 2024
357a01d
Remove shared SimpleDateFormat instances in date adapters
antweb Nov 15, 2024
5a444bc
Use DateTimeFormatter in date adapters
antweb Nov 15, 2024
7701aaf
Add issue_giftcard to test Items
antweb Nov 22, 2024
3a08d8b
Fix boolean handling under Postgres
antweb Nov 22, 2024
434c9f1
Remove id parameter from QueuedOrder INSERT
antweb Nov 22, 2024
eb80c46
Move query to lock QueuedOrder to compat queries
antweb Nov 22, 2024
4a1b201
Add default values for Question model properties
antweb Dec 6, 2024
f36af81
Migrate Question validation tests
antweb Dec 6, 2024
bb3585c
Fix handling of initial receipt
raphaelm Dec 9, 2024
6908d81
Migrate SyncManager.uploadReceipts()
antweb Dec 13, 2024
4961670
Move manual migration from SyncManager to android_manual_migrations
antweb Dec 13, 2024
7e9a96e
Tax codes (#50)
raphaelm Dec 13, 2024
ce97bab
Remove remaining requery references from SyncManager
antweb Dec 13, 2024
45d25d0
Fix JSONObject creation
antweb Dec 13, 2024
04a107c
Fix migration race condition by providing sqldelight migration
raphaelm Dec 13, 2024
4842644
Move MediaPolicy out of AbstractItem
antweb Dec 13, 2024
206d05c
Move AbstractQueuedCheckIn.formatDatetime to new model
antweb Dec 13, 2024
803a466
Revert 4937a4a
raphaelm Dec 16, 2024
b78a1d7
Resolve TODO around addons
raphaelm Dec 17, 2024
f654bd9
Fix nullability of tax_code
raphaelm Dec 18, 2024
81a1cdc
Add migration to resolve bug remains
raphaelm Dec 18, 2024
8c44df8
Replace ItemVariation.listed_price with ItemVariation.display_price
raphaelm Dec 23, 2024
184db6d
Remove setter from TicketCheckProvider.QuestionAnswer.question
antweb Jan 10, 2025
fc8332a
Rename datetime to dateTime
antweb Jan 17, 2025
7331279
Rename Item.checkInAttention to requiresCheckInAttention
antweb Jan 17, 2025
6421313
Move BadgeLayoutExtensions and TicketLayoutExtensions
antweb Jan 17, 2025
3e794f0
Add query to select Questions by server ID list
antweb Jan 22, 2025
fbbf3ff
Remove unused store parameter from EventManager
antweb Feb 5, 2025
fec689b
Remove remaining references to BlockingEntityStore / Persistable
antweb Feb 12, 2025
aa2fb07
Fix de-serialization of TicketCheckProvider.QuestionAnswer
antweb Feb 19, 2025
8b8ccd2
Add columns for storing customer invoice details for a upcoming order
robbi5 Jan 27, 2025
6613066
Better names for email and phone columns
robbi5 Jan 27, 2025
e2f2434
Add new properties to toJSON, toModel, requery and fix sqlite syntax
robbi5 Jan 28, 2025
151fa75
Clear local order answer data on receipt after receipt data got uploaded
robbi5 Feb 5, 2025
3400351
New types of cash movements
raphaelm Feb 10, 2025
8fdd861
Move pretixSCAN Proxy API types to libpretixsync
antweb Mar 5, 2025
204e06b
Add _version queries
antweb Mar 12, 2025
199f445
Add SQLDelight migrations
antweb Mar 12, 2025
9951f4f
Move common migrations to common dir
antweb Mar 26, 2025
42b39c1
Add SQLDelight migration utilities
antweb Apr 2, 2025
d8d98a2
Add SQLDelight migrations for schema versions 77 to 91
antweb Apr 2, 2025
33f74ec
Update migrations after validation
antweb Apr 9, 2025
19f4fdf
Document migration validation
antweb Apr 9, 2025
b83803c
Fix migration from schema version 79 to 80
antweb Apr 16, 2025
14d31df
Use screaming snake case for constants
antweb Apr 16, 2025
c9188df
Add constant for the default database name
antweb Apr 16, 2025
32ba18d
Remove outdated requery references
antweb Apr 16, 2025
a979408
Migrate BaseDatabaseTest
antweb Apr 16, 2025
c70e759
Move CURRENT_VERSION constant to new Migrations class
antweb Apr 16, 2025
36e8056
Use SyncDatabase.Schema.version to get current schema version
antweb Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ on:

jobs:
test:
strategy:
matrix:
java: [ '11' ]

name: test with java ${{ matrix.java }}

name: test
runs-on: ubuntu-latest

steps:
Expand All @@ -22,7 +17,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java }}
java-version: '17'
distribution: 'temurin'

- name: Run Gradle
Expand Down
15 changes: 14 additions & 1 deletion libpretixsync/build-postgres.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ plugins {
id 'jacoco'
id 'org.jetbrains.kotlin.jvm'
id 'org.jetbrains.kotlin.kapt'
id 'com.google.protobuf' version '0.9.4'
id 'com.google.protobuf'
id 'com.github.gmazzo.buildconfig' version "5.3.5"
id 'org.gradle.idea'
id 'app.cash.sqldelight'
}
apply from: 'versions.gradle'

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

implementation "app.cash.sqldelight:jdbc-driver:$sqldelight_version"

kapt "io.requery:requery-processor:$requery_version"
annotationProcessor "javax.annotation:jsr250-api:$jsr250_version"

Expand All @@ -121,3 +124,13 @@ task copyTestResources(type: Copy) {
into "${buildDir}/classes/test"
}
processTestResources.dependsOn copyTestResources

sqldelight {
databases {
SyncDatabase {
packageName = "eu.pretix.libpretixsync.sqldelight"
dialect "app.cash.sqldelight:postgresql-dialect:$sqldelight_version"
srcDirs('src/main/sqldelight/postgres', 'src/main/sqldelight/common', 'src/main/sqldelight/migrations')
}
}
}
32 changes: 31 additions & 1 deletion libpretixsync/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ plugins {
id 'jacoco'
id 'org.jetbrains.kotlin.jvm'
id 'org.jetbrains.kotlin.kapt'
id 'com.google.protobuf' version '0.9.4'
id 'com.google.protobuf'
id 'com.github.gmazzo.buildconfig' version '5.3.5'
id 'org.gradle.idea'
id 'app.cash.sqldelight'
}
apply from: 'versions.gradle'

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

implementation "app.cash.sqldelight:sqlite-driver:$sqldelight_version"

kapt "io.requery:requery-processor:$requery_version"
annotationProcessor "javax.annotation:jsr250-api:$jsr250_version"

Expand All @@ -118,3 +121,30 @@ task copyTestResources(type: Copy) {
into "${buildDir}/classes/test"
}
processTestResources.dependsOn copyTestResources

sqldelight {
databases {
SyncDatabase {
packageName = "eu.pretix.libpretixsync.sqldelight"
srcDirs('src/main/sqldelight/sqlite', 'src/main/sqldelight/common', 'src/main/sqldelight/migrations')

// SQLDelight supports migration validation by running the migrations against a database file from a
// previous version and comparing the result against the current schema.
//
// The database dumps can be generated with the Gradle task `generateMainSyncDatabaseSchema`, which will
// place a .db file in `schemaOutputDirectory` (e.g. 100.db for schema version 100).
//
// Unfortunately, the validation is buggy for complex schemas (see https://github.com/sqldelight/sqldelight/issues/4759)
// and will hang or run out of memory in the current release.
//
// Running the `verifyMainSyncDatabaseMigration` is still helpful to check the syntax of the migrations.
schemaOutputDirectory.set(file("src/main/sqldelight/sqlite"))


// Oldest dialect supported by SQLDelight 2.0.2
// In Android projects, it will auto-select based on SDK
// but not go lower than 3.18 (Android 9 is still on 3.8)
dialect "app.cash.sqldelight:sqlite-3-18-dialect:$sqldelight_version"
}
}
}
3 changes: 2 additions & 1 deletion libpretixsync/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pluginManagement {
// but building it inside the multi module project doesn't exit with "unknown version already on classpath" error
plugins {
id "org.jetbrains.kotlin.jvm" version "1.9.23" apply false
id "com.google.protobuf" version "0.9.4" apply false
id "app.cash.sqldelight" version "2.0.2" apply false
}

rootProject.name = 'eu.pretix.libpretixsync'

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import eu.pretix.libpretixsync.DummySentryImplementation
import eu.pretix.libpretixsync.SentryInterface
import eu.pretix.libpretixsync.config.ConfigStore
import eu.pretix.libpretixsync.db.Answer
import eu.pretix.libpretixsync.db.Question
import eu.pretix.libpretixsync.db.QueuedCheckIn
import eu.pretix.libpretixsync.models.Question
import eu.pretix.libpretixsync.models.QueuedCheckIn
import eu.pretix.libpretixsync.utils.NetUtils
import eu.pretix.libpretixsync.utils.URLFragmentEncoder
import okhttp3.MediaType
Expand Down Expand Up @@ -73,9 +73,9 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
"pdf" -> "application/pdf".toMediaTypeOrNull()!!
else -> "application/unknown".toMediaTypeOrNull()!!
}, a.value.split("/").last())
answerbody.put("" + (a.question as Question).getServer_id(), fileid)
answerbody.put("" + (a.question as Question).serverId, fileid)
} else {
answerbody.put("" + (a.question as Question).getServer_id(), a.value)
answerbody.put("" + (a.question as Question).serverId, a.value)
}
}
}
Expand Down Expand Up @@ -120,9 +120,9 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
"pdf" -> "application/pdf".toMediaTypeOrNull()!!
else -> "application/unknown".toMediaTypeOrNull()!!
}, a.value.split("/").last())
answerbody.put("" + (a.question as Question).getServer_id(), fileid)
answerbody.put("" + (a.question as Question).serverId, fileid)
} else {
answerbody.put("" + (a.question as Question).getServer_id(), a.value)
answerbody.put("" + (a.question as Question).serverId, a.value)
}
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ open class PretixApi(url: String, key: String, orgaSlug: String, version: Int, h
}

@Throws(ApiException::class)
open fun downloadFile(full_url: String): ApiResponse? {
open fun downloadFile(full_url: String): ApiResponse {
var request = Request.Builder()
.url(full_url)
.header("Authorization", "Device $key")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package eu.pretix.libpretixsync.api

import eu.pretix.libpretixsync.db.Answer
import eu.pretix.libpretixsync.db.QuestionOption
import eu.pretix.libpretixsync.models.db.toModel
import eu.pretix.libpretixsync.sqldelight.SyncDatabase

/**
* API types for the pretixSCAN Proxy
*
* Used as common types between the ProxyCheckProvider and the Proxy API endpoints.
*
* They replicate the field names of the old requery models, which were sent in the requests before the SQLDelight
* migration. This should provide reasonable backwards compatibility.
*/

data class MultiCheckInput(
val events_and_checkin_lists: Map<String, Long>,
val ticketid: String,
val answers: List<CheckInputAnswer>?,
val ignore_unpaid: Boolean,
val with_badge_data: Boolean,
val type: String?,
val source_type: String?,

// TODO: Check unused values
val allowQuestions: Boolean,
val nonce: String?
)

data class CheckInput(
val ticketid: String,
val answers: List<CheckInputAnswer>?,
val ignore_unpaid: Boolean,
val with_badge_data: Boolean,
val type: String?,
val source_type: String?
)

data class CheckInputAnswer(
var question: CheckInputQuestion,
var value: String,
var options: List<QuestionOption>? = null
) {
fun toAnswer(db: SyncDatabase): Answer {
val q = db.questionQueries.selectByServerId(question.server_id).executeAsOne().toModel()
return Answer(q, value, options)
}
}

data class CheckInputQuestion(
val server_id: Long,
)

data class SearchInput(
val query: String,
val page: Int,

// TODO: Check unused values
val events_and_checkin_lists: Map<String, Long>,
)
Loading
Loading