inmemory to postgres

This commit is contained in:
2025-12-29 19:44:11 +01:00
parent f5639a367f
commit 12ae6e1dad
17 changed files with 361 additions and 94 deletions

View File

@@ -62,6 +62,7 @@ export type RacingSeed = {
export type RacingSeedOptions = {
driverCount?: number;
baseDate?: Date;
persistence?: 'postgres' | 'inmemory';
};
export const racingSeedDefaults: Readonly<
@@ -69,33 +70,36 @@ export const racingSeedDefaults: Readonly<
> = {
driverCount: 100,
baseDate: new Date(),
persistence: 'inmemory',
};
class RacingSeedFactory {
private readonly driverCount: number;
private readonly baseDate: Date;
private readonly persistence: 'postgres' | 'inmemory';
constructor(options: RacingSeedOptions) {
this.driverCount = options.driverCount ?? racingSeedDefaults.driverCount;
this.baseDate = options.baseDate ?? racingSeedDefaults.baseDate;
this.persistence = options.persistence ?? racingSeedDefaults.persistence;
}
create(): RacingSeed {
const driverFactory = new RacingDriverFactory(this.driverCount, this.baseDate);
const driverFactory = new RacingDriverFactory(this.driverCount, this.baseDate, this.persistence);
const trackFactory = new RacingTrackFactory();
const raceFactory = new RacingRaceFactory(this.baseDate);
const resultFactory = new RacingResultFactory();
const raceFactory = new RacingRaceFactory(this.baseDate, this.persistence);
const resultFactory = new RacingResultFactory(this.persistence);
const standingFactory = new RacingStandingFactory();
const membershipFactory = new RacingMembershipFactory(this.baseDate);
const sponsorFactory = new RacingSponsorFactory(this.baseDate);
const seasonSponsorshipFactory = new RacingSeasonSponsorshipFactory(this.baseDate);
const leagueWalletFactory = new RacingLeagueWalletFactory(this.baseDate);
const membershipFactory = new RacingMembershipFactory(this.baseDate, this.persistence);
const sponsorFactory = new RacingSponsorFactory(this.baseDate, this.persistence);
const seasonSponsorshipFactory = new RacingSeasonSponsorshipFactory(this.baseDate, this.persistence);
const leagueWalletFactory = new RacingLeagueWalletFactory(this.baseDate, this.persistence);
const friendshipFactory = new RacingFriendshipFactory();
const feedFactory = new RacingFeedFactory(this.baseDate);
const feedFactory = new RacingFeedFactory(this.baseDate, this.persistence);
const drivers = driverFactory.create();
const tracks = trackFactory.create();
const leagueFactory = new RacingLeagueFactory(this.baseDate, drivers);
const leagueFactory = new RacingLeagueFactory(this.baseDate, drivers, this.persistence);
const leagues = leagueFactory.create();
const sponsors = sponsorFactory.create();
const seasons = seasonSponsorshipFactory.createSeasons(leagues);
@@ -107,7 +111,7 @@ class RacingSeedFactory {
const { wallets: leagueWallets, transactions: leagueWalletTransactions } = leagueWalletFactory.create(leagues);
const teamFactory = new RacingTeamFactory(this.baseDate);
const teamFactory = new RacingTeamFactory(this.baseDate, this.persistence);
const teams = teamFactory.createTeams(drivers, leagues);
const races = raceFactory.create(leagues, tracks);
const results = resultFactory.create(drivers, races);
@@ -116,7 +120,7 @@ class RacingSeedFactory {
const teamMemberships = teamFactory.createTeamMemberships(drivers, teams);
const teamJoinRequests = teamFactory.createTeamJoinRequests(drivers, teams, teamMemberships);
const stewardingFactory = new RacingStewardingFactory(this.baseDate);
const stewardingFactory = new RacingStewardingFactory(this.baseDate, this.persistence);
const { protests, penalties } = stewardingFactory.create(races, drivers, leagueMemberships);
const friendships = friendshipFactory.create(drivers);