feat: add casts to+from text for text newtypes
Some checks failed
gen-migrations / gen-migrations (push) Failing after 7s

This commit is contained in:
Orion Kindel 2023-07-20 12:30:42 -05:00
parent 6700413593
commit 68cd9c5bb4
Signed by untrusted user who does not match committer: orion
GPG Key ID: 6D4165AE4C928719
2 changed files with 30 additions and 16 deletions

View File

@ -12,5 +12,15 @@ begin
, qualified_name || '_of_string(val text)'
, ' returns ' || qualified_name || E' language sql as \'select row(val);\';'
);
execute concat( 'create cast '
, ' (' || qualified_name || ' as text)'
, ' with function ' || qualified_name || E'_to_string(' || qualified_name || ')'
, ' as assignment;'
);
execute concat( 'create cast '
, ' (text as ' || qualified_name || ')'
, ' with function ' || qualified_name || E'_of_string(text)'
, ' as assignment;'
);
end;
$$;

View File

@ -8,15 +8,6 @@ source ./scripts/env.sh ./.env.schema
base_or_head="$1"
rev="$2"
docker compose kill "$base_or_head"
docker compose rm -vf "$base_or_head"
if [[ "$base_or_head" = "head" ]]; then
port=5433
else
port=5432
fi
db() {
echo -n "postgresql:///$1?port=$port&user=$POSTGRES_USER&password=$POSTGRES_PASSWORD"
}
@ -28,21 +19,34 @@ initdb() {
psql --quiet $(db postgres) -c "create database dnim"
}
if [[ -n "$base_or_head" ]]; then
docker compose kill "$base_or_head"
docker compose rm -vf "$base_or_head"
if [[ "$base_or_head" = "head" ]]; then
port=5433
else
port=5432
fi
fi
if [[ "$rev" = "empty" ]]; then
docker compose up --wait --wait-timeout 30 -d "$base_or_head"
initdb
exit 0
fi
git worktree remove --force "./$base_or_head" &>/dev/null || true
rm -rf "./$base_or_head" &>/dev/null || true
git worktree add "./$base_or_head" --detach "$rev" &>/dev/null
if [[ -n "$rev" ]]; then
git worktree remove --force "./$base_or_head" &>/dev/null || true
rm -rf "./$base_or_head" &>/dev/null || true
git worktree add "./$base_or_head" --detach "$rev" &>/dev/null
cp docker-compose.yml "./$base_or_head/docker-compose.yml"
cp .env.schema "./$base_or_head/.env.schema"
cp docker-compose.yml "./$base_or_head/docker-compose.yml"
cp .env.schema "./$base_or_head/.env.schema"
cd "./$base_or_head"
docker compose up --wait --wait-timeout 30 -d "$base_or_head"
cd "./$base_or_head"
fi
docker compose up --wait --wait-timeout 30 -d "${base_or_head:-head}"
initdb
ls ./schema/ | xargs -I{} bash -c "set -e; $(declare -f query_file); query_file \"$(db dnim)\" ./schema/{}"