Skip to content

Commit c964dbc

Browse files
committed
database onboarding
1 parent 83b1a51 commit c964dbc

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { DataType } from "sequelize-typescript";
2+
import { Migration } from "../umzug";
3+
import { teamRoleValues } from "../types";
4+
5+
const TABLE_NAME = "team_members";
6+
7+
export const up: Migration = async ({ context: sequelize }) => {
8+
await sequelize.getQueryInterface().createTable(TABLE_NAME, {
9+
id: {
10+
type: DataType.UUID,
11+
defaultValue: DataType.UUIDV4,
12+
allowNull: false,
13+
primaryKey: true,
14+
},
15+
firstName: {
16+
type: DataType.STRING,
17+
allowNull: false,
18+
},
19+
lastName: {
20+
type: DataType.STRING,
21+
allowNull: false,
22+
},
23+
teamRole: {
24+
type: DataType.ENUM(...teamRoleValues),
25+
allowNull: false,
26+
},
27+
createdAt: {
28+
type: DataType.DATE,
29+
allowNull: false,
30+
defaultValue: DataType.NOW,
31+
},
32+
updatedAt: {
33+
type: DataType.DATE,
34+
allowNull: false,
35+
defaultValue: DataType.NOW,
36+
},
37+
});
38+
};
39+
40+
export const down: Migration = async ({ context: sequelize }) => {
41+
await sequelize.getQueryInterface().dropTable(TABLE_NAME);
42+
await sequelize
43+
.getQueryInterface()
44+
.sequelize.query(`DROP TYPE IF EXISTS "enum_${TABLE_NAME}_teamRole";`);
45+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Column, DataType, Model, Table } from "sequelize-typescript";
2+
import { TeamRole, teamRoleValues } from "../types";
3+
4+
@Table({ tableName: "team_members" })
5+
export default class TeamMember extends Model {
6+
@Column({
7+
type: DataType.UUID,
8+
defaultValue: DataType.UUIDV4,
9+
primaryKey: true,
10+
})
11+
id!: string;
12+
13+
@Column({ type: DataType.STRING, allowNull: false })
14+
firstName!: string;
15+
16+
@Column({ type: DataType.STRING, allowNull: false })
17+
lastName!: string;
18+
19+
@Column({
20+
type: DataType.ENUM(...teamRoleValues),
21+
allowNull: false,
22+
})
23+
teamRole!: TeamRole;
24+
}

backend/typescript/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export type Role = "User" | "Admin";
22

3+
export const teamRoleValues = ["PM", "Designer", "PL", "Developer"] as const;
4+
export type TeamRole = typeof teamRoleValues[number];
5+
36
export enum StatusType {
47
ACCEPTED = "accepted",
58
APPLIED = "applied",

0 commit comments

Comments
 (0)