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',

View File

@@ -17,11 +17,6 @@ Production.init({
weatherTypeId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: WeatherType,
key: 'id',
schema: 'falukant_type'
},
comment: 'Wetter zum Zeitpunkt der Produktionserstellung'
},
startTimestamp: {

View File

@@ -10,20 +10,11 @@ RegionData.init({
allowNull: false},
regionTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: RegionType,
key: 'id',
schema: 'falukant_type'
}
allowNull: false
},
parentId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'region',
key: 'id',
schema: 'falukant_data'}
allowNull: true
},
map: {
type: DataTypes.JSONB,

View File

@@ -8,21 +8,11 @@ RegionDistance.init(
{
sourceRegionId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: RegionData,
key: 'id',
schema: 'falukant_data',
},
allowNull: false
},
targetRegionId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: RegionData,
key: 'id',
schema: 'falukant_data',
},
allowNull: false
},
transportMode: {
// e.g. 'land', 'water', 'air' should match VehicleType.transportMode

View File

@@ -8,18 +8,10 @@ Relationship.init(
{
character1Id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: FalukantCharacter,
key: 'id'},
onDelete: 'CASCADE'},
allowNull: false},
character2Id: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: FalukantCharacter,
key: 'id'},
onDelete: 'CASCADE'},
allowNull: false},
relationshipTypeId: {
type: DataTypes.INTEGER,
allowNull: false,

View File

@@ -8,13 +8,6 @@ FalukantUser.init({
userId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: {
tableName: 'user',
schema: 'community'
},
key: 'id'
},
unique: true},
money: {
type: DataTypes.DECIMAL(10, 2),
@@ -38,12 +31,7 @@ FalukantUser.init({
defaultValue: 1},
mainBranchRegionId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: RegionData,
key: 'id',
schema: 'falukant_data'
}
allowNull: true
},
lastNobilityAdvanceAt: {
type: DataTypes.DATE,

View File

@@ -10,21 +10,11 @@ Weather.init(
regionId: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
references: {
model: RegionData,
key: 'id',
schema: 'falukant_data'
}
allowNull: false
},
weatherTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: WeatherType,
key: 'id',
schema: 'falukant_type'
}
allowNull: false
}
},
{

View File

@@ -10,13 +10,11 @@ PromotionalGiftCharacterTrait.init(
giftId: {
type: DataTypes.INTEGER,
field: 'gift_id',
references: { model: PromotionalGift, key: 'id' },
allowNull: false
},
traitId: {
type: DataTypes.INTEGER,
field: 'trait_id',
references: { model: CharacterTrait, key: 'id' },
allowNull: false
},
suitability: {

View File

@@ -10,19 +10,11 @@ PromotionalGiftMood.init(
giftId: {
type: DataTypes.INTEGER,
field: 'gift_id',
references: {
model: PromotionalGift,
key: 'id'
},
allowNull: false
},
moodId: {
type: DataTypes.INTEGER,
field: 'mood_id',
references: {
model: Mood,
key: 'id'
},
allowNull: false
},
suitability: {

View File

@@ -9,21 +9,11 @@ ProductWeatherEffect.init(
{
productId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: ProductType,
key: 'id',
schema: 'falukant_type'
}
allowNull: false
},
weatherTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: WeatherType,
key: 'id',
schema: 'falukant_type'
}
allowNull: false
},
qualityEffect: {
type: DataTypes.INTEGER,

View File

@@ -9,11 +9,7 @@ RegionType.init({
allowNull: false},
parentId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: 'region',
key: 'id',
schema: 'falukant_type'}
allowNull: true
}
}, {
sequelize,

View File

@@ -4,19 +4,11 @@ import { DataTypes } from 'sequelize';
const ForumForumPermission = sequelize.define('forum_forum_permission', {
forumId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'forum',
key: 'id'
}
allowNull: false
},
permissionId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'forum_permission',
key: 'id'
}
allowNull: false
}
}, {
tableName: 'forum_forum_permission',

View File

@@ -9,11 +9,7 @@ const Match3Level = sequelize.define('Match3Level', {
},
campaignId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'match3_campaigns',
key: 'id'
}
allowNull: false
},
name: {
type: DataTypes.STRING(255),

View File

@@ -10,19 +10,11 @@ const Match3LevelTileType = sequelize.define('Match3LevelTileType', {
levelId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'match3_levels',
key: 'id'
},
comment: 'Referenz auf den Level'
},
tileTypeId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'match3_tile_types',
key: 'id'
},
comment: 'Referenz auf den Tile-Typ'
},
weight: {

View File

@@ -9,14 +9,7 @@ const TaxiHighscore = sequelize.define('TaxiHighscore', {
},
userId: {
type: DataTypes.INTEGER,
allowNull: true, // Kann null sein, falls User gelöscht wird
references: {
model: {
tableName: 'user',
schema: 'community'
},
key: 'id'
}
allowNull: true // Kann null sein, falls User gelöscht wird
},
nickname: {
type: DataTypes.STRING(100),
@@ -44,13 +37,6 @@ const TaxiHighscore = sequelize.define('TaxiHighscore', {
mapId: {
type: DataTypes.INTEGER,
allowNull: true,
references: {
model: {
tableName: 'taxi_map',
schema: 'taxi'
},
key: 'id'
},
comment: 'ID der gespielten Map'
},
mapName: {

View File

@@ -13,13 +13,7 @@ const interestTranslation = sequelize.define('interest_translation_type', {
},
interestsId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: Interest,
key: 'id'
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE'
allowNull: false
}}, {
tableName: 'interest_translation',
schema: 'type',

View File

@@ -21,11 +21,7 @@ const UserParamType = sequelize.define('user_param_type', {
},
settingsId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'settings',
key: 'id'
}
allowNull: false
},
orderId: {
type: DataTypes.INTEGER,