-
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.
- Loading branch information
1 parent
8a5fd21
commit 9156318
Showing
12 changed files
with
407 additions
and
343 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
backend/typescript/migrations/2024.10.09T02.40.17.rename-activity-table-to-activity-type.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,54 @@ | ||
import { DataType } from "sequelize-typescript"; | ||
import { Migration } from "../umzug"; | ||
|
||
const OLD_TABLE_NAME = "activities"; | ||
const NEW_TABLE_NAME = "activity_types"; | ||
const USER_PET_ACTIVITIES_TABLE = "user_pet_activities"; | ||
|
||
export const up: Migration = async ({ context: sequelize }) => { | ||
// Rename the activities table to activity_types | ||
await sequelize | ||
.getQueryInterface() | ||
.renameTable(OLD_TABLE_NAME, NEW_TABLE_NAME); | ||
|
||
// Change the activity_id column in user_pet_activities to activity_type_id | ||
await sequelize | ||
.getQueryInterface() | ||
.renameColumn(USER_PET_ACTIVITIES_TABLE, "activity_id", "activity_type_id"); | ||
|
||
// Update the references for activity_type_id to point to the new activity_types table | ||
await sequelize | ||
.getQueryInterface() | ||
.changeColumn(USER_PET_ACTIVITIES_TABLE, "activity_type_id", { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: NEW_TABLE_NAME, // Reference the new table name | ||
key: "id", | ||
}, | ||
}); | ||
}; | ||
|
||
export const down: Migration = async ({ context: sequelize }) => { | ||
// Rename the activity_types table back to activities | ||
await sequelize | ||
.getQueryInterface() | ||
.renameTable(NEW_TABLE_NAME, OLD_TABLE_NAME); | ||
|
||
// Revert the activity_type_id column back to activity_id | ||
await sequelize | ||
.getQueryInterface() | ||
.renameColumn(USER_PET_ACTIVITIES_TABLE, "activity_type_id", "activity_id"); | ||
|
||
// Revert the activity_id column to reference the old activities table | ||
await sequelize | ||
.getQueryInterface() | ||
.changeColumn(USER_PET_ACTIVITIES_TABLE, "activity_id", { | ||
type: DataType.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: OLD_TABLE_NAME, // Revert back to the old table name | ||
key: "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,56 @@ | ||
import { Column, Model, Table } from "sequelize-typescript"; | ||
import { | ||
Column, | ||
Model, | ||
Table, | ||
DataType, | ||
ForeignKey, | ||
BelongsTo, | ||
} from "sequelize-typescript"; | ||
import User from "./user.model"; | ||
import Pet from "./pet.model"; | ||
import ActivityType from "./activityType.model"; | ||
|
||
@Table({ timestamps: false, tableName: "activities" }) | ||
@Table({ timestamps: false, tableName: "user_pet_activities" }) | ||
export default class Activity extends Model { | ||
@Column | ||
activity_name!: string; | ||
@Column({}) | ||
user_pet_activity_id!: number; | ||
|
||
@ForeignKey(() => User) // in case of null, task has not been assigned | ||
@Column({}) | ||
user_id?: number; | ||
|
||
@BelongsTo(() => User) | ||
user?: User; | ||
|
||
@ForeignKey(() => Pet) | ||
@Column({}) | ||
pet_id!: number; | ||
|
||
@BelongsTo(() => Pet) | ||
pet!: Pet; | ||
|
||
@ForeignKey(() => ActivityType) | ||
@Column({}) | ||
activity_type_id!: number; | ||
|
||
@BelongsTo(() => ActivityType) | ||
activity_type!: ActivityType; | ||
|
||
@Column({}) | ||
scheduled_start_time?: Date; | ||
|
||
@Column({}) | ||
start_time?: Date; | ||
|
||
@Column({}) | ||
end_time?: Date; | ||
|
||
@Column({ type: DataType.TEXT }) | ||
notes?: string; | ||
|
||
@Column({}) | ||
created_at!: Date; | ||
|
||
@Column({}) | ||
updated_at?: Date; | ||
} |
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 { Column, Model, Table } from "sequelize-typescript"; | ||
|
||
@Table({ timestamps: false, tableName: "activity_types" }) | ||
export default class ActivityType extends Model { | ||
@Column | ||
activity_name!: string; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.