Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SQL #451

Merged
merged 3 commits into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update the link to point to the cloud console.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with the link?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be https://console.cloud.google.com/sql/instances Remember console.developers.google.com just has the API manager now and no cloud stuff.

2. Change the root password (under Access Control) and / or create a new user / password.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't create dbs or users from the cloud console with v2 instances yet, AFAIK.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I can. Maybe not yet deployed?

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but I prefer the 4-space indent or

code blocks with three ```

Also, it's a bit funny to see a property name that isn't camelCase such as INSTANCE_CONNCETION_NAME but probably fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally yes, but I really want to call attention to it.

-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] -->