feat(package): migrator: something
This commit is contained in:
18
flake.nix
18
flake.nix
@@ -66,15 +66,17 @@
|
|||||||
system,
|
system,
|
||||||
pkgs,
|
pkgs,
|
||||||
}: {
|
}: {
|
||||||
packages.${system} = import ./package { inherit flake self inputs pkgs system; };
|
packages.${system} = import ./package { inherit flake self inputs pkgs system; };
|
||||||
devShells.${system} = import ./devshell { inherit flake self inputs pkgs system; };
|
devShells.${system} = import ./devshell { inherit flake self inputs pkgs system; };
|
||||||
legacyPackages.${system} = import ./legacy { inherit flake self inputs pkgs system; };
|
legacyPackages.${system} = import ./legacy { inherit flake self inputs pkgs system; };
|
||||||
nixosConfigurations = { };
|
nixosConfigurations = {
|
||||||
checks.${system} = import ./test { inherit flake self inputs pkgs system; };
|
"xray|${system}" = import ./nixos/system/xray { inherit flake self inputs system; };
|
||||||
|
};
|
||||||
|
checks.${system} = import ./test { inherit flake self inputs pkgs system; };
|
||||||
}) // {
|
}) // {
|
||||||
lib = self-lib;
|
lib = self-lib;
|
||||||
overlays.default = import ./overlay { inherit flake self inputs; };
|
overlays.default = import ./overlay { inherit flake self inputs; };
|
||||||
nixosModules = import ./nixos/module { inherit flake self inputs; };
|
nixosModules = import ./nixos/module { inherit flake self inputs; };
|
||||||
templates = import ./template { inherit flake self inputs; };
|
templates = import ./template { inherit flake self inputs; };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
20
nixos/system/xray/default.nix
Normal file
20
nixos/system/xray/default.nix
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
flake,
|
||||||
|
self,
|
||||||
|
inputs,
|
||||||
|
system,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
# Use folder name as name of this system
|
||||||
|
name = builtins.baseNameOf ./.;
|
||||||
|
|
||||||
|
in self.lib.nixpkgs-lib.nixosSystem {
|
||||||
|
pkgs = import inputs.nixpkgs {
|
||||||
|
inherit system;
|
||||||
|
overlays = [ self.overlays.default ];
|
||||||
|
};
|
||||||
|
modules = [
|
||||||
|
{ networking.hostName = name; }
|
||||||
|
(import ./${name}.nix { inherit flake self inputs; })
|
||||||
|
];
|
||||||
|
}
|
||||||
47
nixos/system/xray/xray.nix
Normal file
47
nixos/system/xray/xray.nix
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
{
|
||||||
|
inputs,
|
||||||
|
flake,
|
||||||
|
self,
|
||||||
|
}: {
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
modulesPath,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
self.nixosModules.hectic
|
||||||
|
];
|
||||||
|
|
||||||
|
services.xray = {
|
||||||
|
enable = true;
|
||||||
|
setting = ''
|
||||||
|
{
|
||||||
|
"inbounds": [
|
||||||
|
{
|
||||||
|
"port": 10086,
|
||||||
|
"protocol": "vmess",
|
||||||
|
"settings": {
|
||||||
|
"clients": [
|
||||||
|
{
|
||||||
|
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outbounds": [
|
||||||
|
{
|
||||||
|
"protocol": "freedom"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
hectic = {
|
||||||
|
archetype.base.enable = true;
|
||||||
|
hardware.lenovo-legion.enable = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -143,7 +143,6 @@ in {
|
|||||||
migrator = pkgs.callPackage ./migrator {};
|
migrator = pkgs.callPackage ./migrator {};
|
||||||
nbt2json = pkgs.callPackage ./nbt2json {};
|
nbt2json = pkgs.callPackage ./nbt2json {};
|
||||||
hemar-parser = pkgs.callPackage ./hemar/parser {};
|
hemar-parser = pkgs.callPackage ./hemar/parser {};
|
||||||
hemar-grammar = pkgs.callPackage ./hemar/grammar {};
|
|
||||||
pg-17-ext-http = buildHttpExt pkgs "17";
|
pg-17-ext-http = buildHttpExt pkgs "17";
|
||||||
pg-17-ext-smtp-client = buildSmtpExt pkgs "17";
|
pg-17-ext-smtp-client = buildSmtpExt pkgs "17";
|
||||||
pg-17-ext-plhaskell = buildPlHaskellExt pkgs "17";
|
pg-17-ext-plhaskell = buildPlHaskellExt pkgs "17";
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ while [ $# -gt 0 ]; do
|
|||||||
case $1 in
|
case $1 in
|
||||||
migrate|create|fetch|list|init)
|
migrate|create|fetch|list|init)
|
||||||
[ "${SUBCOMMAND+x}" ] && {
|
[ "${SUBCOMMAND+x}" ] && {
|
||||||
log error "ambiguous subcommand, decide ${WHITE}$SUBCOMMAND ${NC}or ${WHITE}$1";
|
log error "ambiguous subcommand, decide ${WHITE}$SUBCOMMAND ${NC}or ${WHITE}$1";
|
||||||
exit 2;
|
exit 2;
|
||||||
}
|
}
|
||||||
SUBCOMMAND=$1
|
SUBCOMMAND=$1
|
||||||
shift
|
shift
|
||||||
@@ -71,7 +71,7 @@ init() {
|
|||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--set|-v)
|
--set|-v)
|
||||||
VARIABLE_LIST="${VARIABLE_LIST+$VARIABLE_LIST }$2"
|
VARIABLE_LIST="${VARIABLE_LIST+$VARIABLE_LIST }$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--*|-*)
|
--*|-*)
|
||||||
@@ -204,16 +204,16 @@ migrate_down() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--*|-*)
|
--*|-*)
|
||||||
printf 'migrate argument %s does not exists' "$1"
|
log error "\`migrate down\` argument $WHITE$1$NC does not exists"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
''|*[!0-9]*)
|
''|*[!0-9]*)
|
||||||
log error "down argument not a number";
|
log error "down argument not a number";
|
||||||
exit 1;
|
exit 1;
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
DOWN_NUMBER=$2
|
DOWN_NUMBER=$2
|
||||||
shift 2;
|
shift 2;
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -226,16 +226,16 @@ migrate_up() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--*|-*)
|
--*|-*)
|
||||||
printf 'migrate argument %s does not exists' "$1"
|
log error "\`migrate up\` argument $WHITE$1$NC does not exists"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
''|*[!0-9]*)
|
''|*[!0-9]*)
|
||||||
log error "up argument not a number";
|
log error "up argument not a number";
|
||||||
exit 1;
|
exit 1;
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
UP_NUMBER=$2
|
UP_NUMBER=$2
|
||||||
shift 2;
|
shift 2;
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
@@ -245,19 +245,24 @@ migrate_up() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
migrate_to() {
|
migrate_to() {
|
||||||
|
local migration_name
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--*|-*)
|
--*|-*)
|
||||||
printf 'migrate argument %s does not exists' "$1"
|
log error "\`migrate to\` argument $WHITE$1$NC does not exists"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
MIGRATION_NAME=
|
# shellcheck disable=SC2016
|
||||||
|
[ "${migration_name+x}" ] && { log error '`migrate to` too many arguments'; exit 1; }
|
||||||
|
migration_name=$1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[ "${MIGRATION_NAME+x}" ] || { log error "no migration name specified"; exit 1; }
|
[ "${migration_name+x}" ] || { log error "no migration name specified"; exit 1; }
|
||||||
|
printf '%s' "$migration_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
migration_list() {
|
migration_list() {
|
||||||
@@ -266,16 +271,18 @@ migration_list() {
|
|||||||
|
|
||||||
migrate() {
|
migrate() {
|
||||||
local fs_migrations db_migrations db_migration fs_migration psql_args var #target_migration
|
local fs_migrations db_migrations db_migration fs_migration psql_args var #target_migration
|
||||||
|
MIGRATOR_REMAINING_ARS=
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
|
log trace "migrate arg $WHITE$1"
|
||||||
case $1 in
|
case $1 in
|
||||||
up|down|to)
|
up|down|to)
|
||||||
[ "${MIGRATE_SUBCOMMAND+x}" ] && {
|
[ "${MIGRATE_SUBCOMMAND+x}" ] && {
|
||||||
log error "ambiguous migrate subcommand, decide ${WHITE}$MIGRATE_SUBCOMMAND ${NC}or ${WHITE}$1";
|
log error "ambiguous migrate subcommand, decide ${WHITE}$MIGRATE_SUBCOMMAND ${NC}or ${WHITE}$1";
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
MIGRATE_SUBCOMMAND="$1"
|
MIGRATE_SUBCOMMAND="$1"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--db-url|-u)
|
--db-url|-u)
|
||||||
DB_URL="$2"
|
DB_URL="$2"
|
||||||
@@ -286,14 +293,16 @@ migrate() {
|
|||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
--set|-v)
|
--set|-v)
|
||||||
VARIABLE_LIST="${VARIABLE_LIST+$VARIABLE_LIST }$2"
|
VARIABLE_LIST="${VARIABLE_LIST+$VARIABLE_LIST }$2"
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
--*|-*) REMAINING_ARS="$REMAINING_ARS $(quote "$1")"; shift ;; # unknown global -> pass through
|
--*|-*) MIGRATOR_REMAINING_ARS="$MIGRATOR_REMAINING_ARS $(quote "$1")"; shift ;; # unknown global -> pass through
|
||||||
*) REMAINING_ARS="$REMAINING_ARS $(quote "$1")"; shift ;;
|
*) MIGRATOR_REMAINING_ARS="$MIGRATOR_REMAINING_ARS $(quote "$1")"; shift ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
log debug "migrate REMAINING_ARGS: $WHITE$MIGRATOR_REMAINING_ARS"
|
||||||
|
|
||||||
[ "${FORCE+x}" ] && {
|
[ "${FORCE+x}" ] && {
|
||||||
log error "migrate --force not implemented"
|
log error "migrate --force not implemented"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -330,14 +339,24 @@ migrate() {
|
|||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
|
|
||||||
eval "set -- $REMAINING_ARS"
|
eval "set -- $MIGRATOR_REMAINING_ARS"
|
||||||
target_migration="$("migrate_$MIGRATE_SUBCOMMAND" "$@")"
|
target_migration="$("migrate_$MIGRATE_SUBCOMMAND" "$@")"
|
||||||
|
|
||||||
log debug "target_migration: ${target_migration}"
|
log debug "target_migration: ${target_migration}"
|
||||||
|
|
||||||
exit 1
|
index_of
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
idx_of() {
|
||||||
|
name=$1
|
||||||
|
[ -z "$name" ] && { echo 0; return; }
|
||||||
|
i=1
|
||||||
|
printf '%s\n' "$fs_migrations" | while IFS= read -r m; do
|
||||||
|
[ "$m" = "$name" ] && { echo "$i"; return; }
|
||||||
|
i=$((i+1))
|
||||||
|
done
|
||||||
|
echo 0
|
||||||
}
|
}
|
||||||
|
|
||||||
form_psql_args() {
|
form_psql_args() {
|
||||||
@@ -383,7 +402,7 @@ create() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--name|-n)
|
--name|-n)
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
MIGRATION_NAME=$2
|
MIGRATION_NAME=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
@@ -414,7 +433,7 @@ fetch() {
|
|||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
--db-url|-u)
|
--db-url|-u)
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
DB_URL=$2
|
DB_URL=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
|||||||
0
package/migrator/util.sh
Normal file
0
package/migrator/util.sh
Normal file
@@ -31,7 +31,7 @@
|
|||||||
) (lib.filterAttrs (_: v: v != null)
|
) (lib.filterAttrs (_: v: v != null)
|
||||||
(lib.mapAttrs (n: t: mkTestDrv n t) testDir));
|
(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}"
|
mkPgTest = testName: testDrv: pkgs.runCommand "hemar-test-${testName}"
|
||||||
{
|
{
|
||||||
nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused ];
|
nativeBuildInputs = [ pkgs.coreutils pkgs.gnugrep pkgs.gnused ];
|
||||||
|
|||||||
@@ -1,32 +1,32 @@
|
|||||||
answer="$(printf '%s' 'some text' | hemar -c)"
|
#answer="$(printf '%s' 'some text' | hemar -c)"
|
||||||
|
#
|
||||||
expected="$(printf '%s' '[
|
#expected="$(printf '%s' '[
|
||||||
{
|
# {
|
||||||
"type": "text",
|
# "type": "text",
|
||||||
"value": "some text"
|
# "value": "some text"
|
||||||
}
|
# }
|
||||||
]')"
|
#]')"
|
||||||
|
#
|
||||||
json_diff "$answer" "$expected"
|
#json_diff "$answer" "$expected"
|
||||||
|
#
|
||||||
answer="$(printf '%s' 'some [] {} text' | hemar -c)"
|
#answer="$(printf '%s' 'some [] {} text' | hemar -c)"
|
||||||
|
#
|
||||||
expected="$(printf '%s' '[
|
#expected="$(printf '%s' '[
|
||||||
{
|
# {
|
||||||
"type": "text",
|
# "type": "text",
|
||||||
"value": "some [] {} text"
|
# "value": "some [] {} text"
|
||||||
}
|
# }
|
||||||
]')"
|
#]')"
|
||||||
|
#
|
||||||
json_diff "$answer" "$expected"
|
#json_diff "$answer" "$expected"
|
||||||
|
#
|
||||||
answer="$(printf '%s' 'some {' | hemar -c)"
|
#answer="$(printf '%s' 'some {' | hemar -c)"
|
||||||
|
#
|
||||||
expected="$(printf '%s' '[
|
#expected="$(printf '%s' '[
|
||||||
{
|
# {
|
||||||
"type": "text",
|
# "type": "text",
|
||||||
"value": "some {"
|
# "value": "some {"
|
||||||
}
|
# }
|
||||||
]')"
|
#]')"
|
||||||
|
#
|
||||||
json_diff "$answer" "$expected"
|
#json_diff "$answer" "$expected"
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
answer="$(printf '%s' 'text begind {[ "inn \\e\"r"-t\"ext ]}' | hemar -c)"
|
#answer="$(printf '%s' 'text begind {[ "inn \\e\"r"-t\"ext ]}' | hemar -c)"
|
||||||
|
#
|
||||||
expected="$(printf '%s' '[
|
#expected="$(printf '%s' '[
|
||||||
{
|
# {
|
||||||
"type": "text",
|
# "type": "text",
|
||||||
"value": "text begind "
|
# "value": "text begind "
|
||||||
},
|
# },
|
||||||
{
|
# {
|
||||||
"type": "interpolation",
|
# "type": "interpolation",
|
||||||
"path": "inn \\e\"r-t\"ext"
|
# "path": "inn \\e\"r-t\"ext"
|
||||||
}
|
# }
|
||||||
]')"
|
#]')"
|
||||||
|
#
|
||||||
json_diff "$answer" "$expected"
|
#json_diff "$answer" "$expected"
|
||||||
|
#
|
||||||
[ "$(printf '%s' "$answer" | yq '.[1] | .path')" = 'inn \e"r-t"ext' ] || {
|
#[ "$(printf '%s' "$answer" | yq '.[1] | .path')" = 'inn \e"r-t"ext' ] || {
|
||||||
log error 'unexpected'
|
# log error 'unexpected'
|
||||||
exit 1
|
# exit 1
|
||||||
}
|
#}
|
||||||
|
#
|
||||||
answer="$(printf '%s' 'text begind {[ [" "] ]}' | hemar -c)"
|
#answer="$(printf '%s' 'text begind {[ [" "] ]}' | hemar -c)"
|
||||||
|
#
|
||||||
expected="$(printf '%s' '[
|
#expected="$(printf '%s' '[
|
||||||
{
|
# {
|
||||||
"type": "text",
|
# "type": "text",
|
||||||
"value": "text begind "
|
# "value": "text begind "
|
||||||
},
|
# },
|
||||||
{
|
# {
|
||||||
"type": "interpolation",
|
# "type": "interpolation",
|
||||||
"path": "[ ]"
|
# "path": "[ ]"
|
||||||
}
|
# }
|
||||||
]')"
|
#]')"
|
||||||
|
#
|
||||||
json_diff "$answer" "$expected"
|
#json_diff "$answer" "$expected"
|
||||||
|
#
|
||||||
answer="$(printf '%s' 'text begind {[ [" "\ ] ]}' | hemar -c)"
|
#answer="$(printf '%s' 'text begind {[ [" "\ ] ]}' | hemar -c)"
|
||||||
|
#
|
||||||
json_diff "$answer" "$expected"
|
#json_diff "$answer" "$expected"
|
||||||
|
|||||||
@@ -39,6 +39,8 @@
|
|||||||
} ''
|
} ''
|
||||||
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
|
${builtins.readFile self.legacyPackages.${system}.helpers.posix-shell.log}
|
||||||
test=${testDrv}
|
test=${testDrv}
|
||||||
|
export HECTIC_LOG=trace
|
||||||
|
${builtins.readFile ./util.sh}
|
||||||
${builtins.readFile ./lauch.sh}
|
${builtins.readFile ./lauch.sh}
|
||||||
|
|
||||||
# success marker for Nix
|
# success marker for Nix
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
##!/bin/dash
|
#!/bin/dash
|
||||||
#
|
|
||||||
#HECTIC_NAMESPACE=test-migration-list
|
HECTIC_NAMESPACE=test-migration-list
|
||||||
#
|
|
||||||
#psql "$DATABASE_URL" 'CREATE TABLE profile (
|
|
||||||
# id INTEGER,
|
|
||||||
# username TEXT
|
log notice "test case: ${WHITE}migration up"
|
||||||
#)'
|
psql "$DATABASE_URL" 'CREATE TABLE profile (
|
||||||
#
|
id INTEGER,
|
||||||
#migrator --db-url "$DATABASE_URL" migrate to 20251104192425-add-info-to-profile
|
username TEXT
|
||||||
#
|
)'
|
||||||
#exit 1
|
|
||||||
|
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
|
||||||
|
|||||||
8
test/package/migrator/util.sh
Normal file
8
test/package/migrator/util.sh
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# columns(table)
|
||||||
|
columns() {
|
||||||
|
psql -Atc 'SELECT column_name
|
||||||
|
FROM information_schema.columns
|
||||||
|
WHERE table_name = '"${1};"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user