2021-07-01 17:40:05 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# functions common to dev.sh (local testing) and test-server.sh (CI tests)
|
|
|
|
function add_sources() {
|
|
|
|
hasura_graphql_server_port=${1:-8181}
|
|
|
|
|
|
|
|
# always add a Postgres source for metadata, at least
|
|
|
|
add_postgres_source "$hasura_graphql_server_port" "$PG_DB_URL"
|
|
|
|
|
|
|
|
case "$BACKEND" in
|
|
|
|
citus)
|
|
|
|
add_citus_source "$hasura_graphql_server_port" "$CITUS_DB_URL"
|
|
|
|
;;
|
|
|
|
mssql)
|
2021-09-09 10:59:04 +03:00
|
|
|
add_mssql_source "$hasura_graphql_server_port" "$MSSQL_CONN_STR"
|
2021-07-01 17:40:05 +03:00
|
|
|
;;
|
2021-07-21 20:22:08 +03:00
|
|
|
mysql)
|
2021-10-01 21:29:03 +03:00
|
|
|
add_mysql_source "$hasura_graphql_server_port"
|
|
|
|
;;
|
|
|
|
bigquery)
|
|
|
|
add_bigquery_source "$hasura_graphql_server_port"
|
2021-07-21 20:22:08 +03:00
|
|
|
;;
|
2021-07-01 17:40:05 +03:00
|
|
|
esac
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_postgres_source() {
|
|
|
|
hasura_graphql_server_port=${1}
|
|
|
|
db_url=${2}
|
|
|
|
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Adding Postgres source"
|
2022-06-08 18:31:28 +03:00
|
|
|
# FIXME: Without a loop here `dev.sh test` fails for me here. With the loop
|
|
|
|
# I get “source with name \"default\" already exists”
|
|
|
|
until curl -s "$metadata_url" \
|
|
|
|
--data-raw '{"type":"pg_add_source","args":{"name":"default","configuration":{"connection_info":{"database_url":"'"$db_url"'"}}}}'; &>/dev/null; do
|
|
|
|
echo -n '.' && sleep 0.2
|
|
|
|
done
|
|
|
|
echo " Ok"
|
2021-07-01 17:40:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_citus_source() {
|
|
|
|
hasura_graphql_server_port=${1}
|
|
|
|
db_url=${2}
|
|
|
|
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Adding Citus source"
|
2021-10-12 20:58:46 +03:00
|
|
|
curl --fail "$metadata_url" \
|
2021-07-01 17:40:05 +03:00
|
|
|
--data-raw '{"type":"citus_add_source","args":{"name":"citus","configuration":{"connection_info":{"database_url":"'"$db_url"'"}}}}'
|
|
|
|
}
|
|
|
|
|
|
|
|
function add_mssql_source() {
|
|
|
|
hasura_graphql_server_port=${1}
|
|
|
|
connection_string=${2}
|
|
|
|
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Adding SQL Server source"
|
2021-10-12 20:58:46 +03:00
|
|
|
curl --fail "$metadata_url" \
|
2021-07-01 17:40:05 +03:00
|
|
|
--data-raw '{"type":"mssql_add_source","args":{"name":"mssql","configuration":{"connection_info":{"connection_string":"'"$connection_string"'"}}}}'
|
|
|
|
}
|
2021-07-21 20:22:08 +03:00
|
|
|
|
|
|
|
function add_mysql_source() {
|
|
|
|
hasura_graphql_server_port=${1}
|
|
|
|
# connection_string currently unused as mysql_add_source not yet supported
|
|
|
|
# connection_string=${2}
|
|
|
|
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Adding MySQL source"
|
2021-10-12 20:58:46 +03:00
|
|
|
curl --fail "$metadata_url" \
|
2021-07-21 20:22:08 +03:00
|
|
|
--data-raw '{"type":"replace_metadata","args":{"version":3,"sources":[{"name":"mysql","kind":"mysql","tables":[],"configuration":{"database":"hasura","user":"'"$MYSQL_USER"'","password":"'"$MYSQL_PASSWORD"'","host":"127.0.0.1","port":'"$MYSQL_PORT"',"pool_settings":{}}}]}}'
|
|
|
|
}
|
2021-08-12 19:47:33 +03:00
|
|
|
|
2021-10-01 21:29:03 +03:00
|
|
|
function add_bigquery_source() {
|
|
|
|
hasura_graphql_server_port=${1}
|
|
|
|
metadata_url=http://127.0.0.1:$hasura_graphql_server_port/v1/metadata
|
|
|
|
|
|
|
|
echo ""
|
2022-02-21 14:44:13 +03:00
|
|
|
echo "Adding BigQuery sources to project $HASURA_BIGQUERY_PROJECT_ID"
|
2021-10-12 20:58:46 +03:00
|
|
|
curl --fail "$metadata_url" \
|
2021-10-01 21:29:03 +03:00
|
|
|
--data-raw '
|
|
|
|
{
|
|
|
|
"type": "replace_metadata",
|
|
|
|
"args": {
|
|
|
|
"metadata": {
|
|
|
|
"version": 3,
|
|
|
|
"sources": [
|
2021-10-12 20:58:46 +03:00
|
|
|
{
|
|
|
|
"name": "bigquery",
|
|
|
|
"kind": "bigquery",
|
|
|
|
"tables": [],
|
|
|
|
"configuration": {
|
|
|
|
"service_account": {
|
2022-03-14 10:49:36 +03:00
|
|
|
"from_env": "HASURA_BIGQUERY_SERVICE_KEY"
|
2021-10-12 20:58:46 +03:00
|
|
|
},
|
|
|
|
"project_id": { "from_env": "HASURA_BIGQUERY_PROJECT_ID" },
|
2022-02-14 09:22:11 +03:00
|
|
|
"datasets": ["hasura"]
|
2021-10-12 20:58:46 +03:00
|
|
|
}
|
|
|
|
},
|
2021-11-24 19:21:59 +03:00
|
|
|
{
|
|
|
|
"name": "bigquery2",
|
|
|
|
"kind": "bigquery",
|
|
|
|
"tables": [],
|
|
|
|
"configuration": {
|
|
|
|
"service_account": {
|
2022-03-14 10:49:36 +03:00
|
|
|
"from_env": "HASURA_BIGQUERY_SERVICE_KEY"
|
2021-11-24 19:21:59 +03:00
|
|
|
},
|
|
|
|
"project_id": { "from_env": "HASURA_BIGQUERY_PROJECT_ID" },
|
2022-02-14 09:22:11 +03:00
|
|
|
"datasets": ["hasura"]
|
2021-11-24 19:21:59 +03:00
|
|
|
}
|
|
|
|
},
|
2021-10-01 21:29:03 +03:00
|
|
|
{
|
|
|
|
"name": "hasura_global_limited",
|
|
|
|
"kind": "bigquery",
|
|
|
|
"tables": [],
|
|
|
|
"configuration": {
|
|
|
|
"global_select_limit": 1,
|
|
|
|
"service_account": {
|
2022-03-14 10:49:36 +03:00
|
|
|
"from_env": "HASURA_BIGQUERY_SERVICE_KEY"
|
2021-10-01 21:29:03 +03:00
|
|
|
},
|
|
|
|
"project_id": { "from_env": "HASURA_BIGQUERY_PROJECT_ID" },
|
2022-02-14 09:22:11 +03:00
|
|
|
"datasets": ["hasura"]
|
2021-10-01 21:29:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
'
|
|
|
|
}
|