Skip to content

Commit 69933f8

Browse files
authored
feat: add num id (#247)
1 parent c08fdb7 commit 69933f8

File tree

13 files changed

+216
-14
lines changed

13 files changed

+216
-14
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050

5151
- uses: sqlc-dev/setup-sqlc@v4
5252
with:
53-
sqlc-version: '1.29.0'
53+
sqlc-version: '1.30.0'
5454

5555
- run: env
5656

dal/db.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dal/models.go

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dal/query.sql.go

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
create table patch_users
2+
(
3+
user_id integer not null
4+
primary key,
5+
username varchar(255) not null,
6+
nickname varchar(255) not null
7+
);
8+
9+
10+
create table subject_patch
11+
(
12+
id uuid not null
13+
primary key,
14+
subject_id integer not null,
15+
state integer default 0 not null,
16+
from_user_id integer not null,
17+
wiki_user_id integer default 0 not null,
18+
reason text not null,
19+
name text,
20+
original_name text default ''::text not null,
21+
infobox text,
22+
original_infobox text,
23+
summary text,
24+
original_summary text,
25+
nsfw boolean,
26+
created_at timestamp with time zone default CURRENT_TIMESTAMP not null,
27+
updated_at timestamp with time zone default CURRENT_TIMESTAMP not null,
28+
deleted_at timestamp with time zone,
29+
reject_reason text default ''::character varying not null,
30+
subject_type bigint default 0 not null,
31+
comments_count integer default 0 not null,
32+
patch_desc text default ''::text not null,
33+
original_platform integer,
34+
platform integer,
35+
action integer default 1
36+
);
37+
38+
comment on column subject_patch.action is '1 for update 2 for create';
39+
40+
create index idx_subject_id
41+
on subject_patch (subject_id);
42+
43+
create index idx_subject_patch_list
44+
on subject_patch (created_at, state, deleted_at);
45+
46+
create index idx_subject_patch_list2
47+
on subject_patch (updated_at, state, deleted_at);
48+
49+
create index idx_subject_patch_list3
50+
on subject_patch (deleted_at, state, created_at);
51+
52+
create index idx_subject_count
53+
on subject_patch (state, deleted_at);
54+
55+
create index idx_subject_subject_id
56+
on subject_patch (subject_id, state);
57+
58+
create table episode_patch
59+
(
60+
id uuid not null
61+
primary key,
62+
episode_id integer not null,
63+
state integer default 0 not null,
64+
from_user_id integer not null,
65+
wiki_user_id integer default 0 not null,
66+
reason text not null,
67+
original_name text,
68+
name text,
69+
original_name_cn text,
70+
name_cn text,
71+
original_duration varchar(255),
72+
duration varchar(255),
73+
original_airdate varchar(64),
74+
airdate varchar(64),
75+
original_description text,
76+
description text,
77+
created_at timestamp with time zone default CURRENT_TIMESTAMP not null,
78+
updated_at timestamp with time zone default CURRENT_TIMESTAMP not null,
79+
deleted_at timestamp with time zone,
80+
reject_reason text default ''::character varying not null,
81+
subject_id integer default 0 not null,
82+
comments_count integer default 0 not null,
83+
patch_desc text default ''::text not null,
84+
ep integer
85+
);
86+
87+
create index episode_patch_state_idx
88+
on episode_patch (state);
89+
90+
create index idx_episode_patch_list
91+
on episode_patch (created_at, state, deleted_at);
92+
93+
create index idx_episode_patch_list2
94+
on episode_patch (updated_at, state, deleted_at);
95+
96+
create index idx_episode_patch_list3
97+
on episode_patch (deleted_at, state, created_at);
98+
99+
create index idx_episode_count
100+
on episode_patch (state, deleted_at);
101+
102+
create index idx_episode_subject_id
103+
on episode_patch (subject_id, state);
104+
105+
create index idx_episode_episode_id
106+
on episode_patch (episode_id, state);
107+
108+
create table edit_suggestion
109+
(
110+
id uuid not null
111+
primary key,
112+
patch_id uuid not null,
113+
patch_type varchar(64) not null,
114+
text text not null,
115+
from_user integer not null,
116+
created_at timestamp with time zone default CURRENT_TIMESTAMP not null,
117+
deleted_at timestamp with time zone
118+
);
119+
120+
create index idx_edit_patch_lookup
121+
on edit_suggestion (created_at, patch_id, patch_type);

db/migrations/000004_num-id.down.sql

Whitespace-only changes.

db/migrations/000004_num-id.up.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
alter table subject_patch
2+
add column if not exists num_id bigserial not null;
3+
alter table episode_patch
4+
add column if not exists num_id bigserial not null;
5+
6+
create index idx_subject_patch_num_id on subject_patch (num_id);
7+
create index idx_episode_patch_num_id on episode_patch (num_id);

db/schema.sql

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ create table patch_users
66
nickname varchar(255) not null
77
);
88

9-
109
create table subject_patch
1110
(
1211
id uuid not null
@@ -32,7 +31,8 @@ create table subject_patch
3231
patch_desc text default ''::text not null,
3332
original_platform integer,
3433
platform integer,
35-
action integer default 1
34+
action integer default 1,
35+
num_id bigserial not null
3636
);
3737

3838
comment on column subject_patch.action is '1 for update 2 for create';
@@ -55,6 +55,9 @@ create index idx_subject_count
5555
create index idx_subject_subject_id
5656
on subject_patch (subject_id, state);
5757

58+
create index idx_subject_patch_num_id
59+
on subject_patch (num_id);
60+
5861
create table episode_patch
5962
(
6063
id uuid not null
@@ -81,7 +84,8 @@ create table episode_patch
8184
subject_id integer default 0 not null,
8285
comments_count integer default 0 not null,
8386
patch_desc text default ''::text not null,
84-
ep integer
87+
ep integer,
88+
num_id bigserial not null
8589
);
8690

8791
create index episode_patch_state_idx
@@ -105,17 +109,21 @@ create index idx_episode_subject_id
105109
create index idx_episode_episode_id
106110
on episode_patch (episode_id, state);
107111

112+
create index idx_episode_patch_num_id
113+
on episode_patch (num_id);
114+
108115
create table edit_suggestion
109116
(
110117
id uuid not null
111118
primary key,
112119
patch_id uuid not null,
113-
patch_type varchar(64) not null,
120+
patch_type varchar(64) not null,
114121
text text not null,
115122
from_user integer not null,
116123
created_at timestamp with time zone default CURRENT_TIMESTAMP not null,
117124
deleted_at timestamp with time zone
118125
);
119126

127+
120128
create index idx_edit_patch_lookup
121129
on edit_suggestion (created_at, patch_id, patch_type);

episode-review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (h *handler) handleEpisodeApprove(
105105
s *session.Session,
106106
) error {
107107
var body = ApiUpdateEpisode{
108-
CommieMessage: fmt.Sprintf("%s [https://patch.bgm38.tv/episode/%s]", patch.Reason, patch.ID),
108+
CommieMessage: fmt.Sprintf("%s [https://patch.bgm38.tv/e/%d]", patch.Reason, patch.NumID),
109109
ExpectedRevision: ApiExpectedSubject{
110110
Name: valuePtrIfChanged(patch.OriginalName.String, patch.Name.String),
111111
NameCN: valuePtrIfChanged(patch.OriginalNameCn.String, patch.NameCn.String),

episode.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,34 @@ func (h *handler) listEpisodePatches(
255255
}).Render(r.Context(), w)
256256
}
257257

258+
func (h *handler) episodePatchShortLink(
259+
w http.ResponseWriter,
260+
r *http.Request,
261+
) error {
262+
patchID := chi.URLParam(r, "patchID")
263+
if patchID == "" {
264+
http.Error(w, "missing patch id", http.StatusBadRequest)
265+
return nil
266+
}
267+
268+
numID, err := strconv.ParseUint(patchID, 10, 64)
269+
if err != nil {
270+
http.NotFound(w, r)
271+
return nil
272+
}
273+
274+
var id uuid.UUID
275+
row := h.db.QueryRow(r.Context(), `select id from episode_patch where num_id = $1 limit 1`, numID)
276+
err = row.Scan(&id)
277+
if err != nil {
278+
return errgo.Wrap(err, "failed to query subject_path")
279+
}
280+
281+
http.Redirect(w, r, fmt.Sprintf("/episode/%s", id), http.StatusSeeOther)
282+
283+
return nil
284+
}
285+
258286
func (h *handler) episodePatchDetailView(
259287
w http.ResponseWriter,
260288
r *http.Request,

0 commit comments

Comments
 (0)