-
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.
Merge pull request #40 from uwblueprint/F24/julia/add-user-animal-typ…
…e-table Added user animal type table
- Loading branch information
Showing
4 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
backend/typescript/migrations/2024.10.04T00.23.02.create-user-animal-types-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,36 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
|
||
import { Migration } from "../umzug"; | ||
|
||
const TABLE_NAME = "user_animal_types"; | ||
|
||
export const up: Migration = async ({ context: sequelize }) => { | ||
await sequelize.getQueryInterface().createTable(TABLE_NAME, { | ||
user_id: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
animal_type_id: { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: "animal_types", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
}); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
await sequelize.getQueryInterface().dropTable(TABLE_NAME); | ||
}; |
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
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,7 @@ | ||
import User from "./user.model"; | ||
import AnimalType from "./animalType.model"; | ||
import UserAnimalType from "./userAnimalType.model"; | ||
|
||
export default function defineRelationships(): void { | ||
User.belongsToMany(AnimalType, { through: UserAnimalType }); | ||
} |
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,26 @@ | ||
import { | ||
Column, | ||
DataType, | ||
Model, | ||
Table, | ||
ForeignKey, | ||
PrimaryKey, | ||
} from "sequelize-typescript"; | ||
import User from "./user.model"; | ||
import AnimalType from "./animalType.model"; | ||
|
||
@Table({ | ||
tableName: "User_AnimalTypes", | ||
timestamps: true, | ||
}) | ||
export default class UserAnimalType extends Model { | ||
@ForeignKey(() => User) | ||
@PrimaryKey | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
user_id!: number; | ||
|
||
@ForeignKey(() => AnimalType) | ||
@PrimaryKey | ||
@Column({ type: DataType.INTEGER, allowNull: false }) | ||
animal_type_id!: number; | ||
} |