-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
73 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,13 @@ | ||
import { OrganizationInterface } from '@isomera/interfaces' | ||
import { PrimaryGeneratedColumn, JoinColumn, ManyToOne } from 'typeorm' | ||
|
||
import { UserEntity } from './user.entity' | ||
|
||
export class OrganizationEntity implements OrganizationInterface { | ||
@PrimaryGeneratedColumn('increment') | ||
id: number | ||
|
||
@ManyToOne(() => UserEntity, user => user.id) | ||
@JoinColumn() | ||
user: UserEntity | ||
} |
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
47 changes: 47 additions & 0 deletions
47
apps/api/src/migrations/1701953109158-create-organizations-table.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,47 @@ | ||
import { | ||
MigrationInterface, | ||
QueryRunner, | ||
Table, | ||
TableColumn, | ||
TableForeignKey | ||
} from 'typeorm' | ||
|
||
export class CreateOrganizationsTable1701953109158 | ||
implements MigrationInterface | ||
{ | ||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.createTable( | ||
new Table({ | ||
name: 'organizations', | ||
columns: [ | ||
new TableColumn({ | ||
name: 'id', | ||
type: 'int', | ||
isPrimary: true, | ||
isGenerated: true, | ||
generationStrategy: 'increment' | ||
}), | ||
new TableColumn({ | ||
name: 'userId', | ||
type: 'int' | ||
}) | ||
] | ||
}) | ||
) | ||
|
||
await queryRunner.createForeignKey( | ||
'organizations', | ||
new TableForeignKey({ | ||
name: 'FK_user_of_organization', | ||
columnNames: ['userId'], | ||
referencedColumnNames: ['id'], | ||
referencedTableName: 'users', | ||
onDelete: 'CASCADE' | ||
}) | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.dropTable('organizations') | ||
} | ||
} |
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,6 @@ | ||
import { UserInterface } from '../user/User.interface' | ||
|
||
export interface OrganizationInterface { | ||
id?: number | ||
user: UserInterface | ||
} |
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