Created
December 1, 2017 21:34
-
-
Save mchmarny/2222e8aaa12c281165e9b1c3be7367cb to your computer and use it in GitHub Desktop.
How to create Cloud Spanner database from long DDL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Cloud Spanner does supports DDL operations but to load a real (long) DDL | |
| # you will wanna use something similar to this script to parse each command | |
| # Define path to your DDL | |
| # export SPANNER_DB_DDL="./tpch-v2-17-3.ddl" | |
| echo 'Loading DDL...' | |
| echo 'NOTE: empty @type property warning on return protobuf message are OK' | |
| DDL=`cat ${SPANNER_DB_DDL} | tr -d '\n' | tr -d '\r' | tr -d '\t'` | |
| IFS=';' read -ra LINES <<< "$DDL" | |
| for SQL in "${LINES[@]}"; do | |
| # echo $SQL | |
| if [ ${#SQL} -ge 5 ]; then | |
| gcloud spanner databases ddl update $SPANNER_DB --instance=$SPANNER_INSTANCE --ddl="$SQL" | |
| fi | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, you can navigate to the Cloud Spanner UI and paste the long DDL there