Skip to content

Commit dc8015f

Browse files
committed
Update interaction log migration and model: set foreign key onDelete behavior to SET NULL, adjust column types for descriptions
1 parent fd9bf6e commit dc8015f

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

backend/typescript/migrations/2025.06.10T00.24.34.create_interaction_logs.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const up: Migration = async ({ context: sequelize }) => {
4040
key: "id",
4141
},
4242
onUpdate: "CASCADE",
43+
onDelete: "SET NULL",
4344
},
4445
target_pet_id: {
4546
type: DataType.INTEGER,
@@ -49,6 +50,7 @@ export const up: Migration = async ({ context: sequelize }) => {
4950
key: "id",
5051
},
5152
onUpdate: "CASCADE",
53+
onDelete: "SET NULL",
5254
},
5355
target_task_id: {
5456
type: DataType.INTEGER,
@@ -58,6 +60,7 @@ export const up: Migration = async ({ context: sequelize }) => {
5860
key: "id",
5961
},
6062
onUpdate: "CASCADE",
63+
onDelete: "SET NULL",
6164
},
6265
target_task_template_id: {
6366
type: DataType.INTEGER,
@@ -67,6 +70,7 @@ export const up: Migration = async ({ context: sequelize }) => {
6770
key: "id",
6871
},
6972
onUpdate: "CASCADE",
73+
onDelete: "SET NULL",
7074
},
7175
interaction_type_id: {
7276
type: DataType.INTEGER,
@@ -76,17 +80,18 @@ export const up: Migration = async ({ context: sequelize }) => {
7680
key: "id",
7781
},
7882
onUpdate: "CASCADE",
83+
onDelete: "RESTRICT",
7984
},
8085
metadata: {
8186
type: DataType.ARRAY(DataType.STRING),
8287
allowNull: false,
8388
},
8489
short_description: {
85-
type: DataType.STRING,
90+
type: DataType.STRING(256),
8691
allowNull: false,
8792
},
8893
detailed_description: {
89-
type: DataType.STRING,
94+
type: DataType.TEXT,
9095
allowNull: false,
9196
},
9297
created_at: {

backend/typescript/models/interactionLog.model.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,39 @@ export default class Interaction extends Model {
2323
@Column({ allowNull: false })
2424
actor_id!: number;
2525

26-
@BelongsTo(() => User)
26+
@BelongsTo(() => User, { foreignKey: "actor_id", onDelete: "SET NULL" })
2727
actor!: User;
2828

29+
@ForeignKey(() => User)
30+
@Column({ type: DataType.INTEGER, allowNull: true })
31+
target_user_id!: number;
32+
33+
@BelongsTo(() => User, { foreignKey: "target_user_id", onDelete: "SET NULL" })
34+
target_user?: User;
35+
2936
@ForeignKey(() => Pet)
30-
@Column({
31-
type: DataType.INTEGER,
32-
allowNull: true,
33-
})
37+
@Column({ type: DataType.INTEGER, allowNull: true })
3438
target_pet_id!: number;
3539

36-
@BelongsTo(() => Pet)
37-
pet?: Pet;
40+
@BelongsTo(() => Pet, { foreignKey: "target_pet_id", onDelete: "SET NULL" })
41+
target_pet?: Pet;
3842

3943
@ForeignKey(() => Activity)
40-
@Column({
41-
type: DataType.INTEGER,
42-
allowNull: true,
43-
})
44+
@Column({ type: DataType.INTEGER, allowNull: true })
4445
target_task_id!: number;
4546

46-
@BelongsTo(() => Activity)
47-
task?: Activity;
47+
@BelongsTo(() => Activity, { foreignKey: "target_task_id", onDelete: "SET NULL" })
48+
target_task?: Activity;
4849

4950
@ForeignKey(() => ActivityType)
50-
@Column({
51-
type: DataType.INTEGER,
52-
allowNull: true,
53-
})
54-
target_task_type_id!: number;
55-
56-
@BelongsTo(() => ActivityType)
57-
activity_type?: ActivityType;
51+
@Column({ type: DataType.INTEGER, allowNull: true })
52+
target_task_template_id!: number;
5853

54+
@BelongsTo(() => ActivityType, {
55+
foreignKey: "target_task_template_id",
56+
onDelete: "SET NULL",
57+
})
58+
target_task_template?: ActivityType;
5959
@ForeignKey(() => InteractionType)
6060
@Column({
6161
type: DataType.INTEGER,
@@ -70,13 +70,9 @@ export default class Interaction extends Model {
7070
@Column({ type: DataType.ARRAY(DataType.STRING), allowNull: false })
7171
metadata!: Array<string>;
7272

73-
@Column({ type: DataType.STRING, allowNull: false })
73+
@Column({ type: DataType.STRING(256), allowNull: false })
7474
short_description!: string;
7575

76-
@Column({ type: DataType.STRING, allowNull: false })
76+
@Column({ type: DataType.TEXT, allowNull: false })
7777
detailed_description!: string;
78-
79-
@Index
80-
@Column({ allowNull: false })
81-
target_id!: number;
8278
}

0 commit comments

Comments
 (0)