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.
This commit is contained in:
Tau
2019-11-06 17:28:30 -05:00
parent 6be23145d8
commit 6ab2112ea9
22 changed files with 236 additions and 156 deletions
+13 -15
View File
@@ -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")
);
+63 -62
View File
@@ -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
+1 -1
View File
@@ -1,2 +1,2 @@
create table "meta" ("schemaver" integer not null);
insert into "meta" values (3);
insert into "meta" values (5);
+81
View File
@@ -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;
+5 -5
View File
@@ -11,8 +11,8 @@ class CardRepositoryImpl implements CardRepository {
async lookup(luid: string, now: Date): Promise<AimeId | undefined> {
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,
+1 -1
View File
@@ -5,7 +5,7 @@ import { Pool, PoolClient } from "pg";
export type Id<T> = bigint & { __id: T };
const debug = logger("app:sql");
const currentSchemaVer = 3;
const currentSchemaVer = 5;
const pool = new Pool();
const fence = testConnection();
+3 -3
View File
@@ -13,8 +13,8 @@ export class SqlBackgroundsRepository
async loadAll(id: Id<Profile>): Promise<Set<BackgroundCode>> {
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,
+7 -7
View File
@@ -32,7 +32,7 @@ export class SqlCarRepository implements CarRepository {
async countCars(profileId: Id<Profile>): Promise<number> {
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<Profile>): Promise<Car[]> {
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<Profile>): Promise<Car> {
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<Profile>, car: Car): Promise<void> {
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<void> {
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,
})
+2 -2
View File
@@ -27,7 +27,7 @@ export class SqlCharaRepository implements FacetRepository<Chara> {
async load(profileId: Id<Profile>): Promise<Chara> {
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<Chara> {
async save(profileId: Id<Profile>, chara: Chara): Promise<void> {
const saveSql = sql
.insert("idz.chara", {
.insert("idz_chara", {
id: profileId,
gender: chara.gender,
field_02: chara.field_02,
+2 -2
View File
@@ -12,7 +12,7 @@ export class SqlCoursePlaysRepository implements CoursePlaysRepository {
async loadAll(profileId: Id<Profile>): Promise<Map<CourseNo, number>> {
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<void> {
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,
+2 -2
View File
@@ -30,7 +30,7 @@ export class SqlMissionsRepository implements FacetRepository<MissionState> {
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<MissionState> {
}
const saveSql = sql
.insert("idz.solo_mission_state", {
.insert("idz_solo_mission_state", {
id: generateId(),
profile_id: profileId,
grid_no: i,
+7 -7
View File
@@ -36,8 +36,8 @@ export class SqlProfileRepository implements ProfileRepository {
async peek(aimeId: AimeId): Promise<Id<Profile> | 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<Profile>): Promise<Profile> {
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: Profile): Promise<void> {
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<Id<Profile>> {
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,
+2 -2
View File
@@ -12,7 +12,7 @@ export class SqlSettingsRepository implements FacetRepository<Settings> {
async load(profileId: Id<Profile>): Promise<Settings> {
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<Settings> {
async save(profileId: Id<Profile>, settings: Settings): Promise<void> {
const saveSql = sql
.insert("idz.settings", {
.insert("idz_settings", {
id: profileId,
music: settings.music,
pack: settings.pack,
+4 -4
View File
@@ -12,7 +12,7 @@ export class SqlStoryRepository implements FacetRepository<Story> {
async load(profileId: Id<Profile>): Promise<Story> {
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<Story> {
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<Story> {
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<Story> {
}
const cellSql = sql
.insert("idz.story_cell_state", {
.insert("idz_story_cell_state", {
id: generateId(),
profile_id: profileId,
row_no: i,
+5 -5
View File
@@ -12,7 +12,7 @@ export class SqlTeamRepository implements TeamRepository {
async find(extId: ExtId<Team>): Promise<Id<Team>> {
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<Team>): Promise<Team> {
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: Team): Promise<void> {
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<Team>;
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<Team>): Promise<void> {
const deleteSql = sql
.delete("idz.team")
.delete("idz_team")
.where("id", id)
.toParams();
+2 -2
View File
@@ -11,7 +11,7 @@ export class SqlTeamAutoRepository implements TeamAutoRepository {
async peek(): Promise<[TeamAuto, Id<Team>] | 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<Team>, auto: TeamAuto): Promise<void> {
const pushSql = sql
.insert("idz.team_auto", {
.insert("idz_team_auto", {
id: teamId,
serial_no: auto.serialNo,
name_idx: auto.nameIdx,
+12 -12
View File
@@ -14,7 +14,7 @@ export class SqlTeamMemberRepository implements TeamMemberRepository {
async findTeam(profileId: Id<Profile>): Promise<Id<Team> | 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<Team>): Promise<Id<Profile> | 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<Team>): Promise<TeamMember[]> {
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<Team>, profileId: Id<Profile>): Promise<void> {
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<Team>, profileId: Id<Profile>): Promise<void> {
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)
+10 -10
View File
@@ -13,7 +13,7 @@ export class SqlTeamReservationRepository
private async _lockTeam(teamId: Id<Team>): Promise<void> {
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<void> {
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<void> {
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();
+3 -3
View File
@@ -14,7 +14,7 @@ export class SqlTicketsRepository implements FacetRepository<Tickets> {
async load(profileId: Id<Profile>): Promise<Tickets> {
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<Tickets> {
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,
})
+7 -7
View File
@@ -16,8 +16,8 @@ export class SqlTimeAttackRepository implements TimeAttackRepository {
): Promise<TopTenResult[]> {
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<Profile>): Promise<TimeAttackScore[]> {
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<Profile>, score: TimeAttackScore): Promise<void> {
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,
+2 -2
View File
@@ -12,7 +12,7 @@ export class SqlTitlesRepository implements FlagRepository<TitleCode> {
async loadAll(profileId: Id<Profile>): Promise<Set<TitleCode>> {
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<TitleCode> {
}
const saveSql = sql
.insert("idz.title_unlock", {
.insert("idz_title_unlock", {
id: generateId(),
profile_id: profileId,
title_no: flag,
+2 -2
View File
@@ -13,7 +13,7 @@ export class SqlUnlocksRepository implements FacetRepository<Unlocks> {
async load(profileId: Id<Profile>): Promise<Unlocks> {
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<Unlocks> {
async save(profileId: Id<Profile>, unlocks: Unlocks): Promise<void> {
const saveSql = sql
.insert("idz.unlocks", {
.insert("idz_unlocks", {
id: profileId,
cup: unlocks.cup,
gauges: unlocks.gauges,