I have connection issue between my spring boot/kotlin app and database. I tried following guides what google has to offer and some Stackoverflow posts. I added client/admin sql permisions to users. After following google guide https://github.com/spring-cloud/spring-cloud-gcp/tree/master/spring-cloud-gcp-samples/spring-cloud-gcp-sql-postgres-sample on this link and recreating everything as it is. I came to problem: deployed App does not connect to actual database, instead it uses data.sql and schema.sql objects from resources, also it does not do changes to actual database, but somewhere else, for example I am using this command to getdata:
@GetMapping("/getdata")
fun getTuples(): List<String>? {
return jdbcTemplate!!.queryForList("SELECT * FROM users").stream()
.map { m: Map<String?, Any?> -> m.values.toString() }
.collect(Collectors.toList())
}
result I get is the one provided in example:
0 "[luisao@example.com, Anderson, Silva]"
1 "[jonas@example.com, Jonas, Goncalves]"
2 "[fejsa@example.com, Ljubomir, Fejsa]"
the actual users table in Cloud database looks like this:
postgres=> select * from users;
email | first_name | last_name
--------------------+------------+-----------
luisao@example.com | Anderson | Silva
jonas@example.com | Jonas | Goncalves
fejsa@example.com | Ljubomir | Fejsa
kkskldk | sjndjfdf | skdskd
(4 rows)
first 3 rows are same just because I added them manually. App does not see DDL/DML changes in database, only those I do in data.sql or schema.sql. So the question is where could be a problem? in this documentation https://cloud.spring.io/spring-cloud-gcp/multi/multi__spring_jdbc.html says that this dependency should do most of the stuff automaticly but somehow something goes wrong. Could it be that spring boot/hikari creates virtual enviroment in appengine which blocks database connection and you connect and see only Mock data from data.sql files? Or problem lies in configuration? My application.properties file:
server.error.include-message=always
spring.cloud.gcp.sql.database-name=[database name]
spring.cloud.gcp.sql.instance-connection-name=[Instance name]
spring.datasource.continue-on-error=true
spring.datasource.initialization-mode=always
spring.datasource.username=postgres
spring.datasource.password=[password]
spring.cloud.gcp.project-id=[project id]