Giter Site home page Giter Site logo

Comments (9)

snevolin avatar snevolin commented on May 23, 2024 3

I have the same issue with loopback 3.0.0

from loopback-connector-postgresql.

raymondfeng avatar raymondfeng commented on May 23, 2024

How did you create the Role table? Do you create the columns for Date type with 'TIMESTAMP WITH TIME ZONE’?

Here is an example SQL for date properties from ‘automigrate’:

CREATE TABLE "public"."account" (
"email" VARCHAR(1024),
"level" INTEGER,
"created" TIMESTAMP WITH TIME ZONE,
"modified" TIMESTAMP WITH TIME ZONE,
"id" SERIAL,
PRIMARY KEY("id")
)

Thanks,


Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop makes it easy to develop APIs in Node, plus get DevOps capabilities like monitoring, debugging and clustering.

On Jun 20, 2014, at 5:50 PM, Jonathan [email protected] wrote:

I'm following the instructions for defining an admin role in the documentation, but I'm receiving the following error at the Role.create({name: 'admin'}, cb) step:

loopback:connector:postgresql error: time zone "gmt-0700" not recognized
Any help would be appreciated!


Reply to this email directly or view it on GitHub.

from loopback-connector-postgresql.

woodedlawn avatar woodedlawn commented on May 23, 2024

I used automigrate to create the table using the default Role model. The Created and Modified columns are both of type "timestamp with time zone".

It appears the problem is that loopback is trying to insert a javascript date but it needs to be converted to ISO format. Is this an option that I can set somewhere?

from loopback-connector-postgresql.

raymondfeng avatar raymondfeng commented on May 23, 2024

The conversion is handled by pg module. I don't have issue with similar code at https://github.com/strongloop-community/loopback-example-database/blob/postgresql/create-test-data.js. What's your Postgresql version?

from loopback-connector-postgresql.

woodedlawn avatar woodedlawn commented on May 23, 2024

The code sample you provided worked, and after some digging, I think I've narrowed my issue. My Postgresql version is 9.3.4.2.

My problem appears to stem from the defaults set on the Role model timestamps here: https://github.com/strongloop/loopback/blob/master/lib/models/role.js#L14-16

I modified the code sample you provided to recreate the issue.

var app = require('./app');
var dataSource = app.dataSources.accountDB;

var properties = {
    email: {type: String},
    level: {type: Number},
    created: {type: Date, default: Date},
    modified: {type: Date, default: Date}
};

var Test = app.model('test', {
  properties: properties, 
  dataSource: 'accountDB'
});

var tests = [ 
    {  email: "[email protected]",
       level: 10
    }, {
       email: "[email protected]",
       level: 20
    } ];

var count = tests.length;
dataSource.automigrate('test', function (err) {
  tests.forEach(function(test) {
    Test.create(test, function(err, result) {
      if(!err) {
        console.log('Record created:', result);
        count--;
        if(count === 0) {
          console.log('done');
        }
      }
    });
  });
});

Thanks for your help. Let me know if I can provide any additional info.

from loopback-connector-postgresql.

jlouthan avatar jlouthan commented on May 23, 2024

I'm having the exact same issue as @woodedlawn. I tried to update my loopback-datasource-juggler in order to employ your workaround, @raymondfeng, but I couldn't get a 1.6.x version because of the npm error

npm ERR! peerinvalid The package loopback-datasource-juggler does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants loopback-datasource-juggler@>=1.4.0 <1.6.0

I manually went in and changed loopback's package.json to allow a 1.6.x version of loopback-datasource-juggler, npm installed the latest version, and instead of the time zone error I was met with a new error:

error: null value in column "id" violates not-null constraint

when running the same code from the docs to create a role for a user. So I changed the code to provide an id when creating a new role and role mapping, and it worked. The working code looked like:

    User.create({name: 'John', email: '[email protected]', password: 'foobar'}, function (err, user) {
    // Create the static admin Role
        Role.create({name: 'admin', id: '1'}, function (err, role) {
    // Make John an admin
        role.principals.create({principalType: RoleMapping.USER, principalId: user.id, id: '1'});
   });

Is there a reason the version of loopback I'm using (1.8.8) doesn't want a 1.6.x version of loopback-datasource-juggler, or should this be fixed in its package.json file? And am I missing something or is setting the id when creating a new Role and Role Mapping necessary?

Thanks!!

from loopback-connector-postgresql.

raymondfeng avatar raymondfeng commented on May 23, 2024

Please upgrade to loopback 1.9.x. Remove node_modules and run npm install if necessary.

Sent from my iPhone 5

On Jul 1, 2014, at 4:55 PM, jlouthan [email protected] wrote:

I'm having the exact same issue as @woodedlawn. I tried to update my loopback-datasource-juggler in order to employ your workaround, @raymondfeng, but I couldn't get a 1.6.x version because of the npm error

npm ERR! peerinvalid The package loopback-datasource-juggler does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants loopback-datasource-juggler@>=1.4.0 <1.6.0

I manually went in and changed loopback's package.json to allow a 1.6.x version of loopback-datasource-juggler, npm installed the latest version, and instead of the time zone error I was met with a new error:

error: null value in column "id" violates not-null constraint

when running the same code from the docs to create a role for a user. So I changed the code to provide an id when creating a new role, and it worked. The working code looked like:

User.create({name: 'John', email: '[email protected]', password: 'foobar'}, function (err, user) {
// Create the static admin Role
    Role.create({name: 'admin', id: '1'}, function (err, role) {
// Make John an admin
    role.principals.create({principalType: RoleMapping.USER, principalId: user.id});

});
Is there a reason the version of loopback I'm using (1.8.8) doesn't want a 1.6.x version of loopback-datasource-juggler, or should this be fixed in its package.json file? And am I missing something or is setting the id when creating a new Role necessary?

Thanks!!


Reply to this email directly or view it on GitHub.

from loopback-connector-postgresql.

davidcheung avatar davidcheung commented on May 23, 2024

Cleaning up old issues, loopbackio/loopback-datasource-juggler@3edee5c address this issue, closing issue now.

from loopback-connector-postgresql.

edbond avatar edbond commented on May 23, 2024

For me the problem was in setting updatedAt to number. Changed to Date object.

  Model.observe('before save', function (ctx, next) {
    var instance = ctx.instance || ctx.data;

    // instance.updatedAt = Date.now();
    instance.updatedAt = new Date();

    next();
  });

from loopback-connector-postgresql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.