Skip to content

Commit

Permalink
fix: set correct defaultValue for JSON fields
Browse files Browse the repository at this point in the history
This specifies a `defaultValue` for all JSON fields which corresponds with the kind of field (array or object). This fixes empty fields being set to `'{}'` instead of `{}` in the database.
  • Loading branch information
rudivanhierden committed May 8, 2023
1 parent 5effe86 commit 3bece85
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 5 additions & 3 deletions model/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = (db, sequelize, Sequelize) => {

authTypes: {
type: DataTypes.JSON,
defaultValue: '[]',
defaultValue: [],
allowNull: false,
get: function () {
let value = this.getDataValue('authTypes') || [];
Expand Down Expand Up @@ -77,6 +77,7 @@ module.exports = (db, sequelize, Sequelize) => {

requiredUserFields: {
type: DataTypes.JSON,
defaultValue: [],
get: function () {
let value = this.getDataValue('requiredUserFields');
try {
Expand All @@ -95,6 +96,7 @@ module.exports = (db, sequelize, Sequelize) => {

allowedDomains: {
type: DataTypes.JSON,
defaultValue: [],
get: function () {
let value = this.getDataValue('allowedDomains');
try {
Expand All @@ -113,7 +115,7 @@ module.exports = (db, sequelize, Sequelize) => {

config: {
type: DataTypes.JSON,
defaultValue: '{}',
defaultValue: {},
get: function () {
let value = this.getDataValue('config');
try {
Expand All @@ -132,7 +134,7 @@ module.exports = (db, sequelize, Sequelize) => {

twoFactorRoles: {
type: DataTypes.JSON,
defaultValue: '{}',
defaultValue: [],
get: function () {
let value = this.getDataValue('twoFactorRoles');
try {
Expand Down
3 changes: 1 addition & 2 deletions model/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = (db, sequelize, Sequelize) => {

extraData: {
type: DataTypes.JSON,
defaultValue: '{}',
defaultValue: {},
allowNull: false,
get: function () {
let value = this.getDataValue('extraData');
Expand Down Expand Up @@ -179,4 +179,3 @@ module.exports = (db, sequelize, Sequelize) => {
return User;

}

1 comment on commit 3bece85

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Published new image: openstad/auth:codeimprovement-migrate-to-sequelize-3bece85

Please sign in to comment.