From 6ab2112ea9c9fe529340e8c425d0a30b3bc363d1 Mon Sep 17 00:00:00 2001 From: Tau Date: Mon, 7 Oct 2019 21:02:43 -0400 Subject: [PATCH] Stop using SQL namespaces ("schemas") This is in preparation for a transition to SQLite. SQLite does have a similar concept called "attached databases", but it's kind of a pain to deal with if you're casually browsing a database from the `sqlite3` CLI so we'll just use some slightly uglier explicitly namespaced table name identifiers instead. --- schema/init/aime.sql | 28 +++--- schema/init/idz.sql | 125 +++++++++++++------------ schema/init/meta.sql | 2 +- schema/migrate/M0005-merge-schemas.sql | 81 ++++++++++++++++ src/aimedb/db.ts | 10 +- src/db.ts | 2 +- src/idz/db/backgrounds.ts | 6 +- src/idz/db/car.ts | 14 +-- src/idz/db/chara.ts | 4 +- src/idz/db/coursePlays.ts | 4 +- src/idz/db/missions.ts | 4 +- src/idz/db/profile.ts | 14 +-- src/idz/db/settings.ts | 4 +- src/idz/db/story.ts | 8 +- src/idz/db/team.ts | 10 +- src/idz/db/teamAuto.ts | 4 +- src/idz/db/teamMember.ts | 24 ++--- src/idz/db/teamReservation.ts | 20 ++-- src/idz/db/tickets.ts | 6 +- src/idz/db/timeAttack.ts | 14 +-- src/idz/db/titles.ts | 4 +- src/idz/db/unlocks.ts | 4 +- 22 files changed, 236 insertions(+), 156 deletions(-) create mode 100644 schema/migrate/M0005-merge-schemas.sql diff --git a/schema/init/aime.sql b/schema/init/aime.sql index ea98ed6..3b3d044 100644 --- a/schema/init/aime.sql +++ b/schema/init/aime.sql @@ -1,6 +1,4 @@ -create schema "aime"; - -create type "aime"."region" as enum ( +create type "aime_region" as enum ( 'JPN', 'HKG', 'SGP', @@ -8,38 +6,38 @@ create type "aime"."region" as enum ( 'USA' ); -create table "aime"."shop" ( +create table "aime_shop" ( "id" bigint primary key not null, "ext_id" integer not null, "name" text not null, - "region" "aime"."region" not null, - constraint "shop_uq" unique ("ext_id") + "region" "aime_region" not null, + constraint "aime_shop_uq" unique ("ext_id") ); -create table "aime"."machine" ( +create table "aime_machine" ( "id" bigint primary key not null, "shop_id" bigint not null - references "aime"."shop"("id"), + references "aime_shop"("id"), "pcb_id" text not null, "keychip_id" text not null, - constraint "machine_pcb_id_uq" unique ("pcb_id"), - constraint "machine_keychip_id_uq" unique ("keychip_id") + constraint "aime_machine_pcb_id_uq" unique ("pcb_id"), + constraint "aime_machine_keychip_id_uq" unique ("keychip_id") ); -create table "aime"."player" ( +create table "aime_player" ( "id" bigint primary key not null, "ext_id" integer not null, "register_time" timestamp not null, - constraint "player_uq" unique ("ext_id") + constraint "aime_player_uq" unique ("ext_id") ); -create table "aime"."card" ( +create table "aime_card" ( "id" bigint primary key not null, "player_id" bigint not null - references "aime"."player"("id") + references "aime_player"("id") on delete cascade, "nfc_id" text not null, "register_time" timestamp not null, "access_time" timestamp not null, - constraint "card_uq" unique ("nfc_id") + constraint "aime_card_uq" unique ("nfc_id") ); diff --git a/schema/init/idz.sql b/schema/init/idz.sql index c94d20e..a3c6d24 100644 --- a/schema/init/idz.sql +++ b/schema/init/idz.sql @@ -4,12 +4,12 @@ create schema "idz"; -create type "idz"."gender" as enum ('male', 'female'); +create type "idz_gender" as enum ('male', 'female'); -create table "idz"."profile" ( +create table "idz_profile" ( "id" bigint primary key not null, "player_id" bigint not null - references "aime"."player"("id") + references "aime_player"("id") on delete cascade, -- TODO shop_id "name" text not null, @@ -20,14 +20,14 @@ create table "idz"."profile" ( "mileage" integer not null, "register_time" timestamp not null, "access_time" timestamp not null, - constraint "profile_player_uq" unique ("player_id") + constraint "idz_profile_player_uq" unique ("player_id") ); -create table "idz"."chara" ( +create table "idz_chara" ( "id" bigint primary key not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, - "gender" "idz"."gender" not null, + "gender" "idz_gender" not null, "field_02" integer not null, "field_04" integer not null, "field_06" integer not null, @@ -39,20 +39,20 @@ create table "idz"."chara" ( "background" integer not null ); -create table "idz"."course_plays" ( +create table "idz_course_plays" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "course_no" smallint not null, "count" integer not null, - constraint "course_plays_uq" unique ("profile_id", "course_no") + constraint "idz_course_plays_uq" unique ("profile_id", "course_no") ); -create table "idz"."car" ( +create table "idz_car" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "selector" integer not null, "field_00" integer not null, @@ -69,32 +69,36 @@ create table "idz"."car" ( "field_5b" integer not null, "field_5c" integer not null, "field_5e" integer not null, - constraint "car_uq" unique ("profile_id", "selector") + constraint "idz_car_uq" unique ("profile_id", "selector") ); -create table "idz"."car_selection" ( +create table "idz_car_selection" ( "id" bigint primary key not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "car_id" bigint not null - references "idz"."car"("id") + references "idz_car"("id") on delete cascade ); -create table "idz"."solo_mission_state" ( +create table "idz_solo_mission_state" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "grid_no" smallint not null, "cell_no" smallint not null, "value" smallint not null, - constraint "solo_mission_state_uq" unique ("profile_id", "grid_no", "cell_no") + constraint "idz_solo_mission_state_uq" unique ( + "profile_id", + "grid_no", + "cell_no" + ) ); -create table "idz"."settings" ( +create table "idz_settings" ( "id" bigint primary key not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "music" smallint not null, "pack" bigint not null, @@ -102,29 +106,33 @@ create table "idz"."settings" ( "gauges" integer not null ); -create table "idz"."story_state" ( +create table "idz_story_state" ( "id" bigint primary key not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "x" smallint not null, "y" smallint not null ); -create table "idz"."story_cell_state" ( +create table "idz_story_cell_state" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "row_no" integer not null, "col_no" integer not null, "a" smallint not null, "b" smallint not null, - constraint story_cell_state_uq unique ("profile_id", "row_no", "col_no") + constraint "idz_story_cell_state_uq" unique ( + "profile_id", + "row_no", + "col_no" + ) ); -create table "idz"."free_car" ( +create table "idz_free_car" ( "id" bigint primary key not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "valid_from" timestamp not null -- Expiry cannot be controlled by the server @@ -132,10 +140,10 @@ create table "idz"."free_car" ( -- Times are stored as floating-point seconds -create table "idz"."ta_result" ( +create table "idz_ta_result" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "route_no" smallint not null, "total_time" float not null, @@ -146,10 +154,10 @@ create table "idz"."ta_result" ( "timestamp" timestamp not null ); -create table "idz"."ta_best" ( +create table "idz_ta_best" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "route_no" smallint not null, "total_time" float not null, @@ -158,32 +166,35 @@ create table "idz"."ta_best" ( "grade" smallint not null, -- TODO enum "car_selector" integer not null, "timestamp" timestamp not null, - constraint "ta_best_uq" unique ("profile_id", "route_no") + constraint "idz_ta_best_uq" unique ("profile_id", "route_no") ); -- TODO ta_section_best -create table "idz"."background_unlock" ( +create table "idz_background_unlock" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "background_no" smallint not null, - constraint "background_unlock_uq" unique ("profile_id", "background_no") + constraint "idz_background_unlock_uq" unique ( + "profile_id", + "background_no" + ) ); -create table "idz"."title_unlock" ( +create table "idz_title_unlock" ( "id" bigint primary key not null, "profile_id" bigint not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "title_no" smallint not null, - constraint "title_unlock_uq" unique ("profile_id", "title_no") + constraint "idz_title_unlock_uq" unique ("profile_id", "title_no") ); -create table "idz"."unlocks" ( +create table "idz_unlocks" ( "id" bigint primary key not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "cup" smallint not null, "gauges" integer not null, @@ -191,52 +202,42 @@ create table "idz"."unlocks" ( "last_mileage_reward" integer not null ); -create table "idz"."team" ( +create table "idz_team" ( "id" bigint primary key not null, "ext_id" integer not null, "name" text not null, "name_bg" smallint not null, "name_fx" smallint not null, "register_time" timestamp not null, - constraint "team_uq" unique ("ext_id") + constraint "idz_team_uq" unique ("ext_id") ); -create table "idz"."team" ( - "id" bigint primary key not null, - "ext_id" integer not null, - "name" text not null, - "name_bg" smallint not null, - "name_fx" smallint not null, - "register_time" timestamp not null, - constraint "team_uq" unique ("ext_id") -); - -create table "idz"."team_auto" ( +create table "idz_team_auto" ( "id" bigint primary key not null - references "idz"."team"("id") + references "idz_team"("id") on delete cascade, "serial_no" smallint not null, "name_idx" smallint not null, - constraint "team_auto_uq" unique ("serial_no", "name_idx") + constraint "idz_team_auto_uq" unique ("serial_no", "name_idx") ); -create table "idz"."team_member" ( +create table "idz_team_member" ( "id" bigint primary key not null - references "idz"."profile"("id") + references "idz_profile"("id") on delete cascade, "team_id" bigint not null - references "idz"."team"("id") + references "idz_team"("id") on delete cascade, "join_time" timestamp not null, "leader" boolean not null ); -create table "idz"."team_reservation" ( +create table "idz_team_reservation" ( "id" bigint primary key not null - references "aime"."player"("id") + references "aime_player"("id") on delete cascade, "team_id" bigint not null - references "idz"."team"("id") + references "idz_team"("id") on delete cascade, "join_time" timestamp not null, "leader" boolean not null diff --git a/schema/init/meta.sql b/schema/init/meta.sql index 4282f71..b5e5e1b 100644 --- a/schema/init/meta.sql +++ b/schema/init/meta.sql @@ -1,2 +1,2 @@ create table "meta" ("schemaver" integer not null); -insert into "meta" values (3); +insert into "meta" values (5); diff --git a/schema/migrate/M0005-merge-schemas.sql b/schema/migrate/M0005-merge-schemas.sql new file mode 100644 index 0000000..b88bc6d --- /dev/null +++ b/schema/migrate/M0005-merge-schemas.sql @@ -0,0 +1,81 @@ +alter type "aime"."region" set schema "public"; +alter type "region" rename to "aime_region"; + +alter table "aime"."shop" set schema "public"; +alter table "shop" rename to "aime_shop"; + +alter table "aime"."machine" set schema "public"; +alter table "machine" rename to "aime_machine"; + +alter table "aime"."player" set schema "public"; +alter table "player" rename to "aime_player"; + +alter table "aime"."card" set schema "public"; +alter table "card" rename to "aime_card"; + +---- + +alter type "idz"."gender" set schema "public"; +alter type "gender" rename to "idz_gender"; + +alter table "idz"."profile" set schema "public"; +alter table "profile" rename to "idz_profile"; + +alter table "idz"."chara" set schema "public"; +alter table "chara" rename to "idz_chara"; + +alter table "idz"."course_plays" set schema "public"; +alter table "course_plays" rename to "idz_course_plays"; + +alter table "idz"."car" set schema "public"; +alter table "car" rename to "idz_car"; + +alter table "idz"."car_selection" set schema "public"; +alter table "car_selection" rename to "idz_car_selection"; + +alter table "idz"."solo_mission_state" set schema "public"; +alter table "solo_mission_state" rename to "idz_solo_mission_state"; + +alter table "idz"."settings" set schema "public"; +alter table "settings" rename to "idz_settings"; + +alter table "idz"."story_state" set schema "public"; +alter table "story_state" rename to "idz_story_state"; + +alter table "idz"."story_cell_state" set schema "public"; +alter table "story_cell_state" rename to "idz_story_cell_state"; + +alter table "idz"."free_car" set schema "public"; +alter table "free_car" rename to "idz_free_car"; + +alter table "idz"."ta_result" set schema "public"; +alter table "ta_result" rename to "idz_ta_result"; + +alter table "idz"."ta_best" set schema "public"; +alter table "ta_best" rename to "idz_ta_best"; + +alter table "idz"."background_unlock" set schema "public"; +alter table "background_unlock" rename to "idz_background_unlock"; + +alter table "idz"."title_unlock" set schema "public"; +alter table "title_unlock" rename to "idz_title_unlock"; + +alter table "idz"."unlocks" set schema "public"; +alter table "unlocks" rename to "idz_unlocks"; + +alter table "idz"."team" set schema "public"; +alter table "team" rename to "idz_team"; + +alter table "idz"."team_auto" set schema "public"; +alter table "team_auto" rename to "idz_team_auto"; + +alter table "idz"."team_member" set schema "public"; +alter table "team_member" rename to "idz_team_member"; + +alter table "idz"."team_reservation" set schema "public"; +alter table "team_reservation" rename to "idz_team_reservation"; + +drop schema "idz"; +drop schema "aime"; + +update "meta" set "schemaver" = 5; diff --git a/src/aimedb/db.ts b/src/aimedb/db.ts index ae49fa0..4bdbdaf 100644 --- a/src/aimedb/db.ts +++ b/src/aimedb/db.ts @@ -11,8 +11,8 @@ class CardRepositoryImpl implements CardRepository { async lookup(luid: string, now: Date): Promise { const fetchSql = sql .select("c.id", "p.ext_id") - .from("aime.card c") - .join("aime.player p", { "c.player_id": "p.id" }) + .from("aime_card c") + .join("aime_player p", { "c.player_id": "p.id" }) .where("c.nfc_id", luid) .toParams(); @@ -26,7 +26,7 @@ class CardRepositoryImpl implements CardRepository { const extId = rows[0].ext_id; const touchSql = sql - .update("aime.card") + .update("aime_card") .set({ access_time: now }) .where("id", id) .toParams(); @@ -42,7 +42,7 @@ class CardRepositoryImpl implements CardRepository { const aimeId = generateExtId() as AimeId; const playerSql = sql - .insert("aime.player", { + .insert("aime_player", { id: playerId, ext_id: aimeId, register_time: now, @@ -52,7 +52,7 @@ class CardRepositoryImpl implements CardRepository { await this._conn.query(playerSql); const cardSql = sql - .insert("aime.card", { + .insert("aime_card", { id: cardId, player_id: playerId, nfc_id: luid, diff --git a/src/db.ts b/src/db.ts index b7b8047..b666023 100644 --- a/src/db.ts +++ b/src/db.ts @@ -5,7 +5,7 @@ import { Pool, PoolClient } from "pg"; export type Id = bigint & { __id: T }; const debug = logger("app:sql"); -const currentSchemaVer = 3; +const currentSchemaVer = 5; const pool = new Pool(); const fence = testConnection(); diff --git a/src/idz/db/backgrounds.ts b/src/idz/db/backgrounds.ts index ffa8db4..e2687cc 100644 --- a/src/idz/db/backgrounds.ts +++ b/src/idz/db/backgrounds.ts @@ -13,8 +13,8 @@ export class SqlBackgroundsRepository async loadAll(id: Id): Promise> { const loadSql = sql .select("bg.background_no") - .from("idz.background_unlock bg") - .join("idz.profile p", { "bg.profile_id": "p.id" }) + .from("idz_background_unlock bg") + .join("idz_profile p", { "bg.profile_id": "p.id" }) .where("p.id", id) .toParams(); @@ -40,7 +40,7 @@ export class SqlBackgroundsRepository } const saveSql = sql - .insert("idz.background_unlock", { + .insert("idz_background_unlock", { id: generateId(), profile_id: profileId, background_no: flag, diff --git a/src/idz/db/car.ts b/src/idz/db/car.ts index 02d4653..a71f793 100644 --- a/src/idz/db/car.ts +++ b/src/idz/db/car.ts @@ -32,7 +32,7 @@ export class SqlCarRepository implements CarRepository { async countCars(profileId: Id): Promise { const countSql = sql .select("count(*) result") - .from("idz.car c") + .from("idz_car c") .where("c.profile_id", profileId) .toParams(); @@ -45,7 +45,7 @@ export class SqlCarRepository implements CarRepository { async loadAllCars(profileId: Id): Promise { const loadSql = sql .select("c.*") - .from("idz.car c") + .from("idz_car c") .where("c.profile_id", profileId) .toParams(); @@ -57,8 +57,8 @@ export class SqlCarRepository implements CarRepository { async loadSelectedCar(profileId: Id): Promise { const loadSql = sql .select("c.*") - .from("idz.car c") - .join("idz.car_selection s", { "c.id": "s.car_id" }) + .from("idz_car c") + .join("idz_car_selection s", { "c.id": "s.car_id" }) .where("s.id", profileId) .toParams(); @@ -69,7 +69,7 @@ export class SqlCarRepository implements CarRepository { async saveCar(profileId: Id, car: Car): Promise { const saveSql = sql - .insert("idz.car", { + .insert("idz_car", { id: generateId(), profile_id: profileId, selector: car.selector, @@ -116,7 +116,7 @@ export class SqlCarRepository implements CarRepository { ): Promise { const findSql = sql .select("c.id") - .from("idz.car c") + .from("idz_car c") .where("c.profile_id", profileId) .where("c.selector", selector) .toParams(); @@ -129,7 +129,7 @@ export class SqlCarRepository implements CarRepository { } const saveSql = sql - .insert("idz.car_selection", { + .insert("idz_car_selection", { id: profileId, car_id: row.id, }) diff --git a/src/idz/db/chara.ts b/src/idz/db/chara.ts index 9126762..8714d46 100644 --- a/src/idz/db/chara.ts +++ b/src/idz/db/chara.ts @@ -27,7 +27,7 @@ export class SqlCharaRepository implements FacetRepository { async load(profileId: Id): Promise { const loadSql = sql .select("c.*") - .from("idz.chara c") + .from("idz_chara c") .where("c.id", profileId) .toParams(); @@ -39,7 +39,7 @@ export class SqlCharaRepository implements FacetRepository { async save(profileId: Id, chara: Chara): Promise { const saveSql = sql - .insert("idz.chara", { + .insert("idz_chara", { id: profileId, gender: chara.gender, field_02: chara.field_02, diff --git a/src/idz/db/coursePlays.ts b/src/idz/db/coursePlays.ts index aef10ef..cb17cce 100644 --- a/src/idz/db/coursePlays.ts +++ b/src/idz/db/coursePlays.ts @@ -12,7 +12,7 @@ export class SqlCoursePlaysRepository implements CoursePlaysRepository { async loadAll(profileId: Id): Promise> { const loadSql = sql .select("cp.course_no", "cp.count") - .from("idz.course_plays cp") + .from("idz_course_plays cp") .where("cp.profile_id", profileId) .toParams(); @@ -32,7 +32,7 @@ export class SqlCoursePlaysRepository implements CoursePlaysRepository { ): Promise { for (const [k, v] of plays) { const saveSql = sql - .insert("idz.course_plays", { + .insert("idz_course_plays", { id: generateId(), profile_id: profileId, course_no: k, diff --git a/src/idz/db/missions.ts b/src/idz/db/missions.ts index db6fcb6..9f94bf2 100644 --- a/src/idz/db/missions.ts +++ b/src/idz/db/missions.ts @@ -30,7 +30,7 @@ export class SqlMissionsRepository implements FacetRepository { const loadSoloSql = sql .select("sm.*") - .from("idz.solo_mission_state sm") + .from("idz_solo_mission_state sm") .where("sm.profile_id", profileId) .toParams(); @@ -56,7 +56,7 @@ export class SqlMissionsRepository implements FacetRepository { } const saveSql = sql - .insert("idz.solo_mission_state", { + .insert("idz_solo_mission_state", { id: generateId(), profile_id: profileId, grid_no: i, diff --git a/src/idz/db/profile.ts b/src/idz/db/profile.ts index 4691bf4..eb29273 100644 --- a/src/idz/db/profile.ts +++ b/src/idz/db/profile.ts @@ -36,8 +36,8 @@ export class SqlProfileRepository implements ProfileRepository { async peek(aimeId: AimeId): Promise | undefined> { const lookupSql = sql .select("p.id") - .from("idz.profile p") - .join("aime.player r", { "p.player_id": "r.id" }) + .from("idz_profile p") + .join("aime_player r", { "p.player_id": "r.id" }) .where("r.ext_id", aimeId) .toParams(); @@ -54,8 +54,8 @@ export class SqlProfileRepository implements ProfileRepository { async load(id: Id): Promise { const loadSql = sql .select("p.*", "r.ext_id as aime_id") - .from("idz.profile p") - .join("aime.player r", { "p.player_id": "r.id" }) + .from("idz_profile p") + .join("aime_player r", { "p.player_id": "r.id" }) .where("p.id", id) .toParams(); @@ -66,7 +66,7 @@ export class SqlProfileRepository implements ProfileRepository { async save(id: Id, profile: Profile): Promise { const saveSql = sql - .update("idz.profile", { + .update("idz_profile", { lv: profile.lv, exp: profile.exp, fame: profile.fame, @@ -83,7 +83,7 @@ export class SqlProfileRepository implements ProfileRepository { async create(profile: Profile): Promise> { const findSql = sql .select("r.id") - .from("aime.player r") + .from("aime_player r") .where("r.ext_id", profile.aimeId) .toParams(); @@ -98,7 +98,7 @@ export class SqlProfileRepository implements ProfileRepository { const playerId = row.id; const createSql = sql - .insert("idz.profile", { + .insert("idz_profile", { id: id, player_id: playerId, name: profile.name, diff --git a/src/idz/db/settings.ts b/src/idz/db/settings.ts index a44ab33..d07b05a 100644 --- a/src/idz/db/settings.ts +++ b/src/idz/db/settings.ts @@ -12,7 +12,7 @@ export class SqlSettingsRepository implements FacetRepository { async load(profileId: Id): Promise { const loadSql = sql .select("s.*") - .from("idz.settings s") + .from("idz_settings s") .where("s.id", profileId) .toParams(); @@ -29,7 +29,7 @@ export class SqlSettingsRepository implements FacetRepository { async save(profileId: Id, settings: Settings): Promise { const saveSql = sql - .insert("idz.settings", { + .insert("idz_settings", { id: profileId, music: settings.music, pack: settings.pack, diff --git a/src/idz/db/story.ts b/src/idz/db/story.ts index 9bc3776..cc0490c 100644 --- a/src/idz/db/story.ts +++ b/src/idz/db/story.ts @@ -12,7 +12,7 @@ export class SqlStoryRepository implements FacetRepository { async load(profileId: Id): Promise { const loadSql = sql .select("s.*") - .from("idz.story_state s") + .from("idz_story_state s") .where("s.id", profileId) .toParams(); @@ -39,7 +39,7 @@ export class SqlStoryRepository implements FacetRepository { const loadCellSql = sql .select("sc.*") - .from("idz.story_cell_state sc") + .from("idz_story_cell_state sc") .where("sc.profile_id", profileId) .toParams(); @@ -59,7 +59,7 @@ export class SqlStoryRepository implements FacetRepository { const existing = await this.load(profileId); const headSql = sql - .insert("idz.story_state", { + .insert("idz_story_state", { id: profileId, x: story.x, y: story.y, @@ -83,7 +83,7 @@ export class SqlStoryRepository implements FacetRepository { } const cellSql = sql - .insert("idz.story_cell_state", { + .insert("idz_story_cell_state", { id: generateId(), profile_id: profileId, row_no: i, diff --git a/src/idz/db/team.ts b/src/idz/db/team.ts index 9671265..f08ab30 100644 --- a/src/idz/db/team.ts +++ b/src/idz/db/team.ts @@ -12,7 +12,7 @@ export class SqlTeamRepository implements TeamRepository { async find(extId: ExtId): Promise> { const findSql = sql .select("t.id") - .from("idz.team t") + .from("idz_team t") .where("t.ext_id", extId) .toParams(); @@ -29,7 +29,7 @@ export class SqlTeamRepository implements TeamRepository { async load(id: Id): Promise { const loadSql = sql .select("t.*") - .from("idz.team t") + .from("idz_team t") .where("t.id", id) .toParams(); @@ -51,7 +51,7 @@ export class SqlTeamRepository implements TeamRepository { async save(id: Id, team: Team): Promise { const saveSql = sql - .update("idz.team", { + .update("idz_team", { name_bg: team.nameBg, name_fx: team.nameFx, }) @@ -66,7 +66,7 @@ export class SqlTeamRepository implements TeamRepository { const extId = generateExtId() as ExtId; const createSql = sql - .insert("idz.team", { + .insert("idz_team", { id: id, ext_id: extId, name: team.name, @@ -83,7 +83,7 @@ export class SqlTeamRepository implements TeamRepository { async delete(id: Id): Promise { const deleteSql = sql - .delete("idz.team") + .delete("idz_team") .where("id", id) .toParams(); diff --git a/src/idz/db/teamAuto.ts b/src/idz/db/teamAuto.ts index 6f91d87..1ece405 100644 --- a/src/idz/db/teamAuto.ts +++ b/src/idz/db/teamAuto.ts @@ -11,7 +11,7 @@ export class SqlTeamAutoRepository implements TeamAutoRepository { async peek(): Promise<[TeamAuto, Id] | undefined> { const peekSql = sql .select("tt.*") - .from("idz.team_auto tt") + .from("idz_team_auto tt") .orderBy("serial_no desc", "name_idx desc") .limit(1) .toParams(); @@ -32,7 +32,7 @@ export class SqlTeamAutoRepository implements TeamAutoRepository { async push(teamId: Id, auto: TeamAuto): Promise { const pushSql = sql - .insert("idz.team_auto", { + .insert("idz_team_auto", { id: teamId, serial_no: auto.serialNo, name_idx: auto.nameIdx, diff --git a/src/idz/db/teamMember.ts b/src/idz/db/teamMember.ts index aaafe57..ea5b547 100644 --- a/src/idz/db/teamMember.ts +++ b/src/idz/db/teamMember.ts @@ -14,7 +14,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { async findTeam(profileId: Id): Promise | undefined> { const findSql = sql .select("tm.team_id") - .from("idz.team_member tm") + .from("idz_team_member tm") .where("tm.id", profileId) .toParams(); @@ -31,7 +31,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { async findLeader(teamId: Id): Promise | undefined> { const findSql = sql .select("tm.id") - .from("idz.team_member tm") + .from("idz_team_member tm") .where("tm.team_id", teamId) .where("tm.leader", true) .toParams(); @@ -49,10 +49,10 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { async loadRoster(teamId: Id): Promise { const loadSql = sql .select("tm.*", "p.*", "c.*", "r.ext_id as aime_id") - .from("idz.team_member tm") - .join("idz.profile p", { "tm.id": "p.id" }) - .join("idz.chara c", { "tm.id": "c.id" }) - .join("aime.player r", { "p.player_id": "r.id" }) + .from("idz_team_member tm") + .join("idz_profile p", { "tm.id": "p.id" }) + .join("idz_chara c", { "tm.id": "c.id" }) + .join("aime_player r", { "p.player_id": "r.id" }) .where("tm.team_id", teamId) .toParams(); @@ -75,7 +75,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { const lockSql = sql .select("id") - .from("idz.team") + .from("idz_team") .where("id", teamId) .forUpdate() .toParams(); @@ -93,7 +93,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { const countSql = sql .select("count(*) as count") - .from("idz.team_member") + .from("idz_team_member") .where("team_id", teamId) .toParams(); @@ -107,7 +107,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { // Do upsert const joinSql = sql - .insert("idz.team_member", { + .insert("idz_team_member", { id: profileId, team_id: teamId, leader: false, @@ -122,7 +122,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { async leave(teamId: Id, profileId: Id): Promise { const leaveSql = sql - .delete("idz.team_member") + .delete("idz_team_member") .where("team_id", teamId) .where("id", profileId) .toParams(); @@ -132,7 +132,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { async makeLeader(teamId: Id, profileId: Id): Promise { const clearSql = sql - .update("idz.team_member", { + .update("idz_team_member", { leader: false, }) .where("team_id", teamId) @@ -141,7 +141,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository { await this._conn.query(clearSql); const setSql = sql - .update("idz.team_member", { + .update("idz_team_member", { leader: true, }) .where("id", profileId) diff --git a/src/idz/db/teamReservation.ts b/src/idz/db/teamReservation.ts index a311af5..0a15858 100644 --- a/src/idz/db/teamReservation.ts +++ b/src/idz/db/teamReservation.ts @@ -13,7 +13,7 @@ export class SqlTeamReservationRepository private async _lockTeam(teamId: Id): Promise { const lockSql = sql .select("t.id") - .from("idz.team t") + .from("idz_team t") .where("t.id", teamId) .forUpdate() .toParams(); @@ -29,7 +29,7 @@ export class SqlTeamReservationRepository const memberSql = sql .select("count(*) as count") - .from("idz.team_member tm") + .from("idz_team_member tm") .where("tm.team_id", teamId) .toParams(); @@ -38,7 +38,7 @@ export class SqlTeamReservationRepository const reservSql = sql .select("count(*) as count") - .from("idz.team_reservation tr") + .from("idz_team_reservation tr") .where("tr.team_id", teamId) .toParams(); @@ -56,7 +56,7 @@ export class SqlTeamReservationRepository ): Promise { const lookupSql = sql .select("r.id") - .from("aime.player r") + .from("aime_player r") .where("r.ext_id", aimeId) .toParams(); @@ -70,7 +70,7 @@ export class SqlTeamReservationRepository const playerId = row.id; const insertSql = sql - .insert("idz.team_reservation", { + .insert("idz_team_reservation", { id: playerId, team_id: teamId, join_time: timestamp, @@ -86,9 +86,9 @@ export class SqlTeamReservationRepository async commitHack(aimeId: AimeId): Promise { const lookupSql = sql .select("p.id as profile_id", "tr.*") - .from("idz.profile p") - .join("aime.player r", { "p.player_id": "r.id" }) - .join("idz.team_reservation tr", { "r.id": "tr.id" }) + .from("idz_profile p") + .join("aime_player r", { "p.player_id": "r.id" }) + .join("idz_team_reservation tr", { "r.id": "tr.id" }) .where("r.ext_id", aimeId) .toParams(); @@ -100,7 +100,7 @@ export class SqlTeamReservationRepository } const insertSql = sql - .insert("idz.team_member", { + .insert("idz_team_member", { id: row.profile_id, team_id: row.team_id, join_time: row.join_time, @@ -111,7 +111,7 @@ export class SqlTeamReservationRepository await this._conn.query(insertSql); const cleanupSql = sql - .delete("idz.team_reservation") + .delete("idz_team_reservation") .where("id", row.id) .toParams(); diff --git a/src/idz/db/tickets.ts b/src/idz/db/tickets.ts index 4328cd7..e40beba 100644 --- a/src/idz/db/tickets.ts +++ b/src/idz/db/tickets.ts @@ -14,7 +14,7 @@ export class SqlTicketsRepository implements FacetRepository { async load(profileId: Id): Promise { const loadSql = sql .select("fc.*") - .from("idz.free_car fc") + .from("idz_free_car fc") .where("fc.id", profileId) .toParams(); @@ -33,14 +33,14 @@ export class SqlTicketsRepository implements FacetRepository { if (!freeCar) { const delSql = sql - .delete("idz.free_car") + .delete("idz_free_car") .where("id", profileId) .toParams(); await this._conn.query(delSql); } else { const saveSql = sql - .insert("idz.free_car", { + .insert("idz_free_car", { id: profileId, valid_from: freeCar.validFrom, }) diff --git a/src/idz/db/timeAttack.ts b/src/idz/db/timeAttack.ts index 9466432..f2d0c9b 100644 --- a/src/idz/db/timeAttack.ts +++ b/src/idz/db/timeAttack.ts @@ -16,8 +16,8 @@ export class SqlTimeAttackRepository implements TimeAttackRepository { ): Promise { const loadSql = sql .select("p.name", "ta.*") - .from("idz.ta_best ta") - .join("idz.profile p", { "ta.profile_id": "p.id" }) + .from("idz_ta_best ta") + .join("idz_profile p", { "ta.profile_id": "p.id" }) .where("ta.route_no", routeNo) .where(sql.gt("ta.timestamp", minTimestamp)) .orderBy(["ta.total_time asc", "ta.timestamp asc"]) @@ -43,7 +43,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository { async loadAll(profileId: Id): Promise { const loadSql = sql .select("ta.*") - .from("idz.ta_best ta") + .from("idz_ta_best ta") .where("ta.profile_id", profileId) .toParams(); @@ -62,7 +62,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository { async save(profileId: Id, score: TimeAttackScore): Promise { const logSql = sql - .insert("idz.ta_result", { + .insert("idz_ta_result", { id: generateId(), profile_id: profileId, route_no: score.routeNo, @@ -79,7 +79,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository { const existSql = sql .select("ta.total_time") - .from("idz.ta_best ta") + .from("idz_ta_best ta") .where("ta.profile_id", profileId) .where("ta.route_no", score.routeNo) .toParams(); @@ -89,7 +89,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository { if (row === undefined) { const insertSql = sql - .insert("idz.ta_best", { + .insert("idz_ta_best", { id: generateId(), profile_id: profileId, route_no: score.routeNo, @@ -105,7 +105,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository { await this._conn.query(insertSql); } else if (score.totalTime < row.total_time) { const updateSql = sql - .update("idz.ta_best", { + .update("idz_ta_best", { total_time: score.totalTime, section_times: score.sectionTimes, flags: score.flags, diff --git a/src/idz/db/titles.ts b/src/idz/db/titles.ts index a72b13b..173f9c3 100644 --- a/src/idz/db/titles.ts +++ b/src/idz/db/titles.ts @@ -12,7 +12,7 @@ export class SqlTitlesRepository implements FlagRepository { async loadAll(profileId: Id): Promise> { const loadSql = sql .select("t.title_no") - .from("idz.title_unlock t") + .from("idz_title_unlock t") .where("t.profile_id", profileId) .toParams(); @@ -35,7 +35,7 @@ export class SqlTitlesRepository implements FlagRepository { } const saveSql = sql - .insert("idz.title_unlock", { + .insert("idz_title_unlock", { id: generateId(), profile_id: profileId, title_no: flag, diff --git a/src/idz/db/unlocks.ts b/src/idz/db/unlocks.ts index 523ad25..a614bad 100644 --- a/src/idz/db/unlocks.ts +++ b/src/idz/db/unlocks.ts @@ -13,7 +13,7 @@ export class SqlUnlocksRepository implements FacetRepository { async load(profileId: Id): Promise { const loadSql = sql .select("u.*") - .from("idz.unlocks u") + .from("idz_unlocks u") .where("u.id", profileId) .toParams(); @@ -30,7 +30,7 @@ export class SqlUnlocksRepository implements FacetRepository { async save(profileId: Id, unlocks: Unlocks): Promise { const saveSql = sql - .insert("idz.unlocks", { + .insert("idz_unlocks", { id: profileId, cup: unlocks.cup, gauges: unlocks.gauges,