feat(package): migrator: some migrate up works and init
This commit is contained in:
27
test/package/migrator/test/arguments.sh
Normal file
27
test/package/migrator/test/arguments.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
log notice "test case: ${WHITE}error: ambiguous command"
|
||||
set +e
|
||||
migrator --inherits tablename --inherits 'table name' list migrate
|
||||
error_code=$?
|
||||
set -e
|
||||
|
||||
if [ "$error_code" = 0 ]; then
|
||||
log error "test failed: ${WHITE}no error handler"
|
||||
exit 1
|
||||
elif [ "$error_code" != 2 ]; then
|
||||
log error "test failed: ${WHITE}unexpected error code"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test case: ${WHITE}error: ambiguous migrate command"
|
||||
set +e
|
||||
migrator --inherits tablename --inherits 'table name' migrate to up
|
||||
error_code=$?
|
||||
set -e
|
||||
|
||||
if [ "$error_code" = 0 ]; then
|
||||
log error "test failed: ${WHITE}no error handler"
|
||||
exit 1
|
||||
elif [ "$error_code" != 2 ]; then
|
||||
log error "test failed: ${WHITE}unexpected error code"
|
||||
exit 1
|
||||
fi
|
||||
76
test/package/migrator/test/init-migrator-with-inherits.sh
Normal file
76
test/package/migrator/test/init-migrator-with-inherits.sh
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/bin/dash
|
||||
|
||||
HECTIC_NAMESPACE=test-init-migrator
|
||||
|
||||
### CASE 1
|
||||
log notice "test case: ${WHITE}dry run"
|
||||
# NOTE: does not matter exist inherits tables or not, it must not connect to db
|
||||
|
||||
if ! migration_table_sql="$(migrator --inherits tablename --inherits 'table name' init --dry-run)"; then
|
||||
log error "test failed: ${WHITE}error on migration table init dry run"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s' "$migration_table_sql" | grep -Eq 'INHERITS[[:space:]]*\([[:space:]]*"tablename"[[:space:]]*,[[:space:]]*"table name"[[:space:]]*\)' ||
|
||||
{ log error "test failed: ${WHITE}not correct migration table inherits"; exit 1; }
|
||||
|
||||
### CASE 2
|
||||
log notice "test case: ${WHITE}error: table inherit tables that not exists"
|
||||
|
||||
set +e
|
||||
migrator --inherits tablename --inherits 'table name' init --db-url "$DATABASE_URL"
|
||||
error_code=$?
|
||||
set -e
|
||||
|
||||
if [ "$error_code" = 0 ]; then
|
||||
log error "test failed: ${WHITE}no error handler"
|
||||
exit 1
|
||||
elif [ "$error_code" != 5 ]; then
|
||||
log error "test failed: ${WHITE}unexpected error code"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### CASE 3
|
||||
log notice "test case: ${WHITE}error: not provided --db-url"
|
||||
set +e
|
||||
migrator --inherits tablename --inherits 'table name' init
|
||||
error_code=$?
|
||||
set -e
|
||||
|
||||
if [ "$error_code" = 0 ]; then
|
||||
log error "test failed: ${WHITE}no error handler"
|
||||
exit 1
|
||||
elif [ "$error_code" != 3 ]; then
|
||||
log error "test failed: ${WHITE}unexpected error code"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### CASE 4
|
||||
log notice "test case: ${WHITE}normal"
|
||||
|
||||
psql "$DATABASE_URL" -c 'CREATE TABLE "table name"(); CREATE TABLE tablename();'
|
||||
|
||||
if ! migrator --inherits tablename --inherits 'table name' init --db-url "$DATABASE_URL"; then
|
||||
log error "test failed: ${WHITE}error on init sql"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.migration'; then
|
||||
log error "test failed: ${WHITE} tabe hectic.migration was not created"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### CASE 5
|
||||
log notice "test case: ${WHITE}reinit (must just be ignored)"
|
||||
|
||||
if ! migrator --inherits tablename --inherits 'table name' init --db-url "$DATABASE_URL"; then
|
||||
log error "test failed: ${WHITE}error on init sql"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.migration'; then
|
||||
log error "test failed: ${WHITE} tabe hectic.migration was not created"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test passed"
|
||||
@@ -3,36 +3,17 @@
|
||||
HECTIC_NAMESPACE=test-init-migrator
|
||||
|
||||
### CASE 1
|
||||
log notice "test case: ${WHITE}table inherit tables that not exists"
|
||||
log notice "test case: ${WHITE}dry run"
|
||||
|
||||
if ! migration_table_sql="$(migrator --inherits tablename --inherits 'table name' init --dry-run)"; then
|
||||
if ! migration_table_sql="$(migrator init --dry-run)"; then
|
||||
log error "test failed: ${WHITE}error on migration table init dry run"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s' "$migration_table_sql" | grep -Eq 'INHERITS[[:space:]]*\([[:space:]]*"tablename"[[:space:]]*,[[:space:]]*"table name"[[:space:]]*\)' ||
|
||||
{ log error "test failed: ${WHITE}not correct migration table inherits"; exit 1; }
|
||||
|
||||
### CASE 2
|
||||
log notice "test case: ${WHITE}error: table inherit tables that not exists"
|
||||
|
||||
set +e
|
||||
migrator --inherits tablename --inherits 'table name' init --db-url "$DATABASE_URL"
|
||||
error_code=$?
|
||||
set -e
|
||||
|
||||
if [ "$error_code" = 0 ]; then
|
||||
log error "test failed: ${WHITE}no error handler"
|
||||
exit 1
|
||||
elif [ "$error_code" != 5 ]; then
|
||||
log error "test failed: ${WHITE}unexpected error code"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### CASE 3
|
||||
log notice "test case: ${WHITE}error: not provided --db-url"
|
||||
set +e
|
||||
migrator --inherits tablename --inherits 'table name' init
|
||||
migrator init
|
||||
error_code=$?
|
||||
set -e
|
||||
|
||||
@@ -45,14 +26,29 @@ elif [ "$error_code" != 3 ]; then
|
||||
fi
|
||||
|
||||
### CASE 4
|
||||
log notice "test case: ${WHITE}normal init"
|
||||
log notice "test case: ${WHITE}normal"
|
||||
|
||||
psql "$DATABASE_URL" -c 'CREATE TABLE "table name"(); CREATE TABLE tablename();'
|
||||
|
||||
if ! migrator --inherits tablename --inherits 'table name' init --db-url "$DATABASE_URL"; then
|
||||
if ! migrator --db-url "$DATABASE_URL" init; then
|
||||
log error "test failed: ${WHITE}error on init sql"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.migration'
|
||||
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.migration'; then
|
||||
log error "test failed: ${WHITE} tabe hectic.migration was not created"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
### CASE 5
|
||||
log notice "test case: ${WHITE}reinit (must just be ignored)"
|
||||
|
||||
if ! migrator init --db-url "$DATABASE_URL"; then
|
||||
log error "test failed: ${WHITE}error on init sql"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! psql -v ON_ERROR_STOP=1 "$DATABASE_URL" -c 'SELECT * FROM hectic.migration'; then
|
||||
log error "test failed: ${WHITE} tabe hectic.migration was not created"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log notice "test passed"
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
#!/bin/dash
|
||||
|
||||
HECTIC_NAMESPACE=test-migration-list
|
||||
|
||||
psql "$DATABASE_URL" 'CREATE TABLE profile (
|
||||
id INTEGER,
|
||||
username TEXT
|
||||
)'
|
||||
|
||||
#migrator migrate to 20251104192425-add-info-to-profile
|
||||
##!/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
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
-- nothing
|
||||
@@ -1 +0,0 @@
|
||||
-- nothing
|
||||
@@ -1 +0,0 @@
|
||||
-- nothing
|
||||
@@ -1 +0,0 @@
|
||||
-- nothing
|
||||
@@ -1 +0,0 @@
|
||||
-- nothing
|
||||
@@ -1 +0,0 @@
|
||||
-- nothing
|
||||
@@ -3,14 +3,49 @@
|
||||
HECTIC_NAMESPACE=test-migration-list
|
||||
|
||||
log notice "test case: ${WHITE}getting list of local migrations"
|
||||
if ! list="$(migrator list)"; then
|
||||
if ! result="$(migrator list --raw)"; then
|
||||
log error "test failed: ${WHITE}error during execution"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ls
|
||||
ls migration
|
||||
printf '%s' "$result" > result
|
||||
|
||||
exit 1
|
||||
printf '20251004192425-some-changes
|
||||
20251004292448-some-changes
|
||||
20251104172425-third-migration
|
||||
20251104192427-an-other-one
|
||||
20251104292469-almoust-last
|
||||
20251204152446-very-last' > expected
|
||||
|
||||
#printf 'result\n[\n%s\n]\n' "$(cat result)"
|
||||
#printf 'expected\n[\n%s\n]\n' "$(cat expected)"
|
||||
|
||||
diff -q result expected || {
|
||||
log error "test failed: ${WHITE}unexpected result"
|
||||
exit 1
|
||||
}
|
||||
|
||||
log notice "test case: ${WHITE}getting list of local migrations with info"
|
||||
if ! result="$(migrator list)"; then
|
||||
log error "test failed: ${WHITE}error during execution"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s' "$result" > result
|
||||
|
||||
printf '20251004192425-some-changes: missing up.sql down.sql
|
||||
20251004292448-some-changes
|
||||
20251104172425-third-migration: missing down.sql
|
||||
20251104192427-an-other-one: missing down.sql
|
||||
20251104292469-almoust-last
|
||||
20251204152446-very-last' > expected
|
||||
|
||||
#printf 'result\n[\n%s\n]\n' "$(cat result)"
|
||||
#printf 'expected\n[\n%s\n]\n' "$(cat expected)"
|
||||
|
||||
diff -q result expected || {
|
||||
log error "test failed: ${WHITE}unexpected result"
|
||||
exit 1
|
||||
}
|
||||
|
||||
log notice "test passed"
|
||||
|
||||
Reference in New Issue
Block a user