Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Created April 21, 2022 08:16
Show Gist options
  • Save tkuchiki/57b6a3d5972e63daba562f0cc566be3e to your computer and use it in GitHub Desktop.
Save tkuchiki/57b6a3d5972e63daba562f0cc566be3e to your computer and use it in GitHub Desktop.
Drop Spanner tables
$ bash drop-spanner-tables.sh <your project> <your spanner instance> <your spanner database>
#!/bin/bash
project="${1}"
instance="${2}"
database="${3}"
tables="SELECT
table_name
FROM
information_schema.tables
WHERE
table_schema = ''"
for table in $(gcloud --project=${project} spanner databases execute-sql ${database} --instance=${instance} --sql="${tables}" | awk 'NR>1'); do
gcloud --project=${project} spanner databases execute-sql ${database} --instance=${instance} --sql="DROP TABLE ${table}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment