-
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(rr): add database models (#518)
* chore(infraservice): remove unused prop * chore(routes/auth): remove unused var * build(package): add useful command to undo migration * feat(migrations): add migrations for review requests fix(db migratino): update property names * chore(db migration): add migration to add status col to rr * chore(db migrations): add required columns for seq creation * feat(db/models): add new db models for rr fix(db models): update db models fix(reviewmeat): update db model * chore(reviewrequest): update db model for seq * fix(reviewmeta): add annotation on db model * chore(reviewrequest.ts): add col to db model * fix(teardown): add enum dropping for tests teardown
- Loading branch information
Showing
6 changed files
with
145 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
DataType, | ||
Column, | ||
Model, | ||
Table, | ||
ForeignKey, | ||
} from "sequelize-typescript" | ||
|
||
import { ReviewRequest } from "./ReviewRequest" | ||
import { User } from "./User" | ||
|
||
@Table({ tableName: "review_meta" }) | ||
// eslint-disable-next-line import/prefer-default-export | ||
export class ReviewMeta extends Model { | ||
@Column({ | ||
autoIncrement: true, | ||
primaryKey: true, | ||
allowNull: false, | ||
type: DataType.BIGINT, | ||
}) | ||
id!: number | ||
|
||
@ForeignKey(() => User) | ||
reviewerId!: number | ||
|
||
@ForeignKey(() => ReviewRequest) | ||
@Column | ||
reviewId!: number | ||
|
||
@Column({ | ||
allowNull: false, | ||
type: DataType.BIGINT, | ||
}) | ||
pullRequestNumber!: number | ||
|
||
@Column({ | ||
allowNull: false, | ||
type: DataType.STRING, | ||
}) | ||
reviewLink!: string | ||
} |
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,68 @@ | ||
import { | ||
ForeignKey, | ||
DataType, | ||
Column, | ||
Model, | ||
Table, | ||
BelongsTo, | ||
BelongsToMany, | ||
HasOne, | ||
} from "sequelize-typescript" | ||
|
||
import { Site } from "@database/models/Site" | ||
import { User } from "@database/models/User" | ||
|
||
import { Reviewer } from "./Reviewers" | ||
import { ReviewMeta } from "./ReviewMeta" | ||
|
||
@Table({ tableName: "review_requests" }) | ||
// eslint-disable-next-line import/prefer-default-export | ||
export class ReviewRequest extends Model { | ||
@Column({ | ||
autoIncrement: true, | ||
primaryKey: true, | ||
allowNull: false, | ||
type: DataType.BIGINT, | ||
}) | ||
id!: number | ||
|
||
@ForeignKey(() => User) | ||
requestorId!: number | ||
|
||
// NOTE: Because this is a FK to User, | ||
// when User is updated/deleted, | ||
// the corresponding row in ReviewRequest will also be updated. | ||
@BelongsTo(() => User, { | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}) | ||
requestor!: User | ||
|
||
@ForeignKey(() => Site) | ||
siteId!: number | ||
|
||
// See above comment wrt CASCADE | ||
@BelongsTo(() => Site, { | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
}) | ||
site!: Site | ||
|
||
@HasOne(() => ReviewMeta) | ||
reviewMeta!: ReviewMeta | ||
|
||
@Column({ | ||
allowNull: false, | ||
defaultValue: "OPEN", | ||
type: DataType.ENUM("OPEN", "APPROVED", "MERGED", "CLOSED"), | ||
}) | ||
reviewStatus!: "OPEN" | "APPROVED" | "MERGED" | "CLOSED" | ||
|
||
@BelongsToMany(() => User, { | ||
onUpdate: "CASCADE", | ||
onDelete: "CASCADE", | ||
through: () => Reviewer, | ||
as: "reviewers", | ||
}) | ||
reviewers!: User[] | ||
} |
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,24 @@ | ||
import { | ||
Column, | ||
CreatedAt, | ||
DataType, | ||
ForeignKey, | ||
Model, | ||
Table, | ||
UpdatedAt, | ||
} from "sequelize-typescript" | ||
|
||
import { User } from "@database/models/User" | ||
|
||
import { ReviewRequest } from "./ReviewRequest" | ||
|
||
@Table({ tableName: "reviewers" }) | ||
export class Reviewer extends Model { | ||
@ForeignKey(() => User) | ||
@Column | ||
reviewerId!: number | ||
|
||
@ForeignKey(() => ReviewRequest) | ||
@Column | ||
requestId!: string | ||
} |
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