Reputation: 2503
I hit a weird problem where it said column "scopes" does not exist
. Here is the log I encountered in server but not in local enviroment:
Unhandled error for request GET /api/continents?access_token=aaaaaaaaaaabbbbbbbbbbbbbbbbL1AwzSoH8eHXwPdjzQATRXqto3lngEokVxR2j: error: column "scopes" does not exist
2017-05-05T04:35:06.642201+00:00 app[web.1]: at Connection.parseE (/app/node_modules/pg/lib/connection.js:569:11)
2017-05-05T04:35:06.642202+00:00 app[web.1]: at Connection.parseMessage (/app/node_modules/pg/lib/connection.js:396:17)
2017-05-05T04:35:06.642203+00:00 app[web.1]: at TLSSocket.<anonymous> (/app/node_modules/pg/lib/connection.js:132:22)
2017-05-05T04:35:06.642204+00:00 app[web.1]: at emitOne (events.js:96:13)
2017-05-05T04:35:06.642209+00:00 app[web.1]: at TLSSocket.emit (events.js:188:7)
2017-05-05T04:35:06.642210+00:00 app[web.1]: at readableAddChunk (_stream_readable.js:176:18)
2017-05-05T04:35:06.642210+00:00 app[web.1]: at TLSSocket.Readable.push (_stream_readable.js:134:10)
2017-05-05T04:35:06.642211+00:00 app[web.1]: at TLSWrap.onread (net.js:547:20)
All APIs involving access token failed for same reason. If access token is not set, the APIs work as expected (if public, I got data; if authentication required, I got 401/403).
I tried local - it works, I tried heroku local
- it works too. After a long testing, I found that the differences (and verified) is both my local and heroku local
are running loopback version 3.4.0 while my servers are running 3.8.0.
After I enforce the server to use 3.4.0, it is normal.
Digging into /node_modules/loopback/common/models/access-token.json
, here are the differences between 3.4.0 and 3.8.0:
Loopback 3.4.0:
"name": "AccessToken",
"properties": {
"id": { "type": "string", "id": true },
"ttl": { "type": "number", "ttl": true, "default": 1209600, "description": "time to live in seconds (2 weeks by default)" },
"created": { "type": "Date", "defaultFn": "now" }
},
Loopback 3.8.0:
"name": "AccessToken",
"properties": {
"id": { "type": "string", "id": true },
"ttl": { "type": "number", "ttl": true, "default": 1209600, "description": "time to live in seconds (2 weeks by default)" },
"scopes": {
"type": ["string"],
"description": "Array of scopes granted to this access token."
},
"created": { "type": "Date", "defaultFn": "now" }
},
Since I didn't checkin the node_modules, does anyone know how can I fix the issue?
Upvotes: 0
Views: 619
Reputation: 205
I faced the same trouble moving from lb2.x to lb3.17.0
just did an alter table : ALTER TABLE accesstoken ADD scopes TEXT;
Upvotes: 1
Reputation: 31
I just ran into the same issue from upgrading to Loopback v3.8.
You can remedy the issue by autoupdating the AccessToken table using a script. Here is a basic version of an autoupdate script.
var path = require('path');
var app = require(path.resolve(__dirname, '../server/server'));
var ds = app.datasources.db;
function update() {
// migrate AccessToken
ds.autoupdate('AccessToken', function (err) {
console.log("ds.autoupdate('AccessToken', err=", err)
if (err) throw err;
ds.disconnect();
}); // autoupdate('AccessToken')
}
// console.log("ds=", ds)
console.log("ds.connected=", ds.connected)
if(ds.connected) {
// Run autoupdate
update();
} else {
ds.once('connected', function() {
// Run autoupdate
update();
});
}
You can run this by naming it autoupdate.js, putting it in the root of the server directory and then run in the console node autoupdate.js
Then you will be golden.
Upvotes: 2