Skip to content

Commit a2aee64

Browse files
.
1 parent a200318 commit a2aee64

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
import fs from "fs";
3+
import path from "path";
4+
5+
const MIGRATIONS_DIR = path.resolve(__dirname, "../typescript/migrations");
6+
7+
const migrationName = process.argv[2];
8+
9+
if (!migrationName) {
10+
console.error(
11+
"❌ Please provide a migration name. Usage: ts-node scripts/createMigration.ts create-reviewed-applications",
12+
);
13+
process.exit(1);
14+
}
15+
16+
const timestamp = new Date()
17+
.toISOString()
18+
.replace(/[-:.TZ]/g, "")
19+
.slice(0, 14);
20+
const fileName = `${timestamp}-${migrationName}.ts`;
21+
const filePath = path.join(MIGRATIONS_DIR, fileName);
22+
23+
const template = `import { DataType } from "sequelize-typescript";
24+
import { Migration } from "../umzug";
25+
26+
const TABLE_NAME = "your table name here";
27+
28+
export const up: Migration = async ({ context: sequelize }) => {
29+
30+
};
31+
32+
export const down: Migration = async ({ context: sequelize }) => {
33+
};
34+
`;
35+
36+
fs.writeFileSync(filePath, template);
37+
console.log(`✅ Migration created: ${filePath}`);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { DataType } from "sequelize-typescript";
2+
3+
import { Migration } from "../umzug";
4+
5+
const TABLE_NAME = "reviewed-applications";
6+
7+
export const up: Migration = async ({ context: sequelize }) => {
8+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
9+
id: {
10+
type: DataType.INTEGER,
11+
allowNull: false,
12+
primaryKey: true,
13+
autoIncrement: true,
14+
unique: true,
15+
},
16+
applicationId: {
17+
type: DataType.STRING,
18+
allowNull: false,
19+
},
20+
reveiweId: {
21+
type: DataType.STRING,
22+
allowNull: false,
23+
},
24+
review: {
25+
type: DataType.STRING,
26+
allowNull: true,
27+
},
28+
email: {
29+
type: DataType.STRING,
30+
primaryKey: true,
31+
allowNull: false,
32+
},
33+
role: {
34+
type: DataType.ENUM("User", "Admin"),
35+
allowNull: false,
36+
},
37+
createdAt: DataType.DATE,
38+
updatedAt: DataType.DATE,
39+
});
40+
41+
// await sequelize.getQueryInterface().bulkInsert(TABLE_NAME, SEEDED_DATA);
42+
};
43+
44+
export const down: Migration = async ({ context: sequelize }) => {
45+
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
46+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { Migration } from "../umzug";
3+
4+
const TABLE_NAME = "your table name here";
5+
6+
export const up: Migration = async ({ context: sequelize }) => {
7+
8+
};
9+
10+
export const down: Migration = async ({ context: sequelize }) => {
11+
};
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint import/no-cycle: 0 */
2+
3+
import {
4+
Column,
5+
DataType,
6+
ForeignKey,
7+
HasMany,
8+
Model,
9+
Table,
10+
} from "sequelize-typescript";
11+
import ApplicationDashboardTable from "./applicationDashboard.model";
12+
import User from "./user.model";
13+
import { Review, ReviewStatus, ReviewStatusEnum } from "../types";
14+
import Application from "./application.model";
15+
16+
@Table({ tableName: "reviewed_applications" })
17+
export default class ReviewedApplication extends Model {
18+
@Column({ type: DataType.INTEGER, primaryKey: true, autoIncrement: true })
19+
id!: number;
20+
21+
@ForeignKey(() => Application)
22+
@Column({ type: DataType.INTEGER })
23+
applicationId!: number;
24+
25+
@ForeignKey(() => User)
26+
@Column({ type: DataType.INTEGER })
27+
reviewId!: number;
28+
29+
@Column({ type: DataType.JSONB })
30+
review!: Review;
31+
32+
@Column({
33+
type: DataType.ENUM(...Object.values(ReviewStatusEnum)),
34+
defaultValue: ReviewStatusEnum.TODO,
35+
})
36+
status!: ReviewStatus;
37+
38+
@Column({ type: DataType.DATE })
39+
submittedAt!: Date;
40+
41+
@Column({ type: DataType.DATE })
42+
createdAt!: Date;
43+
44+
// TODO: Add when Jesse's PR is merged
45+
@HasMany(() => ApplicationDashboardTable)
46+
applicationDashboards?: ApplicationDashboardTable[];
47+
}

0 commit comments

Comments
 (0)