From 4c099e769917f5719f5e054b1f0d3688d918d03d Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 14 Sep 2022 07:43:54 +0800 Subject: [PATCH] chore: add `shortcut.description` field --- api/shortcut.go | 28 ++++++++++-------- store/db/migration/dev/LATEST__SCHEMA.sql | 1 + store/db/migration/prod/LATEST__SCHEMA.sql | 10 ++++++- store/db/seed/10004__shortcut.sql | 2 ++ store/shortcut.go | 33 +++++++++++++++------- 5 files changed, 51 insertions(+), 23 deletions(-) diff --git a/api/shortcut.go b/api/shortcut.go index cdc648c..373db21 100644 --- a/api/shortcut.go +++ b/api/shortcut.go @@ -31,9 +31,10 @@ type Shortcut struct { RowStatus RowStatus `json:"rowStatus"` // Domain specific fields - Name string `json:"name"` - Link string `json:"link"` - Visibility Visibility `json:"visibility"` + Name string `json:"name"` + Link string `json:"link"` + Description string `json:"description"` + Visibility Visibility `json:"visibility"` } type ShortcutCreate struct { @@ -42,9 +43,10 @@ type ShortcutCreate struct { WorkspaceID int `json:"workspaceId"` // Domain specific fields - Name string `json:"name"` - Link string `json:"link"` - Visibility Visibility `json:"visibility"` + Name string `json:"name"` + Link string `json:"link"` + Description string `json:"description"` + Visibility Visibility `json:"visibility"` } type ShortcutPatch struct { @@ -54,9 +56,10 @@ type ShortcutPatch struct { RowStatus *RowStatus `json:"rowStatus"` // Domain specific fields - Name *string `json:"name"` - Link *string `json:"link"` - Visibility *Visibility `json:"visibility"` + Name *string `json:"name"` + Link *string `json:"link"` + Description *string `json:"description"` + Visibility *Visibility `json:"visibility"` } type ShortcutFind struct { @@ -67,9 +70,10 @@ type ShortcutFind struct { WorkspaceID *int `json:"workspaceId"` // Domain specific fields - Name *string `json:"name"` - Link *string `json:"link"` - Visibility *Visibility `json:"visibility"` + Name *string `json:"name"` + Link *string `json:"link"` + Description *string `json:"description"` + Visibility *Visibility `json:"visibility"` } type ShortcutDelete struct { diff --git a/store/db/migration/dev/LATEST__SCHEMA.sql b/store/db/migration/dev/LATEST__SCHEMA.sql index 0bc0d87..3c2b2f1 100644 --- a/store/db/migration/dev/LATEST__SCHEMA.sql +++ b/store/db/migration/dev/LATEST__SCHEMA.sql @@ -115,6 +115,7 @@ CREATE TABLE shortcut ( workspace_id INTEGER NOT NULL, name TEXT NOT NULL, link TEXT NOT NULL DEFAULT '', + description TEXT NOT NULL DEFAULT '', visibility TEXT NOT NULL CHECK (visibility IN ('PRIVATE', 'WORKSPACE')) DEFAULT 'PRIVATE', FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE, FOREIGN KEY(workspace_id) REFERENCES workspace(id) ON DELETE CASCADE diff --git a/store/db/migration/prod/LATEST__SCHEMA.sql b/store/db/migration/prod/LATEST__SCHEMA.sql index 6915dc9..3c2b2f1 100644 --- a/store/db/migration/prod/LATEST__SCHEMA.sql +++ b/store/db/migration/prod/LATEST__SCHEMA.sql @@ -55,7 +55,8 @@ CREATE TABLE user ( row_status TEXT NOT NULL CHECK (row_status IN ('NORMAL', 'ARCHIVED')) DEFAULT 'NORMAL', email TEXT NOT NULL UNIQUE, name TEXT NOT NULL, - password_hash TEXT NOT NULL + password_hash TEXT NOT NULL, + open_id TEXT NOT NULL UNIQUE ); INSERT INTO @@ -75,6 +76,12 @@ WHERE rowid = old.rowid; END; +CREATE INDEX user_id_index ON user(id); + +CREATE UNIQUE INDEX user_email_index ON user(email); + +CREATE UNIQUE INDEX user_open_id_index ON user(open_id); + -- user_setting CREATE TABLE user_setting ( user_id INTEGER NOT NULL, @@ -108,6 +115,7 @@ CREATE TABLE shortcut ( workspace_id INTEGER NOT NULL, name TEXT NOT NULL, link TEXT NOT NULL DEFAULT '', + description TEXT NOT NULL DEFAULT '', visibility TEXT NOT NULL CHECK (visibility IN ('PRIVATE', 'WORKSPACE')) DEFAULT 'PRIVATE', FOREIGN KEY(creator_id) REFERENCES user(id) ON DELETE CASCADE, FOREIGN KEY(workspace_id) REFERENCES workspace(id) ON DELETE CASCADE diff --git a/store/db/seed/10004__shortcut.sql b/store/db/seed/10004__shortcut.sql index 7a16449..dfa0457 100644 --- a/store/db/seed/10004__shortcut.sql +++ b/store/db/seed/10004__shortcut.sql @@ -4,6 +4,7 @@ INSERT INTO `workspace_id`, `name`, `link`, + `description`, `visibility` ) VALUES @@ -12,5 +13,6 @@ VALUES 11, 'baidu', 'https://baidu.com', + '百度搜索', 'WORKSPACE' ); diff --git a/store/shortcut.go b/store/shortcut.go index 9fb8ddd..8356cd4 100644 --- a/store/shortcut.go +++ b/store/shortcut.go @@ -23,9 +23,10 @@ type shortcutRaw struct { RowStatus api.RowStatus // Domain specific fields - Name string - Link string - Visibility api.Visibility + Name string + Link string + Description string + Visibility api.Visibility } func (raw *shortcutRaw) toShortcut() *api.Shortcut { @@ -38,9 +39,10 @@ func (raw *shortcutRaw) toShortcut() *api.Shortcut { WorkspaceID: raw.WorkspaceID, RowStatus: raw.RowStatus, - Name: raw.Name, - Link: raw.Link, - Visibility: raw.Visibility, + Name: raw.Name, + Link: raw.Link, + Description: raw.Description, + Visibility: raw.Visibility, } } @@ -178,13 +180,14 @@ func createShortcut(ctx context.Context, tx *sql.Tx, create *api.ShortcutCreate) workspace_id, name, link, + description, visibility ) - VALUES (?, ?, ?, ?, ?) - RETURNING id, creator_id, created_ts, updated_ts, workspace_id, row_status, name, link, visibility + VALUES (?, ?, ?, ?, ?, ?) + RETURNING id, creator_id, created_ts, updated_ts, workspace_id, row_status, name, link, description, visibility ` var shortcutRaw shortcutRaw - if err := tx.QueryRowContext(ctx, query, create.CreatorID, create.WorkspaceID, create.Name, create.Link, create.Visibility).Scan( + if err := tx.QueryRowContext(ctx, query, create.CreatorID, create.WorkspaceID, create.Name, create.Link, create.Description, create.Visibility).Scan( &shortcutRaw.ID, &shortcutRaw.CreatorID, &shortcutRaw.CreatedTs, @@ -193,6 +196,7 @@ func createShortcut(ctx context.Context, tx *sql.Tx, create *api.ShortcutCreate) &shortcutRaw.RowStatus, &shortcutRaw.Name, &shortcutRaw.Link, + &shortcutRaw.Description, &shortcutRaw.Visibility, ); err != nil { return nil, FormatError(err) @@ -210,6 +214,9 @@ func patchShortcut(ctx context.Context, tx *sql.Tx, patch *api.ShortcutPatch) (* if v := patch.Link; v != nil { set, args = append(set, "link = ?"), append(args, *v) } + if v := patch.Description; v != nil { + set, args = append(set, "description = ?"), append(args, *v) + } if v := patch.Visibility; v != nil { set, args = append(set, "visibility = ?"), append(args, *v) } @@ -220,7 +227,7 @@ func patchShortcut(ctx context.Context, tx *sql.Tx, patch *api.ShortcutPatch) (* UPDATE shortcut SET ` + strings.Join(set, ", ") + ` WHERE id = ? - RETURNING id, creator_id, created_ts, updated_ts, workspace_id, row_status, name, link, visibility + RETURNING id, creator_id, created_ts, updated_ts, workspace_id, row_status, name, link, description, visibility ` var shortcutRaw shortcutRaw if err := tx.QueryRowContext(ctx, query, args...).Scan( @@ -232,6 +239,7 @@ func patchShortcut(ctx context.Context, tx *sql.Tx, patch *api.ShortcutPatch) (* &shortcutRaw.RowStatus, &shortcutRaw.Name, &shortcutRaw.Link, + &shortcutRaw.Description, &shortcutRaw.Visibility, ); err != nil { return nil, FormatError(err) @@ -258,6 +266,9 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) ( if v := find.Link; v != nil { where, args = append(where, "link = ?"), append(args, *v) } + if v := find.Description; v != nil { + where, args = append(where, "description = ?"), append(args, *v) + } if v := find.Visibility; v != nil { where, args = append(where, "visibility = ?"), append(args, *v) } @@ -272,6 +283,7 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) ( row_status, name, link, + description, visibility FROM shortcut WHERE `+strings.Join(where, " AND ")+` @@ -295,6 +307,7 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) ( &shortcutRaw.RowStatus, &shortcutRaw.Name, &shortcutRaw.Link, + &shortcutRaw.Description, &shortcutRaw.Visibility, ); err != nil { return nil, FormatError(err)