Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import LeaderboardEntry from './leaderboard-entry.js'
import Leaderboard from './leaderboard.js'
import OrganisationPricingPlan from './organisation-pricing-plan.js'
import Organisation from './organisation.js'
import PlayerAliasSubscriptionProp from './player-alias-subscription-prop.js'
import PlayerAliasSubscription from './player-alias-subscription.js'
import PlayerAlias from './player-alias.js'
import PlayerAuthActivity from './player-auth-activity.js'
Expand All @@ -50,6 +51,7 @@ import UserTwoFactorAuth from './user-two-factor-auth.js'
import User from './user.js'

export const entities = [
PlayerAliasSubscriptionProp,
ScheduledGameConfigChange,
EventRetention,
EventFunnel,
Expand Down
34 changes: 34 additions & 0 deletions src/entities/player-alias-subscription-prop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/decorators/es'
import PlayerAliasSubscription from './player-alias-subscription.js'
import { MAX_KEY_LENGTH, MAX_VALUE_LENGTH } from './prop.js'

@Entity()
export default class PlayerAliasSubscriptionProp {
@PrimaryKey()
id!: number

@ManyToOne(() => PlayerAliasSubscription, { deleteRule: 'cascade' })
subscription: PlayerAliasSubscription

@Property({ length: MAX_KEY_LENGTH })
key: string

@Property({ length: MAX_VALUE_LENGTH })
value: string

@Property()
createdAt: Date = new Date()

constructor(subscription: PlayerAliasSubscription, key: string, value: string) {
this.subscription = subscription
this.key = key
this.value = value
}

toJSON() {
return {
key: this.key,
value: this.value,
}
}
}
14 changes: 14 additions & 0 deletions src/entities/player-alias-subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import {
Enum,
Index,
ManyToOne,
OneToMany,
PrimaryKey,
Property,
Unique,
} from '@mikro-orm/decorators/es'
import { Collection } from '@mikro-orm/mysql'
import PlayerAliasSubscriptionProp from './player-alias-subscription-prop.js'
import PlayerAlias from './player-alias.js'

export enum RelationshipType {
Expand All @@ -33,6 +36,12 @@ export default class PlayerAliasSubscription {
@Enum(() => RelationshipType)
relationshipType: RelationshipType = RelationshipType.UNIDIRECTIONAL

@OneToMany(() => PlayerAliasSubscriptionProp, (prop) => prop.subscription, {
eager: true,
orphanRemoval: true,
})
props: Collection<PlayerAliasSubscriptionProp> = new Collection<PlayerAliasSubscriptionProp>(this)

@Property()
createdAt: Date = new Date()

Expand Down Expand Up @@ -61,13 +70,18 @@ export default class PlayerAliasSubscription {
this.relationshipType = relationshipType
}

setProps(props: { key: string; value: string }[]) {
this.props.set(props.map(({ key, value }) => new PlayerAliasSubscriptionProp(this, key, value)))
}

toJSON() {
return {
id: this.id,
subscriber: this.subscriber,
subscribedTo: this.subscribedTo,
confirmed: this.confirmed,
relationshipType: this.relationshipType,
props: this.props,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
}
Expand Down
121 changes: 121 additions & 0 deletions src/migrations/.snapshot-gs_dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -5537,6 +5537,127 @@
},
"comment": null
},
{
"name": "player_alias_subscription_prop",
"columns": {
"created_at": {
"name": "created_at",
"type": "datetime",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"unique": false,
"length": null,
"precision": null,
"scale": null,
"default": null,
"comment": null,
"collation": null,
"enumItems": [],
"mappedType": "datetime"
},
"id": {
"name": "id",
"type": "int",
"unsigned": true,
"autoincrement": true,
"primary": true,
"nullable": false,
"unique": false,
"length": null,
"precision": null,
"scale": null,
"default": null,
"comment": null,
"collation": null,
"enumItems": [],
"mappedType": "integer"
},
"key": {
"name": "key",
"type": "varchar(128)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"unique": false,
"length": 128,
"precision": null,
"scale": null,
"default": null,
"comment": null,
"collation": null,
"enumItems": [],
"mappedType": "string"
},
"subscription_id": {
"name": "subscription_id",
"type": "int",
"unsigned": true,
"autoincrement": false,
"primary": false,
"nullable": false,
"unique": false,
"length": null,
"precision": null,
"scale": null,
"default": null,
"comment": null,
"collation": null,
"enumItems": [],
"mappedType": "integer"
},
"value": {
"name": "value",
"type": "varchar(512)",
"unsigned": false,
"autoincrement": false,
"primary": false,
"nullable": false,
"unique": false,
"length": 512,
"precision": null,
"scale": null,
"default": null,
"comment": null,
"collation": null,
"enumItems": [],
"mappedType": "string"
}
},
"indexes": [
{
"columnNames": ["id"],
"composite": false,
"constraint": true,
"keyName": "PRIMARY",
"primary": true,
"unique": true
},
{
"columnNames": ["subscription_id"],
"composite": false,
"constraint": false,
"keyName": "player_alias_subscription_prop_subscription_id_index",
"primary": false,
"unique": false
}
],
"checks": [],
"triggers": [],
"foreignKeys": {
"player_alias_subscription_prop_subscription_id_foreign": {
"columnNames": ["subscription_id"],
"constraintName": "player_alias_subscription_prop_subscription_id_foreign",
"localTableName": "player_alias_subscription_prop",
"referencedColumnNames": ["id"],
"referencedTableName": "player_alias_subscription",
"deleteRule": "cascade"
}
},
"comment": null
},
{
"name": "player_auth",
"columns": {
Expand Down
21 changes: 21 additions & 0 deletions src/migrations/20261012050921AddPlayerAliasSubscriptionProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Migration } from '@mikro-orm/migrations'

export class AddPlayerAliasSubscriptionProps extends Migration {
override async up(): Promise<void> {
this.addSql(
'create table `player_alias_subscription_prop` (`id` int unsigned not null auto_increment primary key, `subscription_id` int unsigned not null, `key` varchar(128) not null, `value` varchar(512) not null, `created_at` datetime not null) default character set utf8mb4 engine = InnoDB;',
)

this.addSql(
'alter table `player_alias_subscription_prop` add index `player_alias_subscription_prop_subscription_id_index` (`subscription_id`);',
)

this.addSql(
'alter table `player_alias_subscription_prop` add constraint `player_alias_subscription_prop_subscription_id_foreign` foreign key (`subscription_id`) references `player_alias_subscription` (`id`) on delete cascade;',
)
}

override async down(): Promise<void> {
this.addSql('drop table if exists `player_alias_subscription_prop`;')
}
}
2 changes: 2 additions & 0 deletions src/migrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ import { CreateScheduledGameConfigChangesTable } from './20260914074716CreateSch
import { AddAdminAPIKeyToScheduledGameConfigChanges } from './20261004085201AddAdminAPIKeyToScheduledGameConfigChanges.js'
import { AddDowngradeNoticeColumns } from './20261007190000AddDowngradeNoticeColumns.js'
import { AddDevBuildToLeaderboardEntry } from './20261009113941AddDevBuildToLeaderboardEntry.js'
import { AddPlayerAliasSubscriptionProps } from './20261012050921AddPlayerAliasSubscriptionProps.js'

export default [
InitialMigration,
Expand Down Expand Up @@ -188,4 +189,5 @@ export default [
AddAdminAPIKeyToScheduledGameConfigChanges,
AddDowngradeNoticeColumns,
AddDevBuildToLeaderboardEntry,
AddPlayerAliasSubscriptionProps,
]
Loading
Loading