6bfc5b3a3c
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
- Pure Nim wire protocol client (async + sync, no C FFI) - Query Builder: fluent API, SQL generator, execution, transactions - Schema Builder: create/alter/drop tables, column operations - Connection pool with aging and timeout handling - ORM integration via compile-time DB_BARADB switch - Tests: test_open, test_query - Documentation: README.md, PLAN_BARADB.md
109 lines
3.7 KiB
Nim
109 lines
3.7 KiB
Nim
discard """
|
|
cmd: "nim c -d:reset $file"
|
|
"""
|
|
|
|
# nim c -d:reset -r tests/mysql/test_create_schema.nim
|
|
|
|
import std/unittest
|
|
import std/asyncdispatch
|
|
import std/os
|
|
import std/strutils
|
|
import std/json
|
|
import ../../src/allographer/schema_builder
|
|
import ./connections
|
|
import ../clear_tables
|
|
|
|
|
|
let rdb = mysql
|
|
let schemaFilePath = getCurrentDir() / "schema.nim"
|
|
clearTables(rdb).waitFor()
|
|
|
|
suite "Schema output after migration":
|
|
setup:
|
|
# schema.nim ファイルの削除
|
|
if fileExists(schemaFilePath):
|
|
removeFile(schemaFilePath)
|
|
|
|
rdb.create(
|
|
table("int_relation", [
|
|
Column.increments("id")
|
|
]),
|
|
table("str_relation", [
|
|
Column.uuid("uuid")
|
|
]),
|
|
table("test_schema_output", [
|
|
Column.increments("id"),
|
|
Column.integer("integer"),
|
|
Column.smallInteger("smallInteger"),
|
|
Column.mediumInteger("mediumInteger"),
|
|
Column.bigInteger("bigInteger"),
|
|
Column.decimal("decimal", 10, 3),
|
|
Column.double("double", 10, 3),
|
|
Column.float("float"),
|
|
Column.uuid("uuid"),
|
|
Column.char("char", 255),
|
|
Column.string("string"),
|
|
Column.text("text"),
|
|
Column.mediumText("mediumText"),
|
|
Column.longText("longText"),
|
|
Column.date("date"),
|
|
Column.datetime("datetime"),
|
|
Column.time("time"),
|
|
Column.timestamp("timestamp"),
|
|
Column.timestamps(),
|
|
Column.softDelete(),
|
|
Column.binary("binary"),
|
|
Column.boolean("boolean"),
|
|
Column.enumField("enumField", ["A", "B", "C"]),
|
|
Column.json("json"),
|
|
Column.foreign("int_relation_id").reference("id").onTable("int_relation").onDelete(SET_NULL),
|
|
Column.strForeign("str_relation_id").reference("uuid").onTable("str_relation").onDelete(SET_NULL)
|
|
])
|
|
)
|
|
|
|
|
|
test "should generate schema.nim file":
|
|
# スキーマ生成
|
|
rdb.createSchema(schemaFilePath).waitFor()
|
|
|
|
# schema.nim ファイルの存在確認
|
|
check fileExists(schemaFilePath)
|
|
|
|
# ファイル内容の検証
|
|
let schemaContent = readFile(schemaFilePath)
|
|
echo "schemaContent: ", schemaContent
|
|
check schemaContent.contains("type TestSchemaOutputTable* = object")
|
|
check schemaContent.contains("## test_schema_output")
|
|
check schemaContent.contains("integer*: int")
|
|
check schemaContent.contains("smallInteger*: int")
|
|
check schemaContent.contains("mediumInteger*: int")
|
|
check schemaContent.contains("bigInteger*: int")
|
|
check schemaContent.contains("decimal*: float")
|
|
check schemaContent.contains("double*: float")
|
|
check schemaContent.contains("float*: float")
|
|
check schemaContent.contains("uuid*: string")
|
|
check schemaContent.contains("char*: string")
|
|
check schemaContent.contains("string*: string")
|
|
check schemaContent.contains("text*: string")
|
|
check schemaContent.contains("mediumText*: string")
|
|
check schemaContent.contains("longText*: string")
|
|
check schemaContent.contains("date*: string")
|
|
check schemaContent.contains("datetime*: string")
|
|
check schemaContent.contains("time*: string")
|
|
check schemaContent.contains("timestamp*: string")
|
|
check schemaContent.contains("created_at*: string")
|
|
check schemaContent.contains("updated_at*: string")
|
|
check schemaContent.contains("deleted_at*: string")
|
|
check schemaContent.contains("binary*: string")
|
|
check schemaContent.contains("boolean*: bool")
|
|
check schemaContent.contains("enumField*: string")
|
|
check schemaContent.contains("json*: JsonNode")
|
|
check schemaContent.contains("int_relation_id*: int")
|
|
check schemaContent.contains("str_relation_id*: string")
|
|
|
|
|
|
clearTables(rdb).waitFor()
|
|
# schema.nim ファイルの削除
|
|
if fileExists(schemaFilePath):
|
|
removeFile(schemaFilePath)
|