Skip to content

Commit

Permalink
chore: adding extra migration to sqlite and improving error message (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer authored Jan 16, 2025
1 parent 9c0ad85 commit bfd60ce
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions migrations/message_store/00010_dropStoredAt.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE message DROP COLUMN timestamp;

ALTER TABLE message RENAME COLUMN storedAt TO timestamp;
4 changes: 3 additions & 1 deletion tests/waku_archive/archive_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import
waku_archive,
waku_archive/common,
waku_archive/driver/sqlite_driver,
waku_archive/driver/sqlite_driver/migrations,
common/databases/db_sqlite,
],
../testlib/[wakucore]
Expand All @@ -18,7 +19,8 @@ proc newSqliteDatabase*(path: Option[string] = string.none()): SqliteDatabase =

proc newSqliteArchiveDriver*(): ArchiveDriver =
let database = newSqliteDatabase()
SqliteDriver.new(database).tryGet()
migrate(database).tryGet()
return SqliteDriver.new(database).tryGet()

proc newWakuArchive*(driver: ArchiveDriver): WakuArchive =
WakuArchive.new(driver).get()
Expand Down
4 changes: 3 additions & 1 deletion tests/waku_archive_legacy/archive_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import
waku_archive_legacy,
waku_archive_legacy/common,
waku_archive_legacy/driver/sqlite_driver,
waku_archive_legacy/driver/sqlite_driver/migrations,
common/databases/db_sqlite,
],
../testlib/[wakucore]
Expand All @@ -18,7 +19,8 @@ proc newSqliteDatabase*(path: Option[string] = string.none()): SqliteDatabase =

proc newSqliteArchiveDriver*(): ArchiveDriver =
let database = newSqliteDatabase()
SqliteDriver.new(database).tryGet()
migrate(database).tryGet()
return SqliteDriver.new(database).tryGet()

proc newWakuArchive*(driver: ArchiveDriver): WakuArchive =
WakuArchive.new(driver).get()
Expand Down
2 changes: 1 addition & 1 deletion waku/common/databases/db_sqlite.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ proc exec*[P](s: SqliteStmt[P, void], params: P): DatabaseResult[void] =

let res =
if (let v = sqlite3_step(s); v != SQLITE_DONE):
err($sqlite3_errstr(v))
err($sqlite3_errstr(v) & " " & $sqlite3_errmsg(sqlite3_db_handle(s)))
else:
ok()

Expand Down
2 changes: 1 addition & 1 deletion waku/waku_archive/driver/sqlite_driver/migrations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import ../../../common/databases/db_sqlite, ../../../common/databases/common
logScope:
topics = "waku archive migration"

const SchemaVersion* = 9 # increase this when there is an update in the database schema
const SchemaVersion* = 10 # increase this when there is an update in the database schema

template projectRoot(): string =
currentSourcePath.rsplit(DirSep, 1)[0] / ".." / ".." / ".." / ".."
Expand Down

0 comments on commit bfd60ce

Please sign in to comment.