balderdashy / balderdashy/sails
defaultsTo and required key do not reflect in database schema for postgresql
Nobody has claimed this yet.
- 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:
-
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)
-
Ideally, when I add the field
required: true, then the db schema should shownot nullvalue in the Nullable column in the schema, but it shows nothing. (eg. the name field hasrequired: truebut the Nullable column is empty for the same) -
The createdAt column is of type
refwith column typetimestamp(0) with time zone. The requirement is that, it should add the current timestamp (similar as default value NOW() in postgres). ButautoUpdatedAt: trueis 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:

Original existing Schema:

Can you please let me know if I am making some mistake, or sailsjs is designed like this only???
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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