-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created model and migration files for behaviour and behaviour level t…
…ables
- Loading branch information
Showing
5 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
backend/typescript/migrations/2024.10.22T19.38.07.create-behaviour-level-details-table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
|
||
import { Migration } from "../umzug"; | ||
|
||
const TABLE_NAME = "behaviour_level_details"; | ||
|
||
export const up: 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, | ||
}, | ||
level: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
}, | ||
description: { | ||
type: DataType.STRING, | ||
allowNull: false, | ||
}, | ||
training_instructions: { | ||
type: DataType.STRING, | ||
allowNull: false, | ||
}, | ||
}); | ||
|
||
await sequelize.getQueryInterface().addConstraint(TABLE_NAME, { | ||
fields: ["behaviour_id", "level"], | ||
type: "unique", | ||
name: "unique_behaviour_level", | ||
}); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
await sequelize.getQueryInterface().dropTable(TABLE_NAME); | ||
}; |
17 changes: 17 additions & 0 deletions
17
backend/typescript/migrations/2024.10.22T19.42.10.add-behaviour-columns.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
import { Migration } from "../umzug"; | ||
|
||
export const up: Migration = async ({ context: sequelize }) => { | ||
await sequelize | ||
.getQueryInterface() | ||
.addColumn("behaviours", "parent_behaviour_id", { | ||
type: DataType.INTEGER, | ||
allowNull: true, | ||
}); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
await sequelize | ||
.getQueryInterface() | ||
.removeColumn("behaviours", "parent_behaviour_id"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import { Column, Model, Table } from "sequelize-typescript"; | ||
import { | ||
Column, | ||
DataType, | ||
ForeignKey, | ||
Model, | ||
Table, | ||
} from "sequelize-typescript"; | ||
|
||
@Table({ timestamps: false, tableName: "behaviours" }) | ||
export default class Behaviour extends Model { | ||
@Column | ||
@Column({ type: DataType.STRING, allowNull: false }) | ||
behaviour_name!: string; | ||
|
||
@ForeignKey(() => Behaviour) | ||
@Column({ type: DataType.INTEGER }) | ||
parent_behaviour_id?: number | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
Column, | ||
Model, | ||
Table, | ||
ForeignKey, | ||
DataType, | ||
} from "sequelize-typescript"; | ||
import Behaviour from "./behaviour.model"; | ||
import { BehaviourLevel } from "../types"; | ||
|
||
@Table({ timestamps: false, tableName: "behvaiour_level_details" }) | ||
export default class BehaviourLevelDetails extends Model { | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
id!: number; | ||
|
||
@ForeignKey(() => Behaviour) | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
behaviour_id!: number; | ||
|
||
@Column({ type: DataType.ENUM, allowNull: false }) | ||
level!: BehaviourLevel; | ||
|
||
@Column({ type: DataType.STRING, allowNull: false }) | ||
description!: string; | ||
|
||
@Column({ type: DataType.STRING, allowNull: false }) | ||
training_instructions!: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters