Skip to content

Commit

Permalink
Update SQL (#451)
Browse files Browse the repository at this point in the history
* Update SQL

1. Use filtering to set variables.
2. Update README

I was unable to get SQL proxy working so we can’t really do IT testing
yet.
  • Loading branch information
lesv authored Dec 14, 2016
1 parent b9ee31d commit 4a697a9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
26 changes: 19 additions & 7 deletions appengine/cloudsql/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
# Cloud SQL sample for Google App Engine
This sample demonstrates how to use [Cloud SQL](https://cloud.google.com/sql/) on Google App Engine

## Setup
Before you can run or deploy the sample, you will need to create a [Cloud SQL instance](https://cloud.google.com/sql/docs/create-instance)
1. Create a new user and database for the application. The easiest way to do this is via the [Google Developers Console](https://console.developers.google.com/project/_/sql/instances/example-instance2/access-control/users). Alternatively, you can use MySQL tools such as the command line client or workbench.
Before you can run or deploy the sample, you will need to create a [Cloud SQL instance)](https://cloud.google.com/sql/docs/create-instance)

1. Create a new user and database for the application. The easiest way to do this is via the [Google
Developers Console](https://console.developers.google.com/sql/instances). Alternatively, you can use MySQL tools such as the command line client or workbench.
2. Change the root password (under Access Control) and / or create a new user / password.
3. Create a Database (under Databases) (or use MySQL with `gcloud sql connect <instance> --user=root`)
4. Note the **Instance connection name** under Overview > properties
(It will look like project:instance for v1 or project:region:zone for v2)

## Deploying

`$ mvn clean appengine:deploy -DINSTANCE_CONNECTION_NAME="instanceConnectionName" -Duser=root
-Dpassword=myPassword -Ddatabase=myDatabase`

Or you can update the properties in `pom.xml` and

## Running locally
1. You will need to be running a local instance of MySQL.
1. Update the connection string in ``appengine-web.xml`` with your local MySQL instance values.
<br/>`$ mvn clean appengine:devserver`

## Deploying
1. Update the connection string in ``appengine-web.xml`` with your Cloud SQL instance values.
<br/>`$ mvn clean appengine:update`
`$ mvn clean appengine:run -Duser=root -Dpassword=myPassowrd -Ddatabase=myDatabase`

56 changes: 42 additions & 14 deletions appengine/cloudsql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,69 @@
<relativePath>../..</relativePath>
</parent>

<!-- [START properties] -->
<properties>
<!-- INSTANCE_CONNECTION_NAME from Cloud Console > SQL > Instance Details > Properties
or gcloud sql instances describe <instance>
project:region:instance for Cloud SQL v2 or
project:instance for Cloud SQL v1
-->
<INSTANCE_CONNECTION_NAME></INSTANCE_CONNECTION_NAME>
<user>root</user>
<password></password>
<database></database>

<!-- [START_EXCLUDE] -->
<appengine.maven.plugin>1.0.0</appengine.maven.plugin>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<!-- [END_EXCLUDE] -->
</properties>
<!-- [END properties] -->
<dependencies>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>mysql-socket-factory</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<!-- [START dependencies] -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.5</version>
</dependency>

<!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
</dependency>

<!-- [START dependencies] -->
<dependency> <!-- ONLY USED LOCALY -->
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version> <!-- v5.x.x is Java 7, v6.x.x is Java 8 -->
</dependency>
<!-- [END dependencies] -->
</dependencies>
<build>
<!-- for hot reload of the web application -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<resources>
<resource>
<directory>src/webapp/WEB-INF</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin}</version>
</plugin>
<!--
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.sdk.version}</version>
</plugin>
-->
</plugins>
</build>
</project>
6 changes: 2 additions & 4 deletions appengine/cloudsql/src/main/webapp/WEB-INF/appengine-web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
-->
<!-- [START config] -->
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
<application>YOUR-PROJECT-ID</application>
<version>YOUR-VERSION-ID</version>
<threadsafe>true</threadsafe>
<use-google-connector-j>true</use-google-connector-j>
<system-properties>
<property name="ae-cloudsql.cloudsql-database-url" value="jdbc:google:mysql://[INSTANCE_CONNECTION_NAME]/DATABASE-NAME?user=USERNAME&amp;password=PASSWORD" />
<property name="ae-cloudsql.local-database-url" value="jdbc:mysql://localhost/DATABASE-NAME?user=USERNAME&amp;PASSWORD=password&amp;useSSL=false" />
<property name="ae-cloudsql.cloudsql-database-url" value="jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&amp;password=${password}" />
<property name="ae-cloudsql.local-database-url" value="jdbc:mysql://localhost/${database}?user=${user}&amp;PASSWORD=${password}&amp;useSSL=false" />
</system-properties>
</appengine-web-app>
<!-- [END config] -->

0 comments on commit 4a697a9

Please sign in to comment.