Skip to content

Instantly share code, notes, and snippets.

@vovibssnff
Created February 4, 2025 10:57
Show Gist options
  • Save vovibssnff/25043d0647f81f911a9f55794e831fb7 to your computer and use it in GitHub Desktop.
Save vovibssnff/25043d0647f81f911a9f55794e831fb7 to your computer and use it in GitHub Desktop.
diff --git a/schema/01-create_tables.sql b/schema/01-create_tables.sql
index d899125..4cd8f09 100644
--- a/schema/01-create_tables.sql
+++ b/schema/01-create_tables.sql
@@ -1,7 +1,7 @@
CREATE TABLE Account (
id serial PRIMARY KEY,
- name TEXT UNIQUE NOT NULL,
- passwordHash TEXT NOT NULL,
+ name VARCHAR(12) NOT NULL,
+ telegramId TEXT,
friendCode VARCHAR(11) NOT NULL /* 123,456,789 */
);
@@ -23,7 +23,6 @@ CREATE TYPE ServantClass AS ENUM (
CREATE TABLE Servant ( -- api
id int PRIMARY KEY,
- collectionNo int NOT NULL,
name text NOT NULL,
iconUrl text NOT NULL,
rarity smallint CHECK (rarity BETWEEN 0 AND 5),
@@ -41,9 +40,7 @@ CREATE TABLE ServantEnhancement ( -- user
skill1Lv smallint DEFAULT NULL CHECK (skill1Lv BETWEEN 1 AND 10),
skill2Lv smallint DEFAULT NULL CHECK (skill2Lv BETWEEN 1 AND 10),
- skill3Lv smallint DEFAULT NULL CHECK (skill3Lv BETWEEN 1 AND 10),
-
- npLv smallint DEFAULT NULL CHECK (npLv BETWEEN 1 AND 5)
+ skill3Lv smallint DEFAULT NULL CHECK (skill3Lv BETWEEN 1 AND 10)
);
CREATE TABLE SkillMaterials ( -- api
@@ -51,21 +48,24 @@ CREATE TABLE SkillMaterials ( -- api
forLv smallint CHECK(forLv BETWEEN 2 AND 10),
mid int REFERENCES Material(id) NOT NULL,
- amount int CHECK (amount > 0)
+ amount int CHECK (amount > 0),
+
+ UNIQUE(sid, forLv, mid)
);
CREATE TABLE AscensionMaterials ( -- api
sid int REFERENCES Servant(id) NOT NULL,
- forAscLv smallint CHECK(forAscLv BETWEEN 2 AND 4),
+ forAscLv smallint CHECK(forAscLv BETWEEN 1 AND 4),
mid int REFERENCES Material(id) NOT NULL,
- amount int CHECK (amount > 0)
+ amount int CHECK (amount > 0),
+
+ UNIQUE(sid, forAscLv, mid)
);
CREATE TABLE CraftEssence ( -- api
id int PRIMARY KEY,
name TEXT NOT NULL,
- detail TEXT,
iconUrl TEXT NOT NULL
);
@@ -89,7 +89,9 @@ CREATE TABLE ServantEventBonus ( -- api
sid int REFERENCES Servant(id) NOT NULL,
typ EventBonusType NOT NULL,
- mid int REFERENCES Material(id)
+ mid int REFERENCES Material(id),
+
+ UNIQUE NULLS NOT DISTINCT (eid, sid, typ, mid)
);
CREATE TABLE CraftEssenceEventBonus ( -- api
@@ -97,7 +99,9 @@ CREATE TABLE CraftEssenceEventBonus ( -- api
ceid int REFERENCES CraftEssence(id) NOT NULL,
typ EventBonusType NOT NULL,
- mid int REFERENCES Material(id)
+ mid int REFERENCES Material(id),
+
+ UNIQUE NULLS NOT DISTINCT (eid, ceid, typ, mid)
);
CREATE TYPE ActivityType as ENUM (
@@ -142,7 +146,7 @@ CREATE TYPE SupportSlot as ENUM (
CREATE TABLE SupportPartyServant ( -- user
spid int REFERENCES SupportParty(id) ON DELETE CASCADE NOT NULL,
-
+
sid int REFERENCES Servant(id) NOT NULL,
ceid int REFERENCES CraftEssence(id),
mlb boolean DEFAULT false,
@@ -151,3 +155,7 @@ CREATE TABLE SupportPartyServant ( -- user
PRIMARY KEY (spid, slot),
UNIQUE (spid, sid)
);
+
+CREATE INDEX idx_servant_enhancement_latest
+ ON ServantEnhancement(aid, sid, at DESC);
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment