balderdashy / balderdashy/sails

defaultsTo and required key do not reflect in database schema for postgresql

Open
#6,801 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

helpful info or workaround orm postgresql
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Node version: 10.16.0
Sails version (sails): 1.2.3
ORM hook version (sails-hook-orm): ^2.1.1
Sockets hook version (sails-hook-sockets): ^2.0.0
DB adapter & version (sails-postgresql): ^1.0.2


I have an existing postgresql database, and I want to replicate the same database using the sails-postgresql. But I am facing the following issues:

  1. defaultsTo value does not reflect in the database schema. (eg. The isDeleted field in the attribute is of type boolean which defaults to false, but the schema does not reflect the same. Simillarly the meta field in the attribute is of type jsonb which defaults to empty object, but no reflection in the db schema)

  2. Ideally, when I add the field required: true, then the db schema should show not null value in the Nullable column in the schema, but it shows nothing. (eg. the name field has required: true but the Nullable column is empty for the same)

  3. The createdAt column is of type ref with column type timestamp(0) with time zone. The requirement is that, it should add the current timestamp (similar as default value NOW() in postgres). But autoUpdatedAt: true is not helping me with the same.

module.exports = {
  schema: true,
  tableName: 'organization',
  attributes: {
    id: {
      type: 'number',
      unique: true,
      columnName: 'id',
      autoIncrement: true
    },
    isDeleted: {
      type: 'boolean',
      defaultsTo: false,
      columnName: 'is_deleted'
    },
    name: {
      type: 'ref',
      columnName: 'name',
      columnType: 'text',
      required: true
    },
    createdAt: {
      type: 'ref',
      columnName: 'created_at',
      columnType: 'timestamp(0) with time zone',
      autoUpdatedAt: true,
    },
    meta: {
      type: 'ref',
      columnName: 'meta',
      columnType: 'jsonb',
      defaultsTo: {},
    },
  }
};

Schema built using sailsjs:
Screenshot from 2019-06-28 12-42-04
Original existing Schema:
Screenshot from 2019-06-28 12-53-37

Can you please let me know if I am making some mistake, or sailsjs is designed like this only???

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No repository file or test is named. Start with the shown model definition and the sails-postgresql schema-generation path, then reproduce the defaultsTo, required, and createdAt cases against PostgreSQL. Done means the expected schema behavior is confirmed and covered by an appropriate regression test, or the supported limitations are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.