Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
feat(db): remove clients.secret column
Browse files Browse the repository at this point in the history
Closes #323
  • Loading branch information
seanmonstar committed Aug 31, 2015
1 parent e62851e commit 0e39d1e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/db/index.js
Expand Up @@ -36,8 +36,8 @@ function convertClientToConfigFormat(client) {
for (var key in client) {
if (key === 'createdAt') {
continue;
} else if (key === 'secret') {
out.hashedSecret = unbuf(client.secret);
} else if (key === 'hashedSecret') {
out.hashedSecret = unbuf(client.hashedSecret);
} else if (key === 'trusted' || key === 'canGrant') {
out[key] = !!client[key]; // db stores booleans as 0 or 1.
} else if (key === 'termsUri' || key === 'privacyUri') {
Expand Down
7 changes: 2 additions & 5 deletions lib/db/mysql/index.js
Expand Up @@ -114,9 +114,9 @@ MysqlStore.connect = function mysqlConnect(options) {

const QUERY_CLIENT_REGISTER =
'INSERT INTO clients ' +
'(id, name, imageUri, hashedSecret, secret, redirectUri, termsUri,' +
'(id, name, imageUri, hashedSecret, redirectUri, termsUri,' +
'privacyUri, trusted, canGrant) ' +
'VALUES (?,?, ?, ?, ?, ?, ?, ?, ?, ?);';
'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);';
const QUERY_CLIENT_DEVELOPER_INSERT =
'INSERT INTO clientDevelopers ' +
'(rowId, developerId, clientId) ' +
Expand Down Expand Up @@ -145,7 +145,6 @@ const QUERY_CLIENT_LIST = 'SELECT id, name, redirectUri, imageUri, ' +
const QUERY_CLIENT_UPDATE = 'UPDATE clients SET ' +
'name=COALESCE(?, name), imageUri=COALESCE(?, imageUri), ' +
'hashedSecret=COALESCE(?, hashedSecret), ' +
'secret=COALESCE(?, hashedSecret), ' +
'redirectUri=COALESCE(?, redirectUri), ' +
'termsUri=COALESCE(?, termsUri), privacyUri=COALESCE(?, privacyUri), ' +
'trusted=COALESCE(?, trusted), canGrant=COALESCE(?, canGrant) ' +
Expand Down Expand Up @@ -215,7 +214,6 @@ MysqlStore.prototype = {
client.name,
client.imageUri || '',
buf(client.hashedSecret),
buf(client.hashedSecret), // duplicate for `secret` column until dropped
client.redirectUri,
client.termsUri || '',
client.privacyUri || '',
Expand Down Expand Up @@ -311,7 +309,6 @@ MysqlStore.prototype = {
client.name,
client.imageUri,
secret,
secret, // duplicate for `secret` column until dropped
client.redirectUri,
client.termsUri,
client.privacyUri,
Expand Down
2 changes: 1 addition & 1 deletion lib/db/mysql/patch.js
Expand Up @@ -6,4 +6,4 @@
// Update this if you add a new patch, and don't forget to update
// the documentation for the current schema in ../schema.sql.

module.exports.level = 9;
module.exports.level = 10;
5 changes: 5 additions & 0 deletions lib/db/mysql/patches/patch-009-010.sql
@@ -0,0 +1,5 @@
-- Remove `secret` column.

ALTER TABLE clients DROP COLUMN secret;

UPDATE dbMetadata SET value = '10' WHERE name = 'schema-patch-level';
6 changes: 6 additions & 0 deletions lib/db/mysql/patches/patch-010-009.sql
@@ -0,0 +1,6 @@
-- (commented out to avoid accidentally running this in production...)

-- ALTER TABLE clients ADD COLUMN secret BINARY(32);
-- UPDATE clients SET secret = hashedSecret;

-- UPDATE dbMetadata SET value = '9' WHERE name = 'schema-patch-level';
1 change: 0 additions & 1 deletion lib/db/mysql/schema.sql
Expand Up @@ -10,7 +10,6 @@
CREATE TABLE IF NOT EXISTS clients (
id BINARY(8) PRIMARY KEY,
hashedSecret BINARY(32),
secret BINARY(32),
name VARCHAR(256) NOT NULL,
imageUri VARCHAR(256) NOT NULL,
redirectUri VARCHAR(256) NOT NULL,
Expand Down

0 comments on commit 0e39d1e

Please sign in to comment.