Skip to content

Commit

Permalink
add pet table
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity-y committed Jun 22, 2024
1 parent 9e1ad96 commit a440a50
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ const TABLE_NAME = "animal_types";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
animal_type_id: {
id: {
type: DataType.INTEGER,
primaryKey: true,
autoIncrement: true,
},
animal_type_name: {
type: DataType.STRING,
allowNull: false,
},
createdAt: DataType.DATE,
updatedAt: DataType.DATE,
}
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { DataType } from "sequelize-typescript";

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

const TABLE_NAME = "pets";

export const up: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
id: {
type: DataType.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
},
animal_type_id: {
type: DataType.INTEGER,
allowNull: false,
references: {
model: "animal_types",
key: "id",
},
},
name: {
type: DataType.STRING,
allowNull: false,
},
breed: {
type: DataType.STRING,
allowNull: false,
},
age: {
type: DataType.INTEGER,
allowNull: false,
},
adoption_status: {
type: DataType.BOOLEAN,
allowNull: false,
},
// pet_care_info_id: {
// type: DataType.INTEGER,
// allowNull: true,
// references: {
// model: "pet_care_info",
// key: "pet_care_info_id"
// },
// onDelete: "SET NULL"
// },
weight: {
type: DataType.DECIMAL,
allowNull: false,
},
spayed: {
type: DataType.BOOLEAN,
allowNull: false,
},
sex: {
type: DataType.ENUM("M", "F"),
allowNull: false,
},
photo: {
type: DataType.STRING,
allowNull: false,
},
createdAt: {
type: DataType.DATE,
allowNull: false,
},
updatedAt: {
type: DataType.DATE,
allowNull: true,
},
});
};

export const down: Migration = async ({ context: sequelize }) => {
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
};
9 changes: 4 additions & 5 deletions backend/typescript/models/animal_type.model.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { Column, Model, Table, DataType, HasMany, PrimaryKey, AutoIncrement } from "sequelize-typescript";
// import {Pet} from "./Pet"
import Pet from "./pet.model"
@Table({ tableName: "animal_types" })
export default class Animal_Type extends Model {
@PrimaryKey
@AutoIncrement
@Column({
type: DataType.INTEGER,
})
animal_type_id!: number;
id!: number;

@Column({
type: DataType.STRING,
allowNull:false
})
animal_type_name!: string;

//@HasMany(() => Pet)
//pets!: Pet[];
@HasMany(() => Pet)
pets!: Pet[];
}
55 changes: 55 additions & 0 deletions backend/typescript/models/pet.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Column, Model, Table, DataType, ForeignKey, BelongsTo } from "sequelize-typescript";
import Animal_Type from "./animal_type.model"
//import { PetCareInfo } from "./PetCareInfo"

import { Letters } from "../types";

@Table({ tableName: "entities" })
export default class Pet extends Model {
@Column ({ type: DataType.INTEGER })
id!: number;

@ForeignKey(() => Animal_Type)
@Column ({ type: DataType.INTEGER })
animal_type_id!: number;

@BelongsTo(() => Animal_Type)
animal_type!: Animal_Type;

@Column ({ type: DataType.STRING })
name!: string;

@Column ({ type: DataType.STRING })
breed!: string;

@Column ({ type: DataType.INTEGER })
age!: number;

@Column ({ type: DataType.BOOLEAN })
adoption_status!: boolean;

// @ForeignKey(() => PetCareInfo)
// @Column ({ type: DataType.INTEGER })
// pet_care_info_id?: number;

// @BelongsTo(() => PetCareInfo)
// petCareInfo?: PetCareInfo;

@Column ({ type: DataType.DECIMAL })
weight!: number;

@Column({ type: DataType.BOOLEAN })
spayed!: boolean;

@Column({ type: DataType.ENUM("M", "F") })
sex!: Letters;

@Column({ type: DataType.STRING })
photo!: string;

@Column ({ type: DataType.DATE })
created_at!: Date;

@Column ({ type: DataType.DATE })
updated_at?: Date;
}

0 comments on commit a440a50

Please sign in to comment.