Skip to content

Commit 8ee74ad

Browse files
committed
feat(api): Add twitch_accounts and mc_accounts tables
Moves twitch and mc account info into their own tables
1 parent 6c1740e commit 8ee74ad

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

‎api/cmd/migrations/20210613042045_init.down.sql‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ DROP TABLE IF EXISTS users CASCADE;
22

33
--gopg:split
44

5-
DROP TABLE IF EXISTS twitch_tokens CASCADE;
5+
DROP TABLE IF EXISTS twitch_accounts CASCADE;
6+
7+
--gopg:split
8+
9+
DROP TABLE IF EXISTS mc_accounts CASCADE;
610

711
--gopg:split
812

‎api/cmd/migrations/20210613042045_init.up.sql‎

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,35 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
44

55
CREATE TABLE IF NOT EXISTS users (
66
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
7-
email varchar(255) NOT NULL,
8-
email_verified boolean NOT NULL,
9-
twitch_id varchar(255) NOT NULL,
10-
twitch_username varchar(25) NOT NULL,
11-
twitch_picture text,
12-
mc_username varchar(16),
13-
mc_uuid uuid,
147
last_login_at timestamptz NOT NULL DEFAULT now(),
158
created_at timestamptz NOT NULL DEFAULT now(),
169
updated_at timestamptz NOT NULL DEFAULT now(),
1710
deleted_at timestamptz
1811
);
1912

20-
CREATE UNIQUE INDEX IF NOT EXISTS twitch_id_idx ON users (twitch_id);
21-
2213
--gopg:split
2314

24-
CREATE TABLE IF NOT EXISTS twitch_tokens (
25-
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
26-
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
15+
CREATE TABLE IF NOT EXISTS twitch_accounts (
16+
id text PRIMARY KEY,
17+
email text NOT NULL,
18+
email_verified boolean NOT NULL,
19+
username varchar(25) NOT NULL,
20+
picture text,
2721
access_token varchar(255) NOT NULL,
2822
refresh_token varchar(255) NOT NULL,
23+
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
24+
created_at timestamptz NOT NULL DEFAULT now(),
25+
updated_at timestamptz NOT NULL DEFAULT now(),
26+
deleted_at timestamptz
27+
);
28+
29+
--gopg:split
30+
31+
CREATE TABLE IF NOT EXISTS mc_accounts (
32+
id uuid PRIMARY KEY,
33+
username varchar(16) NOT NULL,
34+
skin text,
35+
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
2936
created_at timestamptz NOT NULL DEFAULT now(),
3037
updated_at timestamptz NOT NULL DEFAULT now(),
3138
deleted_at timestamptz
@@ -36,9 +43,9 @@ CREATE TABLE IF NOT EXISTS twitch_tokens (
3643
CREATE TABLE IF NOT EXISTS games (
3744
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
3845
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
39-
name varchar(255) NOT NULL,
40-
motd varchar(255) NOT NULL,
41-
slots int DEFAULT 10,
46+
name varchar(60) NOT NULL,
47+
motd varchar(59),
48+
slots int DEFAULT 10 NOT NULL,
4249
address varchar(63) NOT NULL,
4350
edition varchar(25) NOT NULL,
4451
state varchar(25) NOT NULL,

0 commit comments

Comments
 (0)