-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #997 from notaphplover/feat/update-game-db-entitie…
…s-with-game-history-ones Update game db entities with game history ones
- Loading branch information
Showing
28 changed files
with
423 additions
and
5 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 |
---|---|---|
|
@@ -21,6 +21,7 @@ components: | |
paths: | ||
/v1/auth: | ||
post: | ||
deprecated: true | ||
summary: Create an authorization token | ||
operationId: createAuth | ||
requestBody: | ||
|
@@ -629,6 +630,18 @@ paths: | |
requestBody: | ||
content: | ||
application/json: | ||
examples: | ||
authByCode: | ||
summary: User code | ||
value: | ||
code: 0077df18851946fb67e552b83f34d58283548c38c4c5f144e6b655280b773528 | ||
kind: code | ||
authByLogin: | ||
summary: User credentials | ||
value: | ||
email: [email protected] | ||
kind: login | ||
password: sample-password | ||
schema: | ||
$ref: 'https://onegame.schemas/api/v2/auth/auth-create-query.json' | ||
required: false | ||
|
55 changes: 55 additions & 0 deletions
55
...d-game-adapter-typeorm/src/app/adapter/typeorm/migrations/1708646400000-AddGameHistory.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,55 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class AddGameHistory1708646400000 implements MigrationInterface { | ||
public readonly name: string = 'AddGameHistory1708646400000'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "GameAction" ("id" character varying(36) NOT NULL, "payload" json NOT NULL, "position" smallint NOT NULL, "turn" smallint NOT NULL, "game_id" character varying(36) NOT NULL, CONSTRAINT "PK_504414b3ee4d764e8df48118c0e" PRIMARY KEY ("id"))`, | ||
); | ||
await queryRunner.query( | ||
`CREATE INDEX "IDX_030557ed95c9537ffb33536d49" ON "GameAction" ("game_id", "turn")`, | ||
); | ||
await queryRunner.query( | ||
`CREATE INDEX "IDX_7ed74975e34bbce332c8b58525" ON "GameAction" ("game_id", "position")`, | ||
); | ||
await queryRunner.query( | ||
`CREATE TABLE "GameInitialSnapshotSlot" ("cards" json NOT NULL, "id" character varying(36) NOT NULL, "position" smallint, "user_id" character varying(36) NOT NULL, "game_initial_snapshot_id" character varying(36) NOT NULL, CONSTRAINT "PK_ab9464398b172ed7ff9c00a397d" PRIMARY KEY ("id"))`, | ||
); | ||
await queryRunner.query( | ||
`CREATE TABLE "GameInitialSnapshot" ("current_card" bit(16) NOT NULL, "current_color" bit(16) NOT NULL, "current_direction" character varying(32) NOT NULL, "current_playing_slot" smallint NOT NULL, "deck" json NOT NULL, "draw_count" smallint NOT NULL, "id" character varying(36) NOT NULL, "game_id" character varying(36) NOT NULL, CONSTRAINT "PK_79de72d7a2e49d332bd7ad3ec41" PRIMARY KEY ("id"))`, | ||
); | ||
await queryRunner.query(`ALTER TABLE "Game" ADD "turn" smallint`); | ||
await queryRunner.query( | ||
`ALTER TABLE "GameAction" ADD CONSTRAINT "FK_4ccd5dc231685b49a5355edaa46" FOREIGN KEY ("game_id") REFERENCES "Game"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "GameInitialSnapshotSlot" ADD CONSTRAINT "FK_46af31c84986ba21bf4837025a5" FOREIGN KEY ("game_initial_snapshot_id") REFERENCES "GameInitialSnapshot"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "GameInitialSnapshot" ADD CONSTRAINT "FK_be95245a47a081f63be111e22b0" FOREIGN KEY ("game_id") REFERENCES "Game"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`, | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "GameInitialSnapshot" DROP CONSTRAINT "FK_be95245a47a081f63be111e22b0"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "GameInitialSnapshotSlot" DROP CONSTRAINT "FK_46af31c84986ba21bf4837025a5"`, | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "GameAction" DROP CONSTRAINT "FK_4ccd5dc231685b49a5355edaa46"`, | ||
); | ||
await queryRunner.query(`ALTER TABLE "Game" DROP COLUMN "turn"`); | ||
await queryRunner.query(`DROP TABLE "GameInitialSnapshot"`); | ||
await queryRunner.query(`DROP TABLE "GameInitialSnapshotSlot"`); | ||
await queryRunner.query( | ||
`DROP INDEX "public"."IDX_7ed74975e34bbce332c8b58525"`, | ||
); | ||
await queryRunner.query( | ||
`DROP INDEX "public"."IDX_030557ed95c9537ffb33536d49"`, | ||
); | ||
await queryRunner.query(`DROP TABLE "GameAction"`); | ||
} | ||
} |
12 changes: 11 additions & 1 deletion
12
.../apps/game/backend-game-adapter-typeorm/src/foundation/db/adapter/nest/models/entities.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 |
---|---|---|
@@ -1,6 +1,16 @@ | ||
import { GameActionDb } from '../../../../../games/adapter/typeorm/models/GameActionDb'; | ||
import { GameDb } from '../../../../../games/adapter/typeorm/models/GameDb'; | ||
import { GameInitialSnapshotDb } from '../../../../../games/adapter/typeorm/models/GameInitialSnapshotDb'; | ||
import { GameInitialSnapshotSlotDb } from '../../../../../games/adapter/typeorm/models/GameInitialSnapshotSlotDb'; | ||
import { GameSlotDb } from '../../../../../games/adapter/typeorm/models/GameSlotDb'; | ||
import { GameSpecDb } from '../../../../../games/adapter/typeorm/models/GameSpecDb'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
export const typeOrmEntities: Function[] = [GameDb, GameSlotDb, GameSpecDb]; | ||
export const typeOrmEntities: Function[] = [ | ||
GameActionDb, | ||
GameDb, | ||
GameInitialSnapshotDb, | ||
GameInitialSnapshotSlotDb, | ||
GameSlotDb, | ||
GameSpecDb, | ||
]; |
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
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
53 changes: 53 additions & 0 deletions
53
...d/apps/game/backend-game-adapter-typeorm/src/games/adapter/typeorm/models/GameActionDb.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,53 @@ | ||
import { | ||
Column, | ||
Entity, | ||
Index, | ||
JoinColumn, | ||
ManyToOne, | ||
PrimaryColumn, | ||
RelationId, | ||
} from 'typeorm'; | ||
|
||
import { GameDb } from './GameDb'; | ||
|
||
@Entity({ | ||
name: 'GameAction', | ||
}) | ||
@Index(['game', 'position']) | ||
@Index(['game', 'turn']) | ||
export class GameActionDb { | ||
@ManyToOne(() => GameDb, undefined, { nullable: false }) | ||
@JoinColumn({ name: 'game_id' }) | ||
public readonly game!: GameDb; | ||
|
||
@RelationId((gameAction: GameActionDb) => gameAction.game) | ||
public readonly gameId!: string; | ||
|
||
@PrimaryColumn({ | ||
length: 36, | ||
name: 'id', | ||
type: 'varchar', | ||
}) | ||
public readonly id!: string; | ||
|
||
@Column({ | ||
name: 'payload', | ||
nullable: false, | ||
type: 'json', | ||
}) | ||
public readonly payload!: string; | ||
|
||
@Column({ | ||
name: 'position', | ||
nullable: false, | ||
type: 'smallint', | ||
}) | ||
public readonly position!: number; | ||
|
||
@Column({ | ||
name: 'turn', | ||
nullable: false, | ||
type: 'smallint', | ||
}) | ||
public readonly turn!: number; | ||
} |
4 changes: 4 additions & 0 deletions
4
...ps/game/backend-game-adapter-typeorm/src/games/adapter/typeorm/models/GameActionKindDb.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,4 @@ | ||
export enum GameActionKindDb { | ||
passTurn = 'passTurn', | ||
playCards = 'playCards', | ||
} |
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
95 changes: 95 additions & 0 deletions
95
...me/backend-game-adapter-typeorm/src/games/adapter/typeorm/models/GameInitialSnapshotDb.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,95 @@ | ||
import { | ||
Column, | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
OneToMany, | ||
PrimaryColumn, | ||
RelationId, | ||
} from 'typeorm'; | ||
|
||
import { BinaryToNumberTransformer } from '../../../../foundation/db/adapter/typeorm/transformers/BinaryToNumberTransformer'; | ||
import { GameDb } from './GameDb'; | ||
import { GameDirectionDb } from './GameDirectionDb'; | ||
import { GameInitialSnapshotSlotDb } from './GameInitialSnapshotSlotDb'; | ||
|
||
@Entity({ | ||
name: 'GameInitialSnapshot', | ||
}) | ||
export class GameInitialSnapshotDb { | ||
@Column({ | ||
length: 16, | ||
name: 'current_card', | ||
nullable: false, | ||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers | ||
transformer: new BinaryToNumberTransformer(16), | ||
type: 'bit', | ||
}) | ||
public readonly currentCard!: number; | ||
|
||
@Column({ | ||
length: 16, | ||
name: 'current_color', | ||
nullable: false, | ||
// eslint-disable-next-line @typescript-eslint/no-magic-numbers | ||
transformer: new BinaryToNumberTransformer(16), | ||
type: 'bit', | ||
}) | ||
public readonly currentColor!: number; | ||
|
||
@Column({ | ||
length: 32, | ||
name: 'current_direction', | ||
nullable: false, | ||
type: 'varchar', | ||
}) | ||
public readonly currentDirection!: GameDirectionDb; | ||
|
||
@Column({ | ||
name: 'current_playing_slot', | ||
nullable: false, | ||
type: 'smallint', | ||
}) | ||
public readonly currentPlayingSlotIndex!: number; | ||
|
||
@Column({ | ||
name: 'deck', | ||
nullable: false, | ||
type: 'json', | ||
}) | ||
public readonly deck!: string; | ||
|
||
@Column({ | ||
name: 'draw_count', | ||
nullable: false, | ||
type: 'smallint', | ||
width: 4, | ||
}) | ||
public readonly drawCount!: number; | ||
|
||
@ManyToOne(() => GameDb, undefined, { nullable: false }) | ||
@JoinColumn({ name: 'game_id' }) | ||
public readonly game!: GameDb; | ||
|
||
@RelationId( | ||
(gameInitialSnapshot: GameInitialSnapshotDb) => gameInitialSnapshot.game, | ||
) | ||
public readonly gameId!: string; | ||
|
||
@OneToMany( | ||
() => GameInitialSnapshotSlotDb, | ||
(gameSlotDb: GameInitialSnapshotSlotDb): GameInitialSnapshotDb => | ||
gameSlotDb.gameInitialSnapshot, | ||
{ | ||
eager: true, | ||
}, | ||
) | ||
public readonly gameSlotsDb!: GameInitialSnapshotSlotDb[]; | ||
|
||
@PrimaryColumn({ | ||
length: 36, | ||
name: 'id', | ||
type: 'varchar', | ||
}) | ||
public readonly id!: string; | ||
} |
Oops, something went wrong.