diff --git a/schema/0012_newtype.sql b/schema/0012_newtype.sql index 12c01cc..a6c9b6c 100644 --- a/schema/0012_newtype.sql +++ b/schema/0012_newtype.sql @@ -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; $$; diff --git a/scripts/build.sh b/scripts/build.sh index 9b2a508..c2ba1d6 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -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/{}"