-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add project and project relations entities (#8421)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
- Loading branch information
Showing
11 changed files
with
121 additions
and
2 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
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,17 @@ | ||
import { Column, Entity, OneToMany } from 'typeorm'; | ||
import { WithTimestampsAndStringId } from './AbstractEntity'; | ||
import type { ProjectRelation } from './ProjectRelation'; | ||
|
||
export type ProjectType = 'personal' | 'team' | 'public'; | ||
|
||
@Entity() | ||
export class Project extends WithTimestampsAndStringId { | ||
@Column({ length: 255 }) | ||
name: string; | ||
|
||
@Column({ length: 36 }) | ||
type: ProjectType; | ||
|
||
@OneToMany('ProjectRelation', 'project') | ||
projectRelations: ProjectRelation[]; | ||
} |
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,28 @@ | ||
import { Column, Entity, ManyToOne, PrimaryColumn } from 'typeorm'; | ||
import { User } from './User'; | ||
import { WithTimestamps } from './AbstractEntity'; | ||
import { Project } from './Project'; | ||
|
||
export type ProjectRole = | ||
| 'project:admin' | ||
| 'project:editor' | ||
| 'project:workflowEditor' | ||
| 'project:viewer'; | ||
|
||
@Entity() | ||
export class ProjectRelation extends WithTimestamps { | ||
@Column() | ||
role: ProjectRole; | ||
|
||
@ManyToOne('User', 'projectRelations') | ||
user: User; | ||
|
||
@PrimaryColumn('uuid') | ||
userId: string; | ||
|
||
@ManyToOne('Project', 'projectRelations') | ||
project: Project; | ||
|
||
@PrimaryColumn() | ||
projectId: 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
38 changes: 38 additions & 0 deletions
38
packages/cli/src/databases/migrations/common/1705928727784-CreateProject.ts
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,38 @@ | ||
import type { MigrationContext, ReversibleMigration } from '@db/types'; | ||
|
||
const tableName = 'project'; | ||
const relationTableName = 'project_relation'; | ||
|
||
export class CreateProject1705928727784 implements ReversibleMigration { | ||
async up({ schemaBuilder: { createTable, column } }: MigrationContext) { | ||
await createTable(tableName).withColumns( | ||
column('id').varchar(36).primary.notNull, | ||
column('name').varchar(255), | ||
column('type').varchar(36), | ||
).withTimestamps; | ||
|
||
await createTable(relationTableName) | ||
.withColumns( | ||
column('projectId').varchar(36).primary.notNull, | ||
column('userId').uuid.primary.notNull, | ||
column('role').varchar().notNull, | ||
) | ||
.withIndexOn('projectId') | ||
.withIndexOn('userId') | ||
.withForeignKey('projectId', { | ||
tableName, | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}) | ||
.withForeignKey('userId', { | ||
tableName: 'user', | ||
columnName: 'id', | ||
onDelete: 'CASCADE', | ||
}).withTimestamps; | ||
} | ||
|
||
async down({ schemaBuilder: { dropTable } }: MigrationContext) { | ||
await dropTable(relationTableName); | ||
await dropTable(tableName); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
packages/cli/src/databases/repositories/project.repository.ts
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,10 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { Project } from '../entities/Project'; | ||
|
||
@Service() | ||
export class ProjectRepository extends Repository<Project> { | ||
constructor(dataSource: DataSource) { | ||
super(Project, dataSource.manager); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/cli/src/databases/repositories/projectRelation.repository.ts
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,10 @@ | ||
import { Service } from 'typedi'; | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { ProjectRelation } from '../entities/ProjectRelation'; | ||
|
||
@Service() | ||
export class ProjectRelationRepository extends Repository<ProjectRelation> { | ||
constructor(dataSource: DataSource) { | ||
super(ProjectRelation, dataSource.manager); | ||
} | ||
} |