mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-08-02 01:43:11 +00:00
* bump nim-libp2p pin to v2.0.0 tag * bump json_rpc to v0.6.1, lsquic to v0.5.1, boringssl to v0.0.8 (latest tags) * add libp2p_mix dep; repoint libp2p/protocols/mix -> libp2p_mix * pin nimble.lock: websock / protobuf_serialization / npeg / jwt * Makefile: add -d:libp2p_quic_support * regenerate nix/deps.nix (adds libp2p_mix, refreshes pins) * migrate rng ref HmacDrbgContext -> libp2p Rng across prod/channels/tests (interface-only; same DRBG) * waku_switch: TransportConfig factory; unified 2.0.0 connection limits (withMaxInOut, withMaxConnections); local MaxConnections * waku_relay/rendezvous/discv5/kademlia: v2.0.0 API (rng, config, ServiceDiscovery rename) * call Service.setup() on post-build switch services (2.0.0 split setup/start) * drop libp2p/utils/semaphore -> chronos AsyncSemaphore * add logos_delivery/waku/compat/option_valueor shim (Option[T] valueOr/withValue, dropped upstream) * add std/options where a transitive re-export was removed * add newStandardSwitch shim (libp2p removed it in 2.0.0); mounts yamux+mplex to match prod muxer * PeerId.random(rng); common.rng()/crypto.newRng(); hoist shared rng (instantiation cleanup) * update expectations for 2.0.0 defaults: DEFAULT_PROTOCOLS += /ipfs/id/push/1.0.0; agent "nim-libp2p" * drop relay reboot/reconnect test (asserted a Switch restart capability that is simply not supported) * fix up a few tests that were flaking on MacOS (libp2p upgrade may have exposed these)
101 lines
3.1 KiB
Nim
101 lines
3.1 KiB
Nim
import logos_delivery/waku/compat/option_valueor
|
|
{.push raises: [].}
|
|
|
|
import std/strutils, results, chronicles, chronos
|
|
import
|
|
../../../common/databases/common,
|
|
../../../../../migrations/message_store_postgres/pg_migration_manager,
|
|
../postgres_driver
|
|
|
|
logScope:
|
|
topics = "waku archive migration"
|
|
|
|
const SchemaVersion* = 7 # increase this when there is an update in the database schema
|
|
|
|
proc breakIntoStatements*(script: string): seq[string] =
|
|
## Given a full migration script, that can potentially contain a list
|
|
## of SQL statements, this proc splits it into the contained isolated statements
|
|
## that should be executed one after the other.
|
|
var statements = newSeq[string]()
|
|
|
|
let lines = script.split('\n')
|
|
|
|
var simpleStmt: string
|
|
var plSqlStatement: string
|
|
var insidePlSqlScript = false
|
|
for line in lines:
|
|
if line.strip().len == 0:
|
|
continue
|
|
|
|
if insidePlSqlScript:
|
|
if line.contains("END $$"):
|
|
## End of the Pl/SQL script
|
|
plSqlStatement &= line
|
|
statements.add(plSqlStatement)
|
|
plSqlStatement = ""
|
|
insidePlSqlScript = false
|
|
continue
|
|
else:
|
|
plSqlStatement &= line & "\n"
|
|
|
|
if line.contains("DO $$"):
|
|
## Beginning of the Pl/SQL script
|
|
insidePlSqlScript = true
|
|
plSqlStatement &= line & "\n"
|
|
|
|
if not insidePlSqlScript:
|
|
if line.contains(';'):
|
|
## End of simple statement
|
|
simpleStmt &= line
|
|
statements.add(simpleStmt)
|
|
simpleStmt = ""
|
|
else:
|
|
simpleStmt &= line & "\n"
|
|
|
|
return statements
|
|
|
|
proc migrate*(
|
|
driver: PostgresDriver, targetVersion = SchemaVersion
|
|
): Future[DatabaseResult[void]] {.async.} =
|
|
info "starting message store's postgres database migration"
|
|
|
|
let currentVersion = (await driver.getCurrentVersion()).valueOr:
|
|
return err("migrate error could not retrieve current version: " & $error)
|
|
|
|
if currentVersion == targetVersion:
|
|
info "database schema is up to date",
|
|
currentVersion = currentVersion, targetVersion = targetVersion
|
|
return ok()
|
|
|
|
info "database schema is outdated",
|
|
currentVersion = currentVersion, targetVersion = targetVersion
|
|
|
|
# Load migration scripts
|
|
let scripts = pg_migration_manager.getMigrationScripts(currentVersion, targetVersion)
|
|
|
|
# Lock the db
|
|
(await driver.acquireDatabaseLock()).isOkOr:
|
|
error "failed to acquire lock", error = error
|
|
return err("failed to lock the db")
|
|
|
|
defer:
|
|
(await driver.releaseDatabaseLock()).isOkOr:
|
|
error "failed to release lock", error = error
|
|
return err("failed to unlock the db.")
|
|
|
|
# Run the migration scripts
|
|
for script in scripts:
|
|
for statement in script.breakIntoStatements():
|
|
info "executing migration statement", statement = statement
|
|
|
|
(await driver.performWriteQuery(statement)).isOkOr:
|
|
error "failed to execute migration statement",
|
|
statement = statement, error = error
|
|
return err("failed to execute migration statement")
|
|
|
|
info "migration statement executed succesfully", statement = statement
|
|
|
|
info "finished message store's postgres database migration"
|
|
|
|
return ok()
|