feat: migrate system + cross-DB engine + IMPORT/EXPORT syntax -- 22 files, client+server+docs
CI / test (push) Has been cancelled
CI / verify (push) Has been cancelled
Clients CI / build-server (push) Has been cancelled
Clients CI / test-python (push) Has been cancelled
Clients CI / test-javascript (push) Has been cancelled
Clients CI / test-nim (push) Has been cancelled
Clients CI / test-rust (push) Has been cancelled
CI / test (push) Has been cancelled
CI / verify (push) Has been cancelled
Clients CI / build-server (push) Has been cancelled
Clients CI / test-python (push) Has been cancelled
Clients CI / test-javascript (push) Has been cancelled
Clients CI / test-nim (push) Has been cancelled
Clients CI / test-rust (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
discard """
|
||||
cmd: "nim c -r $file"
|
||||
"""
|
||||
|
||||
import std/unittest
|
||||
import std/asyncdispatch
|
||||
import std/json
|
||||
import ../../src/allographer/query_builder
|
||||
import ../../src/allographer/query_builder/models/baradb/baradb_exec
|
||||
import ./connections
|
||||
|
||||
|
||||
let rdb = baradb
|
||||
|
||||
suite("Baradb migrations"):
|
||||
test("create migration"):
|
||||
let upSql = """
|
||||
CREATE TABLE IF NOT EXISTS test_mig_users (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name VARCHAR(255)
|
||||
)
|
||||
"""
|
||||
let downSql = "DROP TABLE IF EXISTS test_mig_users"
|
||||
let qr = waitFor rdb.createMigration("test_mig_001", upSql, downSql)
|
||||
check qr.rowCount >= 0
|
||||
|
||||
test("migration status shows pending"):
|
||||
let status = waitFor rdb.migrationStatus()
|
||||
var found = false
|
||||
for row in status:
|
||||
if row["name"].getStr() == "test_mig_001":
|
||||
check row["status"].getStr() == "pending"
|
||||
found = true
|
||||
break
|
||||
check found
|
||||
|
||||
test("apply migration"):
|
||||
let qr = waitFor rdb.applyMigration("test_mig_001")
|
||||
check qr.rowCount >= 0
|
||||
|
||||
test("is migration applied"):
|
||||
let applied = waitFor rdb.isMigrationApplied("test_mig_001")
|
||||
check applied
|
||||
|
||||
test("migration up (all pending)"):
|
||||
let qr = waitFor rdb.migrateUp()
|
||||
check qr.rowCount >= 0
|
||||
|
||||
test("migration dry run"):
|
||||
let qr = waitFor rdb.migrationDryRun("test_mig_001")
|
||||
check qr.rowCount >= 0
|
||||
|
||||
test("table exists after migration"):
|
||||
let users = waitFor rdb.table("test_mig_users").get()
|
||||
check users.len >= 0
|
||||
|
||||
test("migrate down (rollback)"):
|
||||
let qr = waitFor rdb.migrateDown(1)
|
||||
check qr.rowCount >= 0
|
||||
@@ -0,0 +1,85 @@
|
||||
discard """
|
||||
cmd: "nim c -r $file"
|
||||
"""
|
||||
|
||||
import std/unittest
|
||||
import std/asyncdispatch
|
||||
import std/json
|
||||
import std/options
|
||||
import ../../src/allographer/query_builder
|
||||
import ../../src/allographer/query_builder/models/baradb/baradb_exec
|
||||
import ../../src/allographer/query_builder/libs/baradb/baradb_client
|
||||
import ./connections
|
||||
|
||||
|
||||
let rdb = baradb
|
||||
|
||||
suite("Baradb prepared statements"):
|
||||
setup:
|
||||
# Ensure test table exists
|
||||
let createSql = """
|
||||
CREATE TABLE IF NOT EXISTS test_prep_data (
|
||||
id SERIAL PRIMARY KEY,
|
||||
label VARCHAR(255),
|
||||
count INTEGER
|
||||
)
|
||||
"""
|
||||
waitFor rdb.raw(createSql).exec()
|
||||
|
||||
test("prepare statement"):
|
||||
let stmt = waitFor rdb.prepare(
|
||||
"SELECT * FROM test_prep_data WHERE count > ?", nArgs = 1
|
||||
)
|
||||
check not stmt.isClosed
|
||||
|
||||
test("ensureStmt"):
|
||||
let entry = rdb.ensureStmt(
|
||||
"SELECT * FROM test_prep_data WHERE label = ?", nArgs = 1
|
||||
)
|
||||
check entry.sql.len > 0
|
||||
check entry.nArgs == 1
|
||||
|
||||
test("preparedGet with params"):
|
||||
# Insert test data
|
||||
waitFor rdb.table("test_prep_data").insert(%*{
|
||||
"label": "alpha", "count": 5
|
||||
})
|
||||
waitFor rdb.table("test_prep_data").insert(%*{
|
||||
"label": "beta", "count": 15
|
||||
})
|
||||
|
||||
# Query via prepared statement
|
||||
let stmt = waitFor rdb.prepare(
|
||||
"SELECT * FROM test_prep_data WHERE count > ?", nArgs = 1
|
||||
)
|
||||
let results = waitFor stmt.preparedGet(@[
|
||||
WireValue(kind: fkInt32, int32Val: 10)
|
||||
])
|
||||
check results.len >= 1
|
||||
if results.len > 0:
|
||||
check results[0]["label"].getStr() == "beta"
|
||||
|
||||
test("preparedExec insert"):
|
||||
let stmt = waitFor rdb.prepare(
|
||||
"INSERT INTO test_prep_data (label, count) VALUES (?, ?)", nArgs = 2
|
||||
)
|
||||
let affected = waitFor stmt.preparedExec(@[
|
||||
WireValue(kind: fkString, strVal: "gamma"),
|
||||
WireValue(kind: fkInt32, int32Val: 25)
|
||||
])
|
||||
check affected >= 0
|
||||
|
||||
test("flush statement"):
|
||||
let stmt = waitFor rdb.prepare(
|
||||
"SELECT * FROM test_prep_data", nArgs = 0
|
||||
)
|
||||
stmt.flushStmt()
|
||||
check stmt.isClosed
|
||||
|
||||
test("clear statement cache"):
|
||||
rdb.clearStmtCache()
|
||||
check true
|
||||
|
||||
test("cleanup"):
|
||||
waitFor rdb.raw("DROP TABLE IF EXISTS test_prep_data").exec()
|
||||
check true
|
||||
Reference in New Issue
Block a user