Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/typescript/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const MIN_BEHAVIOUR_LEVEL = 1;
export const MAX_BEHAVIOUR_LEVEL = 4;
export const MIN_SKILL_LEVEL = 1;
export const MAX_SKILL_LEVEL = 5;
18 changes: 0 additions & 18 deletions backend/typescript/middlewares/validators/behaviourValidators.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { DataType } from "sequelize-typescript";

import { Migration } from "../umzug";
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants";

// hard coded so that we can remove the constants from the constants.ts file
const MIN_BEHAVIOUR_LEVEL = 1;
const MAX_BEHAVIOUR_LEVEL = 4;

const TABLE_NAME = "user_behaviours";
const CONSTRAINT_NAME = "unique_user_behaviour_skill";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DataType } from "sequelize-typescript";
import { Migration } from "../umzug";
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants";

const MIN_BEHAVIOUR_LEVEL = 1;
const MAX_BEHAVIOUR_LEVEL = 4;

const TABLE_NAME = "pet_behaviours";
const CONSTRAINT_NAME = "unique_pet_behaviour";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DataType } from "sequelize-typescript";
import { Migration } from "../umzug";
import { MAX_BEHAVIOUR_LEVEL, MIN_BEHAVIOUR_LEVEL } from "../constants";

const MIN_BEHAVIOUR_LEVEL = 1;
const MAX_BEHAVIOUR_LEVEL = 4;

const TABLE_NAME = "behaviour_level_details";
const CONSTRAINT_NAME = "level_interval";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { DataType } from "sequelize-typescript";

import { Migration } from "../umzug";

// hard coded so that we can remove the constants from the constants.ts file
const MIN_BEHAVIOUR_LEVEL = 1;
const MAX_BEHAVIOUR_LEVEL = 4;

const TABLE_NAME = "behaviour_level_details";
const CONSTRAINT_NAME = "unique_behaviour_level";
const CONSTRAINT_NAME_2 = "level_interval";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize.query(
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`,
);

await sequelize
.getQueryInterface()
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME);

await sequelize.getQueryInterface().dropTable(TABLE_NAME);
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
id: {
type: DataType.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
behaviour_id: {
type: DataType.INTEGER,
allowNull: false,
references: {
model: "behaviours",
key: "id",
},
},
level: {
type: DataType.INTEGER,
allowNull: false,
},
description: {
type: DataType.STRING,
allowNull: true,
},
training_instructions: {
type: DataType.STRING,
allowNull: true,
},
});

await sequelize.getQueryInterface().addConstraint(TABLE_NAME, {
fields: ["behaviour_id", "level"],
type: "unique",
name: CONSTRAINT_NAME,
});

await sequelize.query(
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2}
CHECK (level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`,
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { DataType } from "sequelize-typescript";

import { Migration } from "../umzug";

// hard coded so that we can remove the constants from the constants.ts file
const MIN_BEHAVIOUR_LEVEL = 1;
const MAX_BEHAVIOUR_LEVEL = 4;

const TABLE_NAME = "pet_behaviours";
const CONSTRAINT_NAME = "unique_pet_behaviour";
const CONSTRAINT_NAME_2 = "skill_level_interval";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize
.getQueryInterface()
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME);

await sequelize
.getQueryInterface()
.removeColumn(TABLE_NAME, "is_highlighted");

await sequelize.query(
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`,
);

await sequelize.getQueryInterface().dropTable(TABLE_NAME);
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
id: {
type: DataType.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false,
},
pet_id: {
type: DataType.INTEGER,
allowNull: false,
references: {
model: "pets",
key: "id",
},
},
behaviour_id: {
type: DataType.INTEGER,
allowNull: false,
references: {
model: "behaviours",
key: "id",
},
},
skill_level: {
type: DataType.INTEGER,
allowNull: false,
},
});

await sequelize.getQueryInterface().addColumn(TABLE_NAME, "is_highlighted", {
type: DataType.BOOLEAN,
allowNull: true,
defaultValue: false,
});

await sequelize.getQueryInterface().addConstraint(TABLE_NAME, {
fields: ["behaviour_id", "pet_id"],
type: "unique",
name: CONSTRAINT_NAME,
});

await sequelize.query(
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2}
CHECK (skill_level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`,
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { DataType } from "sequelize-typescript";

import { Migration } from "../umzug";

// hard coded so that we can remove the constants from the constants.ts file
const MIN_BEHAVIOUR_LEVEL = 1;
const MAX_BEHAVIOUR_LEVEL = 4;

const TABLE_NAME = "user_behaviours";
const CONSTRAINT_NAME = "unique_user_behaviour_skill";
const CONSTRAINT_NAME_2 = "max_level_interval";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize
.getQueryInterface()
.removeConstraint(TABLE_NAME, CONSTRAINT_NAME);

await sequelize.query(
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${CONSTRAINT_NAME_2};`,
);

await sequelize.getQueryInterface().dropTable(TABLE_NAME);
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
id: {
type: DataType.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
user_id: {
type: DataType.INTEGER,
allowNull: false,
references: {
model: "users",
key: "id",
},
},
behaviour_id: {
type: DataType.INTEGER,
allowNull: false,
references: {
model: "behaviours",
key: "id",
},
},
max_level: {
type: DataType.INTEGER,
allowNull: false,
},
});

await sequelize.getQueryInterface().addConstraint(TABLE_NAME, {
fields: ["behaviour_id", "user_id"],
type: "unique",
name: CONSTRAINT_NAME,
});

await sequelize.query(
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${CONSTRAINT_NAME_2}
CHECK (max_level BETWEEN ${MIN_BEHAVIOUR_LEVEL} AND ${MAX_BEHAVIOUR_LEVEL});`,
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { DataType } from "sequelize-typescript";

import { Migration } from "../umzug";

const TABLE_NAME = "behaviours";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize
.getQueryInterface()
.removeColumn(TABLE_NAME, "parent_behaviour_id");
await sequelize.getQueryInterface().dropTable("behaviours");
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
id: {
type: DataType.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
behaviour_name: {
type: DataType.STRING,
allowNull: false,
},
});

await sequelize
.getQueryInterface()
.addColumn(TABLE_NAME, "parent_behaviour_id", {
type: DataType.INTEGER,
allowNull: true,
references: {
model: "behaviours",
key: "id",
},
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { DataType } from "sequelize-typescript";
import { MIN_SKILL_LEVEL, MAX_SKILL_LEVEL } from "../constants";
import { Migration } from "../umzug";

const TABLE_NAME = "pets";
const SKILL_LEVEL_INTERVAL = "skill_level_interval";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().addColumn(TABLE_NAME, "skill_level", {
type: DataType.INTEGER,
allowNull: false,
defaultValue: 5,
});
await sequelize.query(
`ALTER TABLE ${TABLE_NAME} ADD CONSTRAINT ${SKILL_LEVEL_INTERVAL}
CHECK (skill_level BETWEEN ${MIN_SKILL_LEVEL} AND ${MAX_SKILL_LEVEL});`,
);
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.query(
`ALTER TABLE ${TABLE_NAME} DROP CONSTRAINT ${SKILL_LEVEL_INTERVAL};`,
);
await sequelize.getQueryInterface().removeColumn(TABLE_NAME, "skill_level");
};
17 changes: 0 additions & 17 deletions backend/typescript/models/behaviour.model.ts

This file was deleted.

24 changes: 0 additions & 24 deletions backend/typescript/models/behaviourLevelDetails.model.ts

This file was deleted.

3 changes: 3 additions & 0 deletions backend/typescript/models/pet.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export default class Pet extends Model {
@Column({})
weight!: number;

@Column({})
skill_level!: number;

@Column({})
neutered!: boolean;

Expand Down
Loading
Loading