feat(package): migrator: something

This commit is contained in:
2025-12-04 21:02:38 +00:00
parent dfa76b2a19
commit b786098867
12 changed files with 226 additions and 120 deletions

View File

@@ -31,7 +31,7 @@
) (lib.filterAttrs (_: v: v != null)
(lib.mapAttrs (n: t: mkTestDrv n t) testDir));
hemar = self.packages.${system}.hemar;
hemar = self.packages.${system}.hemar-parser;
mkPgTest = testName: testDrv: pkgs.runCommand "hemar-test-${testName}"
{
nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused ];

View File

@@ -1,32 +1,32 @@
answer="$(printf '%s' 'some text' | hemar -c)"
expected="$(printf '%s' '[
{
"type": "text",
"value": "some text"
}
]')"
json_diff "$answer" "$expected"
answer="$(printf '%s' 'some [] {} text' | hemar -c)"
expected="$(printf '%s' '[
{
"type": "text",
"value": "some [] {} text"
}
]')"
json_diff "$answer" "$expected"
answer="$(printf '%s' 'some {' | hemar -c)"
expected="$(printf '%s' '[
{
"type": "text",
"value": "some {"
}
]')"
json_diff "$answer" "$expected"
#answer="$(printf '%s' 'some text' | hemar -c)"
#
#expected="$(printf '%s' '[
# {
# "type": "text",
# "value": "some text"
# }
#]')"
#
#json_diff "$answer" "$expected"
#
#answer="$(printf '%s' 'some [] {} text' | hemar -c)"
#
#expected="$(printf '%s' '[
# {
# "type": "text",
# "value": "some [] {} text"
# }
#]')"
#
#json_diff "$answer" "$expected"
#
#answer="$(printf '%s' 'some {' | hemar -c)"
#
#expected="$(printf '%s' '[
# {
# "type": "text",
# "value": "some {"
# }
#]')"
#
#json_diff "$answer" "$expected"

View File

@@ -1,38 +1,38 @@
answer="$(printf '%s' 'text begind {[ "inn \\e\"r"-t\"ext ]}' | hemar -c)"
expected="$(printf '%s' '[
{
"type": "text",
"value": "text begind "
},
{
"type": "interpolation",
"path": "inn \\e\"r-t\"ext"
}
]')"
json_diff "$answer" "$expected"
[ "$(printf '%s' "$answer" | yq '.[1] | .path')" = 'inn \e"r-t"ext' ] || {
log error 'unexpected'
exit 1
}
answer="$(printf '%s' 'text begind {[ [" "] ]}' | hemar -c)"
expected="$(printf '%s' '[
{
"type": "text",
"value": "text begind "
},
{
"type": "interpolation",
"path": "[ ]"
}
]')"
json_diff "$answer" "$expected"
answer="$(printf '%s' 'text begind {[ [" "\ ] ]}' | hemar -c)"
json_diff "$answer" "$expected"
#answer="$(printf '%s' 'text begind {[ "inn \\e\"r"-t\"ext ]}' | hemar -c)"
#
#expected="$(printf '%s' '[
# {
# "type": "text",
# "value": "text begind "
# },
# {
# "type": "interpolation",
# "path": "inn \\e\"r-t\"ext"
# }
#]')"
#
#json_diff "$answer" "$expected"
#
#[ "$(printf '%s' "$answer" | yq '.[1] | .path')" = 'inn \e"r-t"ext' ] || {
# log error 'unexpected'
# exit 1
#}
#
#answer="$(printf '%s' 'text begind {[ [" "] ]}' | hemar -c)"
#
#expected="$(printf '%s' '[
# {
# "type": "text",
# "value": "text begind "
# },
# {
# "type": "interpolation",
# "path": "[ ]"
# }
#]')"
#
#json_diff "$answer" "$expected"
#
#answer="$(printf '%s' 'text begind {[ [" "\ ] ]}' | hemar -c)"
#
#json_diff "$answer" "$expected"

View File

@@ -39,6 +39,8 @@
} ''
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
test=${testDrv}
export HECTIC_LOG=trace
${builtins.readFile ./util.sh}
${builtins.readFile ./lauch.sh}
# success marker for Nix

View File

@@ -1,12 +1,21 @@
##!/bin/dash
#
#HECTIC_NAMESPACE=test-migration-list
#
#psql "$DATABASE_URL" 'CREATE TABLE profile (
# id INTEGER,
# username TEXT
#)'
#
#migrator --db-url "$DATABASE_URL" migrate to 20251104192425-add-info-to-profile
#
#exit 1
#!/bin/dash
HECTIC_NAMESPACE=test-migration-list
log notice "test case: ${WHITE}migration up"
psql "$DATABASE_URL" 'CREATE TABLE profile (
id INTEGER,
username TEXT
)'
if ! migrator --db-url "$DATABASE_URL" migrate to 20251104192425-add-info-to-profile; then
log error "test failed: ${WHITE}error on migration up"
exit 1
fi
log notice "$(columns profile)"
exit 1

View File

@@ -0,0 +1,8 @@
#!/bin/bash
# columns(table)
columns() {
psql -Atc 'SELECT column_name
FROM information_schema.columns
WHERE table_name = '"${1};"
}