Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add model and migration for review_request_views table #521

Merged
merged 6 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: {
dcshzj marked this conversation as resolved.
Show resolved Hide resolved
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")
},
}
56 changes: 56 additions & 0 deletions src/database/models/ReviewRequestView.ts
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
}
1 change: 1 addition & 0 deletions src/database/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from "@database/models/ReviewMeta"
export * from "@database/models/ReviewRequest"
export * from "@database/models/Reviewers"
export * from "@database/models/Notification"
export * from "@database/models/ReviewRequestView"
3 changes: 3 additions & 0 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ReviewRequest,
ReviewMeta,
Reviewer,
ReviewRequestView,
} from "@database/models"
import bootstrap from "@root/bootstrap"
import {
Expand Down Expand Up @@ -58,6 +59,8 @@ const sequelize = initSequelize([
ReviewRequest,
ReviewMeta,
Reviewer,
ReviewRequest,
ReviewRequestView,
])
const usersService = getUsersService(sequelize)

Expand Down
2 changes: 2 additions & 0 deletions src/tests/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
ReviewRequest,
ReviewMeta,
Reviewer,
ReviewRequestView,
} from "@database/models"

const sequelize = new Sequelize({
Expand All @@ -33,6 +34,7 @@ sequelize.addModels([
ReviewRequest,
ReviewMeta,
Reviewer,
ReviewRequestView,
])

// eslint-disable-next-line import/prefer-default-export
Expand Down