-
Notifications
You must be signed in to change notification settings - Fork 182
Closed
Description
I have an amount
property with type number
. I know this maps to a postresql INTEGER
, so I have changed it in my model definition json file. However, when I run automigrate, it is still generating an integer column.
model definition expense.json
{
"name": "Expense",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"description": {
"type": "string"
},
"comment": {
"type": "string"
},
"date": {
"type": "date",
"required": true
},
"amount": {
"type": "number",
"required": true,
"postgresql": {
"dataType": "NUMERIC(10,2)"
}
}
},
"validations": [],
"relations": {
"topUser": {
"type": "belongsTo",
"model": "TopUser",
"foreignKey": ""
}
},
"acls": [],
"methods": {}
}
create-sample-data.js <- with automigration
module.exports = function(app) {
var TopUser = app.models.TopUser;
var Expense = app.models.Expense;
var Role = app.models.Role;
var RoleMapping = app.models.RoleMapping;
var db = app.dataSources.postgrelocal;
// console.log('datasources', app.dataSources.postgrelocal);
var lbTables = [
'User',
'AccessToken',
'ACL',
'RoleMapping',
'Role',
'Expense',
'TopUser',
];
db.automigrate(lbTables, function(er) {
if (er) throw er;
console.log('Loopback tables ', lbTables, ' created in ', db.adapter.name);
Expense.create(
[
{
date: '2017-04-19T16:15:37.919Z',
description: 'expense 1',
comment: 'this is a dumb expense.',
amount: 156,
},
{
date: '2017-04-19T16:15:37.919Z',
description: 'expense 2',
comment: 'this is an extra dumb expense.',
amount: 0,
},
{
date: '2017-04-19T16:15:37.919Z',
description: 'expense 3',
comment: 'this is a dumb expense.',
amount: 12.5,
},
],
function(err, expenses) {
if (err) throw err;
console.log('Expenses created: \n', expenses);
}
);
});
};
Expected result
Should be a DECIMAL type.
Additional information
darwin x64 7.7.3
├── loopback@3.6.0
├── loopback-boot@2.24.0
├── loopback-component-explorer@4.2.0
├── loopback-connector-postgresql@3.0.0
npm ERR! missing: options@latest, required by sse@0.0.6