Skip to content

Commit

Permalink
feat(rr): db migrations (#515)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
seaerchin authored Oct 14, 2022
1 parent ec83a78 commit c84c64c
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 9 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"prepare": "husky install",
"version": "auto-changelog -p && git add CHANGELOG.md",
"db:migrate": "source .env && npx sequelize-cli db:migrate",
"db:migrate:undo": "source .env && npx sequelize-cli db:migrate:undo",
"jump:staging": "source .ssh/.env.staging && ssh -L 5433:$DB_HOST:5432 $SSH_USER@$SSH_HOST -i .ssh/isomercms-staging-bastion.pem",
"db:migrate:staging": "source .ssh/.env.staging && npx sequelize-cli db:migrate",
"jump:prod": "source .ssh/.env.prod && ssh -L 5433:$DB_HOST:5432 $SSH_USER@$SSH_HOST -i .ssh/isomercms-production-bastion.pem",
Expand Down
43 changes: 43 additions & 0 deletions src/database/migrations/20221003052424-review-request-creation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable("review_requests", {
id: {
allowNull: false,
primaryKey: true,
type: Sequelize.BIGINT,
autoIncrement: true,
},
requestor_id: {
type: Sequelize.BIGINT,
allowNull: false,
references: {
model: "users",
key: "id",
},
},
site_id: {
type: Sequelize.BIGINT,
allowNull: false,
references: {
model: "sites",
key: "id",
},
},
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_requests")
},
}
46 changes: 46 additions & 0 deletions src/database/migrations/20221003123422-review-meta-creation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable("review_meta", {
id: {
allowNull: false,
primaryKey: true,
autoIncrement: true,
type: Sequelize.BIGINT,
},
review_id: {
type: Sequelize.BIGINT,
allowNull: false,
references: {
model: "review_requests",
key: "id",
},
},
// The PR number stored by GitHub
pull_request_number: {
type: Sequelize.BIGINT,
allowNull: false,
},
// The link to view this RR
review_link: {
unique: true,
type: Sequelize.STRING,
allowNull: false,
},
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_meta")
},
}
43 changes: 43 additions & 0 deletions src/database/migrations/20221003130006-reviewer-creation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("reviewers", {
request_id: {
allowNull: false,
primaryKey: true,
type: Sequelize.BIGINT,
references: {
model: "review_requests",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
reviewer_id: {
type: Sequelize.BIGINT,
allowNull: false,
primaryKey: true,
references: {
model: "users",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
created_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.fn("NOW"),
},
updated_at: {
type: Sequelize.DATE,
allowNull: false,
defaultValue: Sequelize.fn("NOW"),
},
})
},

down: async (queryInterface) => {
await queryInterface.dropTable("reviewers")
},
}
30 changes: 30 additions & 0 deletions src/database/migrations/20221007124138-create-review-status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
up: async (queryInterface, Sequelize) =>
queryInterface.sequelize.transaction(async (t) => {
await queryInterface.addColumn(
"review_requests", // name of Source model
"review_status", // name of column we're adding
{
type: Sequelize.ENUM,
values: ["OPEN", "MERGED", "CLOSED", "APPROVED"],
allowNull: false,
defaultValue: "OPEN",
transaction: t,
}
)
}),

down: async (queryInterface, _) =>
queryInterface.sequelize.transaction(async (t) => {
await queryInterface.removeColumn(
"review_requests", // name of Source Model
"review_status", // name of column we want to remove
{ transaction: t }
)
// drop created enum
await queryInterface.sequelize.query(
"drop type enum_review_requests_review_status;",
{ transaction: t }
)
}),
}
2 changes: 0 additions & 2 deletions src/routes/v2/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const { attachReadRouteHandlerWrapper } = require("@middleware/routeHandler")
const { FRONTEND_URL } = process.env
const { isSecure } = require("@utils/auth-utils")

const { AuthError } = require("@errors/AuthError")

const AUTH_TOKEN_EXPIRY_MS = parseInt(
process.env.AUTH_TOKEN_EXPIRY_DURATION_IN_MILLISECONDS,
10
Expand Down
8 changes: 1 addition & 7 deletions src/services/infra/InfraService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import logger from "@root/logger/logger"
import DeploymentsService from "@services/identity/DeploymentsService"
import ReposService from "@services/identity/ReposService"
import SitesService from "@services/identity/SitesService"
import UsersService from "@services/identity/UsersService"

interface InfraServiceProps {
sitesService: SitesService
Expand All @@ -30,12 +29,7 @@ export default class InfraService {
this.deploymentsService = deploymentsService
}

createSite = async (
submissionId: string,
creator: User,
siteName: string,
repoName: string
) => {
createSite = async (creator: User, siteName: string, repoName: string) => {
let site: Site | undefined // For error handling
try {
// 1. Create a new site record in the Sites table
Expand Down

0 comments on commit c84c64c

Please sign in to comment.