Refactor multiple models to remove foreign key references while maintaining required fields, enhancing data integrity and simplifying model definitions.

This commit is contained in:
Torsten Schulz (local)
2025-12-18 16:08:30 +01:00
parent c66fbf1a62
commit c8072b8052
24 changed files with 38 additions and 222 deletions

View File

@@ -8,16 +8,12 @@ const Folder = sequelize.define('folder', {
allowNull: false},
parentId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'folder',
key: 'id'}},
allowNull: true
},
userId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'user',
key: 'id'}}}, {
allowNull: false
}}, {
tableName: 'folder',
schema: 'community',
underscored: true,

View File

@@ -10,22 +10,11 @@ const FolderImageVisibility = sequelize.define('folder_image_visibility', {
},
folderId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'folder',
key: 'id'
}
allowNull: false
},
visibilityTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: {
schema: 'type',
tableName: 'image_visibility_type'
},
key: 'id'
}
allowNull: false
}
}, {
tableName: 'folder_image_visibility',

View File

@@ -10,19 +10,11 @@ const FolderVisibilityUser = sequelize.define('folder_visibility_user', {
},
folderId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'folder',
key: 'id'
}
allowNull: false
},
visibilityUserId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'image_visibility_user',
key: 'id'
}
allowNull: false
}
}, {
tableName: 'folder_visibility_user',

View File

@@ -10,19 +10,11 @@ const GuestbookEntry = sequelize.define('guestbook_entry', {
allowNull: false},
recipientId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: User,
key: 'id'
}
allowNull: false
},
senderId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: User,
key: 'id'
}
allowNull: true
},
senderUsername: {
type: DataTypes.STRING,

View File

@@ -18,16 +18,12 @@ const Image = sequelize.define('image', {
unique: true},
folderId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'folder',
key: 'id'}},
allowNull: false
},
userId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'user',
key: 'id'}}}, {
allowNull: false
}}, {
tableName: 'image',
schema: 'community',
underscored: true,

View File

@@ -10,22 +10,11 @@ const ImageImageVisibility = sequelize.define('image_image_visibility', {
},
imageId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'image',
key: 'id'
}
allowNull: false
},
visibilityTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: {
schema: 'type',
tableName: 'image_visibility_type'
},
key: 'id'
}
allowNull: false
}
}, {
tableName: 'image_image_visibility',

View File

@@ -7,19 +7,11 @@ import { encrypt, decrypt } from '../../utils/encryption.js';
const UserParam = sequelize.define('user_param', {
userId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: User,
key: 'id',
},
allowNull: false
},
paramTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: UserParamType,
key: 'id',
},
allowNull: false
},
value: {
type: DataTypes.STRING,

View File

@@ -6,19 +6,11 @@ import UserRightType from '../type/user_right.js';
const UserRight = sequelize.define('user_right', {
userId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: User,
key: 'id'
}
allowNull: false
},
rightTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: UserRightType,
key: 'id'
}
allowNull: false
}}, {
tableName: 'user_right',
schema: 'community',