New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defaultsTo and required key do not reflect in database schema for postgresql #6801
Comments
@krisalay Thanks for posting! We'll take a look as soon as possible. In the mean time, there are a few ways you can help speed things along:
Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly. For help with questions about Sails, click here. |
Unfortunately there is quite a disconnect between how Waterline and the underlying database handle your data validations & constraints, with Waterline favouring to do it all itself. I think for those fields that you defined with type updatedAt: {
type: 'ref',
columnName: 'created_at',
columnType: 'timestamptz not null default now()',
autoUpdatedAt: true,
},
previousEmailAddresses: {
type: 'ref',
columnName: 'previous_email',
columnType: `text[] default '{}'`, // Default array enforced @ db level
defaultsTo: [], // Default empty array enforced @ JS level
}, That
Buyer beware: It's not The Sails Way, and will probably barf using the local disk adapter in tests / if you change to another underlying ORM / if Waterline changes how it handles these kind of attribute definitions in future. Introducing things like "real" foreign keys at the database level can/will-most-likely cause the Waterline migrations/table alterations to go boom, if you ever end up that far down the rabbit hole. Also you probably want to use |
Hi, @krisalay—if you're using the safe migration setting ( |
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 null
value in the Nullable column in the schema, but it shows nothing. (eg. the name field hasrequired: true
but the Nullable column is empty for the same)The createdAt column is of type
ref
with column typetimestamp(0) with time zone
. The requirement is that, it should add the current timestamp (similar as default value NOW() in postgres). ButautoUpdatedAt: true
is not helping me with the same.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???
The text was updated successfully, but these errors were encountered: