-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add postgres samples #396
Add postgres samples #396
Conversation
Codecov Report
@@ Coverage Diff @@
## master #396 +/- ##
=======================================
Coverage 83.88% 83.88%
=======================================
Files 4 4
Lines 422 422
=======================================
Hits 354 354
Misses 68 68 Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this PR is missing an update to the app.yaml file?
Also, why not collapse the MYSQL_ and POSTGRES_ environment variables in variables that are more generic, like DB_USER, DB_PASSWORD, etc. so you don't have to document two sets of variables? The one variable that would control which database to use would be that SQL_CLIENT variable.
], | ||
"msg": "Last 10 visits:", | ||
"args": ["server.js"] | ||
}, | ||
"deploy": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this configuration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line below it seems to be MySQL-specific environment variables - but if we use the same environment variables for both clients, then I'll add it back in + update it accordingly.
appengine/cloudsql/server.js
Outdated
const crypto = require('crypto'); | ||
|
||
const app = express(); | ||
app.enable('trust proxy'); | ||
// [END setup] | ||
let knex; | ||
|
||
function connectMysql () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this can be simplified, do we really need two different connection methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering about this as well. The only difference between these two is the client (mysql
vs pg
), but I wanted two discrete, 'copy-and-paste' samples for both SQL options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think you only need one connection method. Just set client
in the Knex options to process.env.SQL_CLIENT
, then the docs just need to tell the user to set the SQL_CLIENT
env var.
FYI, the "samples test app" failure is likely due to some configuration (or configuration-processing) issue. @jmdobry see trace below, or let me know if you want me to dig further into it.
|
appengine/cloudsql/server.js
Outdated
const crypto = require('crypto'); | ||
|
||
const app = express(); | ||
app.enable('trust proxy'); | ||
// [END setup] | ||
let knex; | ||
|
||
function connectMysql () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think you only need one connection method. Just set client
in the Knex options to process.env.SQL_CLIENT
, then the docs just need to tell the user to set the SQL_CLIENT
env var.
appengine/cloudsql/README.md
Outdated
mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%'; | ||
mysql> create database `YOUR_DATABASE`; | ||
mysql> create user 'YOUR_USER'@'%' identified by 'PASSWORD'; | ||
mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%'; | ||
|
||
1. Set the `MYSQL_USER`, `MYSQL_PASSWORD`, and `MYSQL_DATABASE` environment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These env vars need to be updated to the generic ones.
appengine/cloudsql/README.md
Outdated
1. Update the values in in `app.yaml` with your instance configuration. | ||
export POSTGRES_USER="..." | ||
export POSTGRES_PASSWORD="..." | ||
export POSTGRES_DATABASE="..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These env vars need to be updated to the generic ones.
appengine/cloudsql/README.md
Outdated
|
||
export MYSQL_USER="..." | ||
export MYSQL_PASSWORD="..." | ||
export MYSQL_DATABASE="..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These env vars need to be updated to the generic ones.
appengine/cloudsql/README.md
Outdated
Then, create a user (using the button in the *Access Control* > *Users* tab) and a | ||
database (using the button in the *Databases* tab). | ||
|
||
1. Set the `POSTGRES_USER`, `POSTGRES_PASSWORD`, and `POSTGRES_DATABASE` environment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These env vars need to be updated to the generic ones.
appengine/cloudsql/README.md
Outdated
mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%'; | ||
mysql> create database `YOUR_DATABASE`; | ||
mysql> create user 'YOUR_USER'@'%' identified by 'PASSWORD'; | ||
mysql> grant all on YOUR_DATABASE.* to 'YOUR_USER'@'%'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary still? The postgres docs below indicate this can all be done with the Cloud Console.
appengine/cloudsql/createTables.js
Outdated
console.log(result); | ||
// Connect to the database | ||
return resolve(Knex({ | ||
client: 'mysql', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, I think we only need one connection method, just set the client
Knex option to process.env.SQL_CLIENT
.
appengine/cloudsql/createTables.js
Outdated
// [END postgresMain] | ||
}; | ||
|
||
exports.mysqlMain = function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only need one main function
appengine/cloudsql/createTables.js
Outdated
|
||
// Get type of SQL client to use | ||
const sqlClient = process.env.SQL_CLIENT; | ||
if (sqlClient === 'pg') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for conditional if we just rely on passing process.env.SQL_CLIENT
to the Knex constructor
appengine/cloudsql/server.js
Outdated
// [END listen] | ||
// Get type of SQL client to use | ||
const sqlClient = process.env.SQL_CLIENT; | ||
if (sqlClient === 'pg') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for conditional if we rely on passing process.env.SQL_CLIENT
to the Knex constructor
re: test error - What version of repo tools do you have? |
appengine/cloudsql/package.json
Outdated
"deploy": { | ||
"substitutions": "YOUR_USER=$MYSQL_USER,YOUR_PASSWORD=$MYSQL_PASSWORD,YOUR_DATABASE=$MYSQL_DATABASE,YOUR_INSTANCE_CONNECTION_NAME=$INSTANCE_CONNECTION_NAME" | ||
"substitutions": "YOUR_SQL_CLIENT=$SQL_CLIENT,YOUR_USER=$SQL_USER,YOUR_PASSWORD=$SQL_PASSWORD,YOUR_DATABASE=$SQL_DATABASE,YOUR_INSTANCE_CONNECTION_NAME=$INSTANCE_CONNECTION_NAME", | ||
"startArgs": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/startArgs/args/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think yarn
needs to get run again to update the yarn.lock
file. Do you have the latest version of yarn?
@@ -35,19 +35,18 @@ | |||
"test": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing a dependency on pg
. Run yarn add pg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing also a dependency on knex
@@ -35,19 +35,18 @@ | |||
"test": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing also a dependency on knex
appengine/cloudsql/server.js
Outdated
database: process.env.SQL_DATABASE | ||
}; | ||
|
||
if (process.env.INSTANCE_CONNECTION_NAME) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should change to:
if (process.env.INSTANCE_CONNECTION_NAME && process.env.NODE_ENV === 'prod') {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be prod
, or production
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, should be production
Add README Address comments; 'samples test app' still fails Address comments + make tests pass Enable Cloud SQL tests.
BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM. New feature: methods with pagination now support async iteration.
BREAKING CHANGE: The library now supports Node.js v10+. The last version to support Node.js v8 is tagged legacy-8 on NPM. New feature: methods with pagination now support async iteration.
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
Co-authored-by: Justin Beckwith <justin.beckwith@gmail.com>
Don't merge this (yet): some region tags have changed, and the docs have not been updated accordingly.