Skip to content

Commit

Permalink
cloud: Extract bigquery.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
spbnick committed Jan 15, 2024
1 parent 9c6104e commit e25b8fb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 39 deletions.
40 changes: 1 addition & 39 deletions cloud
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PATH="$(dirname "$(realpath "$0")")/kcidb/cloud:$PATH"

. submitters.sh
. sections.sh
. bigquery.sh
. psql.sh
. pubsub.sh
. firestore.sh
Expand All @@ -37,45 +38,6 @@ function services_enable() {
mute gcloud services enable --quiet --project="$project" "${names[@]}"
}

# Deploy to BigQuery
# Do not initialize datasets that are prepended with the hash sign ('#').
# Args: project dataset...
function bigquery_deploy() {
declare -r project="$1"; shift
declare dataset
declare init
for dataset in "$@"; do
# Handle possible leading hash sign
if [[ $dataset == \#* ]]; then
dataset="${dataset:1}"
init=false
else
init=true
fi
mute bq mk --project_id="$project" --force "$dataset"
if "$init"; then
kcidb-db-init -lDEBUG -d "bigquery:${project}.${dataset}" \
--ignore-initialized
fi
done
}

# Withdraw from BigQuery
# Cleanup all datasets, even those prepended with the hash sign ('#').
# Args: project dataset...
function bigquery_withdraw() {
declare -r project="$1"; shift
declare dataset
for dataset in "$@"; do
# Ignore possible leading hash sign
dataset="${dataset###}"
kcidb-db-cleanup -lDEBUG -d "bigquery:${project}.${dataset}" \
--ignore-not-initialized \
--ignore-not-found
mute bq rm --project_id="$project" --force "$dataset"
done
}

# Check if the App Engine app exists.
# Args: project
# Output: "true" if the app exists, "false" otherwise.
Expand Down
47 changes: 47 additions & 0 deletions kcidb/cloud/bigquery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# KCIDB cloud deployment - BigQuery
#
if [ -z "${_BIGQUERY_SH+set}" ]; then
declare _BIGQUERY_SH=

. misc.sh

# Deploy to BigQuery
# Do not initialize datasets that are prepended with the hash sign ('#').
# Args: project dataset...
function bigquery_deploy() {
declare -r project="$1"; shift
declare dataset
declare init
for dataset in "$@"; do
# Handle possible leading hash sign
if [[ $dataset == \#* ]]; then
dataset="${dataset:1}"
init=false
else
init=true
fi
mute bq mk --project_id="$project" --force "$dataset"
if "$init"; then
kcidb-db-init -lDEBUG -d "bigquery:${project}.${dataset}" \
--ignore-initialized
fi
done
}

# Withdraw from BigQuery
# Cleanup all datasets, even those prepended with the hash sign ('#').
# Args: project dataset...
function bigquery_withdraw() {
declare -r project="$1"; shift
declare dataset
for dataset in "$@"; do
# Ignore possible leading hash sign
dataset="${dataset###}"
kcidb-db-cleanup -lDEBUG -d "bigquery:${project}.${dataset}" \
--ignore-not-initialized \
--ignore-not-found
mute bq rm --project_id="$project" --force "$dataset"
done
}

fi # _BIGQUERY_SH

0 comments on commit e25b8fb

Please sign in to comment.