-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add model and migration for review_request_views table (#521)
* feat: add model and migration for review_request_views table * chore: rename migration * fix: add missing association with ReviewRequest model * fix: revert adding association in ReviewRequest model * fix: missing @column for primary and foreign key * fix: add new database table to sequelize
- Loading branch information
1 parent
b93e81f
commit 2e4eeb8
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/database/migrations/20221012064037-create-review-request-views.js
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,59 @@ | ||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
await queryInterface.createTable("review_request_views", { | ||
review_request_id: { | ||
allowNull: false, | ||
primaryKey: true, | ||
type: Sequelize.BIGINT, | ||
references: { | ||
model: "review_requests", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
site_id: { | ||
type: Sequelize.BIGINT, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: "sites", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
user_id: { | ||
type: Sequelize.BIGINT, | ||
allowNull: false, | ||
primaryKey: true, | ||
references: { | ||
model: "users", | ||
key: "id", | ||
}, | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}, | ||
last_viewed_at: { | ||
type: Sequelize.DATE, | ||
allowNull: true, | ||
defaultValue: null, | ||
}, | ||
created_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.fn("NOW"), | ||
}, | ||
updated_at: { | ||
type: Sequelize.DATE, | ||
allowNull: false, | ||
defaultValue: Sequelize.fn("NOW"), | ||
}, | ||
}) | ||
}, | ||
|
||
async down(queryInterface, Sequelize) { | ||
await queryInterface.dropTable("review_request_views") | ||
}, | ||
} |
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,56 @@ | ||
import { | ||
ForeignKey, | ||
DataType, | ||
Column, | ||
Model, | ||
Table, | ||
BelongsTo, | ||
PrimaryKey, | ||
} from "sequelize-typescript" | ||
|
||
import { ReviewRequest } from "@database/models/ReviewRequest" | ||
import { Site } from "@database/models/Site" | ||
import { User } from "@database/models/User" | ||
|
||
@Table({ tableName: "review_request_views" }) | ||
// eslint-disable-next-line import/prefer-default-export | ||
export class ReviewRequestView extends Model { | ||
@ForeignKey(() => ReviewRequest) | ||
@PrimaryKey | ||
@Column | ||
reviewRequestId!: number | ||
|
||
@BelongsTo(() => ReviewRequest, { | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}) | ||
reviewRequest!: ReviewRequest | ||
|
||
@ForeignKey(() => Site) | ||
@PrimaryKey | ||
@Column | ||
siteId!: number | ||
|
||
@BelongsTo(() => Site, { | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}) | ||
site!: Site | ||
|
||
@ForeignKey(() => User) | ||
@PrimaryKey | ||
@Column | ||
userId!: number | ||
|
||
@BelongsTo(() => User, { | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}) | ||
user!: User | ||
|
||
@Column({ | ||
allowNull: true, | ||
type: DataType.DATE, | ||
}) | ||
lastViewedAt!: 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
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