-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
54 lines (47 loc) · 2.05 KB
/
schema.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
-- Profile
DROP TABLE IF EXISTS profiles;
CREATE TABLE profiles (
id INTEGER PRIMARY KEY AUTOINCREMENT,
uuid TEXT NOT NULL,
nonce INTEGER NOT NULL DEFAULT 0,
name TEXT,
nftChainId TEXT,
nftCollectionAddress TEXT,
nftTokenId TEXT,
createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
-- unique uuid among all profiles
CONSTRAINT unique_uuid UNIQUE (uuid),
-- unique name among all profiles
CONSTRAINT unique_name UNIQUE (name)
);
-- ProfilePublicKey
DROP TABLE IF EXISTS profile_public_keys;
CREATE TABLE profile_public_keys (
id INTEGER PRIMARY KEY AUTOINCREMENT,
profileId INTEGER NOT NULL,
type TEXT NOT NULL,
publicKeyHex TEXT NOT NULL,
addressHex TEXT NOT NULL,
createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_profiles FOREIGN KEY (profileId) REFERENCES profiles (id) ON DELETE CASCADE,
-- unique public key, only one profile can claim a given public key
CONSTRAINT unique_type_public_key_hex UNIQUE (type, publicKeyHex)
);
CREATE INDEX IF NOT EXISTS idx_profile_public_keys_public_key_hex ON profile_public_keys(publicKeyHex);
-- ProfilePublicKeyChainPreference
DROP TABLE IF EXISTS profile_public_key_chain_preferences;
CREATE TABLE profile_public_key_chain_preferences (
id INTEGER PRIMARY KEY AUTOINCREMENT,
profileId INTEGER NOT NULL,
profilePublicKeyId INTEGER NOT NULL,
chainId TEXT NOT NULL,
createdAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updatedAt DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_profiles FOREIGN KEY (profileId) REFERENCES profiles (id) ON DELETE CASCADE,
CONSTRAINT fk_profile_public_keys FOREIGN KEY (profilePublicKeyId) REFERENCES profile_public_keys (id) ON DELETE CASCADE,
-- only one preference for a given chain per profile
CONSTRAINT unique_profile_chain_preference UNIQUE (profileId, chainId)
);
CREATE INDEX IF NOT EXISTS idx_profile_public_key_chain_preferences_profile_chain ON profile_public_key_chain_preferences(profileId, chainId);