Skip to content

Commit f9b0f87

Browse files
Merge pull request #33 from aureateAnatidae/guilds_users
Add guilds, seasons
2 parents 376ed80 + f7acf59 commit f9b0f87

38 files changed

Lines changed: 1362 additions & 511 deletions

apps/backend/.swcrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
},
1010
"baseUrl": "src",
1111
"paths": {
12-
"@seeds/*": ["../seeds/*"],
1312
"@test/*": ["test/*"],
1413
"@db/*": ["db/*"],
1514
"@v1/*": ["v1/*"]

apps/backend/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
},
1212
"dependencies": {
1313
"@hono/node-server": "^1.19.7",
14-
"@hono/standard-validator": "^0.2.0",
15-
"@hono/zod-validator": "^0.7.5",
14+
"@hono/standard-validator": "^0.2.1",
15+
"@hono/zod-validator": "^0.7.6",
1616
"@logtape/hono": "^1.3.5",
1717
"@logtape/logtape": "^1.3.5",
1818
"better-sqlite3": "^12.5.0",
19-
"hono": "^4.10.8",
19+
"hono": "^4.11.3",
2020
"hono-openapi": "^1.1.2",
2121
"knex": "^3.1.0",
22-
"zod": "^4.1.13"
22+
"zod": "^4.3.5"
2323
},
2424
"devDependencies": {
25-
"@faker-js/faker": "^10.1.0"
25+
"@faker-js/faker": "^10.2.0"
2626
}
2727
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { seed as SSBUCharacters_seed } from "@db/seeds/SSBUCharacters";
12
import { getLogger } from "@logtape/logtape";
2-
import { seed as SSBUCharacters_seed } from "@seeds/SSBUCharacters";
33
import type { Knex } from "knex";
44

55
const log = getLogger(["grindcord", "db"]);
66

77
// Seek more customizable API where list of seeds can be provided to the seedsource
8-
export class SeedSource {
8+
export class BaseSeedSource {
99
getSeeds() {
1010
return Promise.resolve(["SSBUCharacters"]);
1111
}

apps/backend/src/db/init_tables.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
11
import { knexDb } from "@db/knexfile";
22
import { getLogger } from "@logtape/logtape";
3+
import { GuildSeasonTable } from "@v1/guild/models";
34
import {
45
MatchCharacterTable,
56
MatchPlayerTable,
67
MatchTable,
78
SSBUCharTable,
89
} from "@v1/match/models";
910
import { MatchReportView, MatchWinnerView } from "@v1/match/views";
11+
import { SeasonTable } from "@v1/season/models";
1012
import type { Knex } from "knex";
1113

1214
const log = getLogger(["grindcord", "db"]);
1315

14-
const tables = [MatchTable, MatchPlayerTable, MatchCharacterTable, SSBUCharTable];
16+
const tables = [
17+
MatchTable,
18+
MatchPlayerTable,
19+
MatchCharacterTable,
20+
SSBUCharTable,
21+
SeasonTable,
22+
GuildSeasonTable,
23+
];
1524
const views = [MatchWinnerView, MatchReportView];
1625

1726
async function create_table_if_notexists(
@@ -31,7 +40,7 @@ async function create_table_if_notexists(
3140
}
3241
}
3342

34-
export async function init_tables(db: Knex = knexDb) {
43+
export async function init_tables(db: Knex = knexDb): Promise<void> {
3544
const trx = await db.transaction();
3645
for (const table of tables) {
3746
await create_table_if_notexists(trx, table.table_name, table.initialize);
@@ -40,6 +49,13 @@ export async function init_tables(db: Knex = knexDb) {
4049
await trx.commit();
4150
}
4251

52+
export async function seed_db(
53+
seedSource: Knex.SeedSource<unknown>,
54+
db: Knex = knexDb,
55+
): Promise<void> {
56+
await db.seed.run({ seedSource });
57+
}
58+
4359
export async function init_views(db: Knex = knexDb) {
4460
const trx = await db.transaction();
4561
for (const _view of views) {

apps/backend/src/db/knexfile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { SeedSource } from "@db/SeedSource";
21
import knex, { type Knex } from "knex";
2+
import { BaseSeedSource } from "./BaseSeedSource";
33

44
// TODO: https://knexjs.org/guide/#log
55
export const config: Knex.Config<Knex.Sqlite3ConnectionConfig> = {
66
client: "better-sqlite3",
77
connection: {
8-
filename: "./bot_data.db",
8+
filename: "./grindcord.db",
99
},
1010
seeds: {
11-
seedSource: new SeedSource(),
11+
seedSource: new BaseSeedSource(),
1212
},
1313
useNullAsDefault: true,
1414
};

apps/backend/src/db/schemas.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.
File renamed without changes.

apps/backend/src/db/test/unit.test.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

apps/backend/src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import { init_tables, init_views, teardown } from "@db/init_tables";
1+
import { BaseSeedSource as SSBUCharacterSeedSource } from "@db/BaseSeedSource";
2+
import { init_tables, init_views, seed_db } from "@db/init_tables";
23
import { serve } from "@hono/node-server";
34
import { honoLogger } from "@logtape/hono";
45
import { configure, getConsoleSink } from "@logtape/logtape";
6+
import guild_router from "@v1/guild/router";
57
import match_router from "@v1/match/router";
6-
import user_router from "@v1/user/router";
8+
import season_router from "@v1/season/router";
79
import { Hono } from "hono";
810
import { requestId } from "hono/request-id";
911
import { openAPIRouteHandler } from "hono-openapi";
@@ -18,8 +20,10 @@ await configure({
1820

1921
const app = new Hono({ strict: false });
2022

21-
await teardown();
2223
await init_tables();
24+
25+
await seed_db(new SSBUCharacterSeedSource());
26+
2327
await init_views();
2428

2529
app.use(requestId());
@@ -30,6 +34,9 @@ app.get("/", (c) => {
3034
});
3135

3236
app.route("/match", match_router);
37+
app.route("/season", season_router);
38+
app.route("/guild", guild_router);
39+
// app.route("/user", _router);
3340

3441
app.get(
3542
"/openapi.json",

apps/backend/src/test/MockSeedSource.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)