-
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.
🧬 Experiment Citus over Redis for data persistance
- Loading branch information
Showing
27 changed files
with
2,243 additions
and
261 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,52 @@ | ||
import type { Playsig } from "core/types/playsig.js"; | ||
import type { PublicKey } from "core/types/public-key.js"; | ||
import type { Hero } from "core/types/hero.js"; | ||
import type { Appellation } from "core/types/appellation.js"; | ||
import type { Money } from "core/types/money.js"; | ||
import type { Level } from "core/types/level.js"; | ||
import type { Health } from "core/types/health.js"; | ||
import type { Combat } from "core/types/combat.js"; | ||
import type { Phase } from "core/types/phase.js"; | ||
import type { DateTime } from "core/types/date-time.js"; | ||
import { Entity, PrimaryKey, Property, Unique } from "@mikro-orm/core"; | ||
|
||
@Entity() | ||
class Game { | ||
@PrimaryKey() | ||
playsig: Playsig; | ||
|
||
@Property({ type: "json" }) | ||
publicKeys: PublicKey[]; | ||
|
||
@Property({ type: "json" }) | ||
nicknames: Record<PublicKey, string>; | ||
|
||
@Property({ type: "json" }) | ||
playerHeroes: Record<PublicKey, Hero[]>; | ||
|
||
@Property({ type: "json" }) | ||
playerBenches: Record<PublicKey, Record<number, Hero>>; | ||
|
||
@Property({ type: "json" }) | ||
playerShops: Record<PublicKey, Appellation[]>; | ||
|
||
@Property({ type: "json" }) | ||
playerMoney: Record<PublicKey, Money>; | ||
|
||
@Property({ type: "json" }) | ||
playerLevel: Record<PublicKey, Level>; | ||
|
||
@Property({ type: "json" }) | ||
playerHealths: Record<PublicKey, Health>; | ||
|
||
@Property({ type: "json", nullable: true }) | ||
combats?: Combat[]; | ||
|
||
@Property() | ||
phase: Phase; | ||
|
||
@Property() | ||
phaseStartAt: DateTime; | ||
} | ||
|
||
export const GameEntity = Game; |
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 type { Pool as PoolType } from "core/types/pool.js"; | ||
import { Entity, PrimaryKey, Property, Unique } from "@mikro-orm/core"; | ||
|
||
@Entity() | ||
class Pool { | ||
@PrimaryKey() | ||
playsig: string; | ||
|
||
@Property({ type: "json" }) | ||
heroes: PoolType["heroes"]; | ||
} | ||
|
||
export const PoolEntity = Pool; |
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,18 @@ | ||
import type { PublicKey } from "core/types/public-key.js"; | ||
import type { Nickname } from "core/types/nickname.js"; | ||
import type { DateTime } from "core/types/date-time.js"; | ||
import { Entity, PrimaryKey, Property, Unique } from "@mikro-orm/core"; | ||
|
||
@Entity() | ||
class Queuer { | ||
@PrimaryKey() | ||
publicKey: PublicKey; | ||
|
||
@Property() | ||
nickname: Nickname; | ||
|
||
@Property() | ||
createdAt: DateTime; | ||
} | ||
|
||
export const QueuerEntity = Queuer; |
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,224 @@ | ||
{ | ||
"namespaces": ["public"], | ||
"name": "public", | ||
"tables": [ | ||
{ | ||
"columns": { | ||
"playsig": { | ||
"name": "playsig", | ||
"type": "varchar(255)", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 255, | ||
"mappedType": "string" | ||
}, | ||
"public_keys": { | ||
"name": "public_keys", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"nicknames": { | ||
"name": "nicknames", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"player_heroes": { | ||
"name": "player_heroes", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"player_benches": { | ||
"name": "player_benches", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"player_shops": { | ||
"name": "player_shops", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"player_money": { | ||
"name": "player_money", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"player_level": { | ||
"name": "player_level", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"player_healths": { | ||
"name": "player_healths", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
}, | ||
"combats": { | ||
"name": "combats", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": true, | ||
"mappedType": "json" | ||
}, | ||
"phase": { | ||
"name": "phase", | ||
"type": "varchar(255)", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 255, | ||
"mappedType": "string" | ||
}, | ||
"phase_start_at": { | ||
"name": "phase_start_at", | ||
"type": "varchar(255)", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 255, | ||
"mappedType": "string" | ||
} | ||
}, | ||
"name": "game", | ||
"schema": "public", | ||
"indexes": [ | ||
{ | ||
"keyName": "game_pkey", | ||
"columnNames": ["playsig"], | ||
"composite": false, | ||
"constraint": true, | ||
"primary": true, | ||
"unique": true | ||
} | ||
], | ||
"checks": [], | ||
"foreignKeys": {}, | ||
"nativeEnums": {} | ||
}, | ||
{ | ||
"columns": { | ||
"playsig": { | ||
"name": "playsig", | ||
"type": "varchar(255)", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 255, | ||
"mappedType": "string" | ||
}, | ||
"heroes": { | ||
"name": "heroes", | ||
"type": "jsonb", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"mappedType": "json" | ||
} | ||
}, | ||
"name": "pool", | ||
"schema": "public", | ||
"indexes": [ | ||
{ | ||
"keyName": "pool_pkey", | ||
"columnNames": ["playsig"], | ||
"composite": false, | ||
"constraint": true, | ||
"primary": true, | ||
"unique": true | ||
} | ||
], | ||
"checks": [], | ||
"foreignKeys": {}, | ||
"nativeEnums": {} | ||
}, | ||
{ | ||
"columns": { | ||
"public_key": { | ||
"name": "public_key", | ||
"type": "varchar(255)", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 255, | ||
"mappedType": "string" | ||
}, | ||
"nickname": { | ||
"name": "nickname", | ||
"type": "varchar(255)", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 255, | ||
"mappedType": "string" | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "varchar(255)", | ||
"unsigned": false, | ||
"autoincrement": false, | ||
"primary": false, | ||
"nullable": false, | ||
"length": 255, | ||
"mappedType": "string" | ||
} | ||
}, | ||
"name": "queuer", | ||
"schema": "public", | ||
"indexes": [ | ||
{ | ||
"keyName": "queuer_pkey", | ||
"columnNames": ["public_key"], | ||
"composite": false, | ||
"constraint": true, | ||
"primary": true, | ||
"unique": true | ||
} | ||
], | ||
"checks": [], | ||
"foreignKeys": {}, | ||
"nativeEnums": {} | ||
} | ||
], | ||
"nativeEnums": {} | ||
} |
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 { Migration } from "@mikro-orm/migrations"; | ||
|
||
export class Migration20241220101918 extends Migration { | ||
override async up(): Promise<void> { | ||
this.addSql( | ||
`create table "game" ("playsig" varchar(255) not null, "public_keys" jsonb not null, "nicknames" jsonb not null, "player_heroes" jsonb not null, "player_benches" jsonb not null, "player_shops" jsonb not null, "player_money" jsonb not null, "player_level" jsonb not null, "player_healths" jsonb not null, "combats" jsonb null, "phase" varchar(255) not null, "phase_start_at" varchar(255) not null, constraint "game_pkey" primary key ("playsig"));`, | ||
); | ||
|
||
this.addSql( | ||
`create table "pool" ("playsig" varchar(255) not null, "heroes" jsonb not null, constraint "pool_pkey" primary key ("playsig"));`, | ||
); | ||
|
||
this.addSql( | ||
`create table "queuer" ("public_key" varchar(255) not null, "nickname" varchar(255) not null, "created_at" varchar(255) not null, constraint "queuer_pkey" primary key ("public_key"));`, | ||
); | ||
} | ||
} |
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 @@ | ||
# Migrations | ||
|
||
This directory is automatically generated with MikroORM migration cli. | ||
|
||
## How to create a new migrations ? | ||
|
||
docker compose down -v | ||
docker compose up -d --build back | ||
docker compose exec back bun run migration:create | ||
docker compose cp back:/autochess/back/migrations ./back/ |
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,20 @@ | ||
import { defineConfig } from "@mikro-orm/postgresql"; | ||
import { GameEntity } from "./entities/game.js"; | ||
import { QueuerEntity } from "./entities/queuer.js"; | ||
import { PoolEntity } from "./entities/pool.js"; | ||
import { Migrator } from "@mikro-orm/migrations"; | ||
|
||
export default defineConfig({ | ||
entities: [GameEntity, QueuerEntity, PoolEntity], | ||
extensions: [Migrator], | ||
host: "citus", | ||
dbName: process.env.MONGODB_DATABASE, | ||
user: process.env.MONGODB_USERNAME, | ||
password: process.env.MONGODB_PASSWORD, | ||
migrations: { | ||
tableName: "mikro_orm_migrations", | ||
path: "./migrations", | ||
transactional: true, | ||
allOrNothing: true, | ||
}, | ||
}); |
Oops, something went wrong.