Skip to content

Commit f4e6ffc

Browse files
authored
fix deprecation warnings and update documentation in SQL samples (GoogleCloudPlatform#5876)
1 parent 246de08 commit f4e6ffc

7 files changed

Lines changed: 17 additions & 17 deletions

File tree

cloud-sql/mysql/client-side-encryption/snippets/cloud_sql_connection_pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def init_tcp_connection_engine(
3030
pool = sqlalchemy.create_engine(
3131
# Equivalent URL:
3232
# mysql+pymysql://<db_user>:<db_pass>@<db_host>:<db_port>/<db_name>
33-
sqlalchemy.engine.url.URL(
33+
sqlalchemy.engine.url.URL.create(
3434
drivername="mysql+pymysql",
3535
username=db_user, # e.g. "my-database-user"
3636
password=db_pass, # e.g. "my-database-password"
@@ -57,7 +57,7 @@ def init_unix_connection_engine(
5757
pool = sqlalchemy.create_engine(
5858
# Equivalent URL:
5959
# mysql+pymysql://<db_user>:<db_pass>@/<db_name>?unix_socket=<socket_path>/<cloud_sql_instance_name>
60-
sqlalchemy.engine.url.URL(
60+
sqlalchemy.engine.url.URL.create(
6161
drivername="mysql+pymysql",
6262
username=db_user, # e.g. "my-database-user"
6363
password=db_pass, # e.g. "my-database-password"

cloud-sql/mysql/sqlalchemy/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export DB_SOCKET_DIR=/path/to/the/new/directory
8888
Use these terminal commands to initialize other environment variables as well:
8989
```bash
9090
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
91-
export INSTANCE_CONNECTION_NAME='<MY-PROJECT>:<INSTANCE-REGION>:<INSTANCE-NAME>'
91+
export CLOUD_SQL_CONNECTION_NAME='<MY-PROJECT>:<INSTANCE-REGION>:<INSTANCE-NAME>'
9292
export DB_USER='<DB_USER_NAME>'
9393
export DB_PASS='<DB_PASSWORD>'
9494
export DB_NAME='<DB_NAME>'
@@ -99,7 +99,7 @@ help keep secrets safe.
9999

100100
Then use this command to launch the proxy in the background:
101101
```bash
102-
./cloud_sql_proxy -dir=$DB_SOCKET_DIR --instances=$INSTANCE_CONNECTION_NAME --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
102+
./cloud_sql_proxy -dir=$DB_SOCKET_DIR --instances=$CLOUD_SQL_CONNECTION_NAME --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
103103
```
104104

105105
### Testing the application
@@ -168,8 +168,8 @@ Take note of the URL output at the end of the deployment process.
168168

169169
```sh
170170
gcloud run services update run-mysql \
171-
--add-cloudsql-instances [INSTANCE_CONNECTION_NAME] \
172-
--set-env-vars CLOUD_SQL_CONNECTION_NAME=[INSTANCE_CONNECTION_NAME],\
171+
--add-cloudsql-instances [CLOUD_SQL_CONNECTION_NAME] \
172+
--set-env-vars CLOUD_SQL_CONNECTION_NAME=[CLOUD_SQL_CONNECTION_NAME],\
173173
DB_USER=[MY_DB_USER],DB_PASS=[MY_DB_PASS],DB_NAME=[MY_DB]
174174
```
175175
Replace environment variables with the correct values for your Cloud SQL

cloud-sql/mysql/sqlalchemy/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def init_tcp_connection_engine(db_config):
8080
pool = sqlalchemy.create_engine(
8181
# Equivalent URL:
8282
# mysql+pymysql://<db_user>:<db_pass>@<db_host>:<db_port>/<db_name>
83-
sqlalchemy.engine.url.URL(
83+
sqlalchemy.engine.url.URL.create(
8484
drivername="mysql+pymysql",
8585
username=db_user, # e.g. "my-database-user"
8686
password=db_pass, # e.g. "my-database-password"
@@ -109,7 +109,7 @@ def init_unix_connection_engine(db_config):
109109
pool = sqlalchemy.create_engine(
110110
# Equivalent URL:
111111
# mysql+pymysql://<db_user>:<db_pass>@/<db_name>?unix_socket=<socket_path>/<cloud_sql_instance_name>
112-
sqlalchemy.engine.url.URL(
112+
sqlalchemy.engine.url.URL.create(
113113
drivername="mysql+pymysql",
114114
username=db_user, # e.g. "my-database-user"
115115
password=db_pass, # e.g. "my-database-password"

cloud-sql/postgres/client-side-encryption/snippets/cloud_sql_connection_pool.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def init_tcp_connection_engine(
3030
pool = sqlalchemy.create_engine(
3131
# Equivalent URL:
3232
# postgresql+pg8000://<db_user>:<db_pass>@<db_host>:<db_port>/<db_name>
33-
sqlalchemy.engine.url.URL(
33+
sqlalchemy.engine.url.URL.create(
3434
drivername="postgresql+pg8000",
3535
username=db_user, # e.g. "my-database-user"
3636
password=db_pass, # e.g. "my-database-password"
@@ -57,7 +57,7 @@ def init_unix_connection_engine(
5757
pool = sqlalchemy.create_engine(
5858
# Equivalent URL:
5959
# mpostgresql+pg8000://<db_user>:<db_pass>@/<db_name>?unix_socket=<socket_path>/<cloud_sql_instance_name>
60-
sqlalchemy.engine.url.URL(
60+
sqlalchemy.engine.url.URL.create(
6161
drivername="postgresql+pg8000",
6262
username=db_user, # e.g. "my-database-user"
6363
password=db_pass, # e.g. "my-database-password"

cloud-sql/postgres/sqlalchemy/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export DB_SOCKET_DIR=/path/to/the/new/directory
8787
Use these terminal commands to initialize other environment variables as well:
8888
```bash
8989
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service/account/key.json
90-
export INSTANCE_CONNECTION_NAME='<MY-PROJECT>:<INSTANCE-REGION>:<INSTANCE-NAME>'
90+
export CLOUD_SQL_CONNECTION_NAME='<MY-PROJECT>:<INSTANCE-REGION>:<INSTANCE-NAME>'
9191
export DB_USER='<DB_USER_NAME>'
9292
export DB_PASS='<DB_PASSWORD>'
9393
export DB_NAME='<DB_NAME>'
@@ -98,7 +98,7 @@ help keep secrets safe.
9898

9999
Then use this command to launch the proxy in the background:
100100
```bash
101-
./cloud_sql_proxy -dir=$DB_SOCKET_DIR --instances=$INSTANCE_CONNECTION_NAME --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
101+
./cloud_sql_proxy -dir=$DB_SOCKET_DIR --instances=$CLOUD_SQL_CONNECTION_NAME --credential_file=$GOOGLE_APPLICATION_CREDENTIALS &
102102
```
103103

104104
### Testing the application
@@ -166,8 +166,8 @@ Take note of the URL output at the end of the deployment process.
166166

167167
```sh
168168
gcloud run services update run-sql \
169-
--add-cloudsql-instances [INSTANCE_CONNECTION_NAME] \
170-
--set-env-vars CLOUD_SQL_CONNECTION_NAME=[INSTANCE_CONNECTION_NAME],\
169+
--add-cloudsql-instances [CLOUD_SQL_CONNECTION_NAME] \
170+
--set-env-vars CLOUD_SQL_CONNECTION_NAME=[CLOUD_SQL_CONNECTION_NAME],\
171171
DB_USER=[MY_DB_USER],DB_PASS=[MY_DB_PASS],DB_NAME=[MY_DB]
172172
```
173173
Replace environment variables with the correct values for your Cloud SQL

cloud-sql/sql-server/sqlalchemy/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def init_tcp_connection_engine(db_config):
9393
pool = sqlalchemy.create_engine(
9494
# Equivalent URL:
9595
# mssql+pytds://<db_user>:<db_pass>@/<host>:<port>/<db_name>?driver=ODBC+Driver+17+for+SQL+Server
96-
sqlalchemy.engine.url.URL(
96+
sqlalchemy.engine.url.URL.create(
9797
"mssql+pytds",
9898
username=db_user,
9999
password=db_pass,

run/idp-sql/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def init_tcp_connection_engine(
7676
pool = sqlalchemy.create_engine(
7777
# Equivalent URL:
7878
# postgres+pg8000://<db_user>:<db_pass>@<db_host>:<db_port>/<db_name>
79-
sqlalchemy.engine.url.URL(
79+
sqlalchemy.engine.url.URL.create(
8080
drivername="postgresql+pg8000",
8181
username=db_user, # e.g. "my-database-user"
8282
password=db_pass, # e.g. "my-database-password"
@@ -107,7 +107,7 @@ def init_unix_connection_engine(
107107
# Equivalent URL:
108108
# postgres+pg8000://<db_user>:<db_pass>@/<db_name>
109109
# ?unix_sock=<socket_path>/<cloud_sql_instance_name>/.s.PGSQL.5432
110-
sqlalchemy.engine.url.URL(
110+
sqlalchemy.engine.url.URL.create(
111111
drivername="postgresql+pg8000",
112112
username=db_user, # e.g. "my-database-user"
113113
password=db_pass, # e.g. "my-database-password"

0 commit comments

Comments
 (0)