r.0.9.1.source-code.DatabaseMigrator.kt Maven / Gradle / Ivy
The newest version!
package se.wollan.tolr
import se.wollan.datascope.SqliteDatabase
import se.wollan.datascope.migrate
interface DatabaseMigrator {
suspend fun migrate()
}
internal class DatabaseMigratorImpl(private val db: SqliteDatabase) : DatabaseMigrator {
override suspend fun migrate() = db.migrate(
"tolr",
listOf(
"""
CREATE TABLE tolr_records (
timestamp INT NOT NULL,
nodeId TEXT NOT NULL,
type TEXT NOT NULL,
payload TEXT NOT NULL,
size INT NOT NULL,
PRIMARY KEY (timestamp, nodeId)
)
""",
"""
CREATE INDEX IX_tolr_records_type_timestamp_nodeId ON tolr_records (type, timestamp, nodeId)
""",
"""
CREATE TABLE tolr_hlc (timestamp INT NOT NULL)
""",
"""
INSERT INTO tolr_hlc (timestamp) VALUES (0)
""",
)
)
}