Skip to content

Commit c393110

Browse files
authored
Merge pull request #60 from uwblueprint/W25/trinity/remove-behaviour-model
W25/trinity/remove-behaviour-model
2 parents 80e7e46 + e3764ee commit c393110

19 files changed

+266
-399
lines changed

backend/typescript/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
export const MIN_COLOR_LEVEL = 1;
2+
export const MAX_COLOR_LEVEL = 5;
3+
4+
// below constants are not currently in use (for old migration files)
15
export const MIN_BEHAVIOUR_LEVEL = 1;
26
export const MAX_BEHAVIOUR_LEVEL = 4;

backend/typescript/middlewares/validators/behaviourValidators.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.

backend/typescript/migrations/2024.10.29T20.20.02.create-user-behaviour-table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DataType } from "sequelize-typescript";
22

33
import { Migration } from "../umzug";
4-
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants";
4+
import { MIN_BEHAVIOUR_LEVEL, MAX_BEHAVIOUR_LEVEL } from "../constants";
55

66
const TABLE_NAME = "user_behaviours";
77
const CONSTRAINT_NAME = "unique_user_behaviour_skill";

backend/typescript/migrations/2024.10.29T20.29.50.add-pet-behaviour-columns.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DataType } from "sequelize-typescript";
22
import { Migration } from "../umzug";
3-
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants";
3+
import { MIN_BEHAVIOUR_LEVEL, MAX_BEHAVIOUR_LEVEL } from "../constants";
44

55
const TABLE_NAME = "pet_behaviours";
66
const CONSTRAINT_NAME = "unique_pet_behaviour";

backend/typescript/migrations/2024.11.21T16.49.50.add-constraint-behaviour-level-details-table.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DataType } from "sequelize-typescript";
22
import { Migration } from "../umzug";
3-
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants";
3+
import { MIN_BEHAVIOUR_LEVEL, MAX_BEHAVIOUR_LEVEL } from "../constants";
44

55
const TABLE_NAME = "behaviour_level_details";
66
const CONSTRAINT_NAME = "level_interval";
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { MIN_BEHAVIOUR_LEVEL, MAX_BEHAVIOUR_LEVEL } from "../constants";
3+
import { Migration } from "../umzug";
4+
5+
const TABLE_NAME = "behaviour_level_details";
6+
const CONSTRAINT_NAME = "unique_behaviour_level";
7+
const CONSTRAINT_NAME_2 = "level_interval";
8+
9+
export const up: Migration = async ({ context: sequelize }) => {
10+
await sequelize.query(
11+
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`,
12+
);
13+
14+
await sequelize
15+
.getQueryInterface()
16+
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME);
17+
18+
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
19+
};
20+
21+
export const down: Migration = async ({ context: sequelize }) => {
22+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
23+
id: {
24+
type: DataType.INTEGER,
25+
allowNull: false,
26+
primaryKey: true,
27+
autoIncrement: true,
28+
},
29+
behaviour_id: {
30+
type: DataType.INTEGER,
31+
allowNull: false,
32+
references: {
33+
model: "behaviours",
34+
key: "id",
35+
},
36+
},
37+
level: {
38+
type: DataType.INTEGER,
39+
allowNull: false,
40+
},
41+
description: {
42+
type: DataType.STRING,
43+
allowNull: true,
44+
},
45+
training_instructions: {
46+
type: DataType.STRING,
47+
allowNull: true,
48+
},
49+
});
50+
51+
await sequelize.getQueryInterface().addConstraint(TABLE_NAME, {
52+
fields: ["behaviour_id", "level"],
53+
type: "unique",
54+
name: CONSTRAINT_NAME,
55+
});
56+
57+
await sequelize.query(
58+
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2}
59+
CHECK (level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`,
60+
);
61+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { MIN_BEHAVIOUR_LEVEL, MAX_BEHAVIOUR_LEVEL } from "../constants";
3+
import { Migration } from "../umzug";
4+
5+
const TABLE_NAME = "pet_behaviours";
6+
const CONSTRAINT_NAME = "unique_pet_behaviour";
7+
const CONSTRAINT_NAME_2 = "skill_level_interval";
8+
9+
export const up: Migration = async ({ context: sequelize }) => {
10+
await sequelize
11+
.getQueryInterface()
12+
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME);
13+
14+
await sequelize
15+
.getQueryInterface()
16+
.removeColumn(TABLE_NAME, "is_highlighted");
17+
18+
await sequelize.query(
19+
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`,
20+
);
21+
22+
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
23+
};
24+
25+
export const down: Migration = async ({ context: sequelize }) => {
26+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
27+
id: {
28+
type: DataType.INTEGER,
29+
autoIncrement: true,
30+
primaryKey: true,
31+
allowNull: false,
32+
},
33+
pet_id: {
34+
type: DataType.INTEGER,
35+
allowNull: false,
36+
references: {
37+
model: "pets",
38+
key: "id",
39+
},
40+
},
41+
behaviour_id: {
42+
type: DataType.INTEGER,
43+
allowNull: false,
44+
references: {
45+
model: "behaviours",
46+
key: "id",
47+
},
48+
},
49+
skill_level: {
50+
type: DataType.INTEGER,
51+
allowNull: false,
52+
},
53+
});
54+
55+
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "is_highlighted", {
56+
type: DataType.BOOLEAN,
57+
allowNull: true,
58+
defaultValue: false,
59+
});
60+
61+
await sequelize.getQueryInterface().addConstraint(TABLE_NAME, {
62+
fields: ["behaviour_id", "pet_id"],
63+
type: "unique",
64+
name: CONSTRAINT_NAME,
65+
});
66+
67+
await sequelize.query(
68+
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2}
69+
CHECK (skill_level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`,
70+
);
71+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { MIN_BEHAVIOUR_LEVEL, MAX_BEHAVIOUR_LEVEL } from "../constants";
3+
import { Migration } from "../umzug";
4+
5+
const TABLE_NAME = "user_behaviours";
6+
const CONSTRAINT_NAME = "unique_user_behaviour_skill";
7+
const CONSTRAINT_NAME_2 = "max_level_interval";
8+
9+
export const up: Migration = async ({ context: sequelize }) => {
10+
await sequelize
11+
.getQueryInterface()
12+
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME);
13+
14+
await sequelize.query(
15+
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`,
16+
);
17+
18+
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
19+
};
20+
21+
export const down: Migration = async ({ context: sequelize }) => {
22+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
23+
id: {
24+
type: DataType.INTEGER,
25+
allowNull: false,
26+
primaryKey: true,
27+
autoIncrement: true,
28+
},
29+
user_id: {
30+
type: DataType.INTEGER,
31+
allowNull: false,
32+
references: {
33+
model: "users",
34+
key: "id",
35+
},
36+
},
37+
behaviour_id: {
38+
type: DataType.INTEGER,
39+
allowNull: false,
40+
references: {
41+
model: "behaviours",
42+
key: "id",
43+
},
44+
},
45+
max_level: {
46+
type: DataType.INTEGER,
47+
allowNull: false,
48+
},
49+
});
50+
51+
await sequelize.getQueryInterface().addConstraint(TABLE_NAME, {
52+
fields: ["behaviour_id", "user_id"],
53+
type: "unique",
54+
name: CONSTRAINT_NAME,
55+
});
56+
57+
await sequelize.query(
58+
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2}
59+
CHECK (max_level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`,
60+
);
61+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { DataType } from "sequelize-typescript";
2+
3+
import { Migration } from "../umzug";
4+
5+
const TABLE_NAME = "behaviours";
6+
7+
export const up: Migration = async ({ context: sequelize }) => {
8+
await sequelize
9+
.getQueryInterface()
10+
.removeColumn(TABLE_NAME, "parent_behaviour_id");
11+
await sequelize.getQueryInterface().dropTable("behaviours");
12+
};
13+
14+
export const down: Migration = async ({ context: sequelize }) => {
15+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
16+
id: {
17+
type: DataType.INTEGER,
18+
allowNull: false,
19+
primaryKey: true,
20+
autoIncrement: true,
21+
},
22+
behaviour_name: {
23+
type: DataType.STRING,
24+
allowNull: false,
25+
},
26+
});
27+
28+
await sequelize
29+
.getQueryInterface()
30+
.addColumn(TABLE_NAME, "parent_behaviour_id", {
31+
type: DataType.INTEGER,
32+
allowNull: true,
33+
references: {
34+
model: "behaviours",
35+
key: "id",
36+
},
37+
});
38+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { MIN_COLOR_LEVEL, MAX_COLOR_LEVEL } from "../constants";
3+
import { Migration } from "../umzug";
4+
5+
const TABLE_NAME = "pets";
6+
const SKILL_LEVEL_INTERVAL = "skill_level_interval";
7+
8+
export const up: Migration = async ({ context: sequelize }) => {
9+
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "skill_level", {
10+
type: DataType.INTEGER,
11+
allowNull: false,
12+
defaultValue: 5,
13+
});
14+
await sequelize.query(
15+
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${SKILL_LEVEL_INTERVAL}
16+
CHECK (skill_level BETWEEN ${MIN_COLOR_LEVEL} AND ${MAX_COLOR_LEVEL});`,
17+
);
18+
};
19+
20+
export const down: Migration = async ({ context: sequelize }) => {
21+
await sequelize.query(
22+
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${SKILL_LEVEL_INTERVAL};`,
23+
);
24+
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "skill_level");
25+
};

0 commit comments

Comments
 (0)