From 575a0610a3dad7476c5d014eeecf91279c54f184 Mon Sep 17 00:00:00 2001 From: boojack Date: Fri, 16 Dec 2022 22:20:17 +0800 Subject: [PATCH] chore: revert "feat: add `visibility` field to resource (#743)" (#751) Revert "feat: add `visibility` field to resource (#743)" This reverts commit b68cc085922a4551c6d493e9e9e0739831f8480c. --- api/resource.go | 26 ++++++------- store/db/migration/dev/LATEST__SCHEMA.sql | 3 +- .../prod/0.9/00__resource_visibility.sql | 2 - store/resource.go | 37 ++++++------------- 4 files changed, 24 insertions(+), 44 deletions(-) delete mode 100644 store/db/migration/prod/0.9/00__resource_visibility.sql diff --git a/api/resource.go b/api/resource.go index 292b46c..b833f91 100644 --- a/api/resource.go +++ b/api/resource.go @@ -9,11 +9,10 @@ type Resource struct { UpdatedTs int64 `json:"updatedTs"` // Domain specific fields - Filename string `json:"filename"` - Blob []byte `json:"-"` - Type string `json:"type"` - Size int64 `json:"size"` - Visibility Visibility `json:"visibility"` + Filename string `json:"filename"` + Blob []byte `json:"-"` + Type string `json:"type"` + Size int64 `json:"size"` // Related fields LinkedMemoAmount int `json:"linkedMemoAmount"` @@ -24,11 +23,10 @@ type ResourceCreate struct { CreatorID int // Domain specific fields - Filename string `json:"filename"` - Blob []byte `json:"blob"` - Type string `json:"type"` - Size int64 `json:"size"` - Visibility Visibility `json:"visibility"` + Filename string `json:"filename"` + Blob []byte `json:"blob"` + Type string `json:"type"` + Size int64 `json:"size"` } type ResourceFind struct { @@ -38,9 +36,8 @@ type ResourceFind struct { CreatorID *int `json:"creatorId"` // Domain specific fields - Filename *string `json:"filename"` - MemoID *int - Visibility *Visibility `json:"visibility"` + Filename *string `json:"filename"` + MemoID *int } type ResourcePatch struct { @@ -50,8 +47,7 @@ type ResourcePatch struct { UpdatedTs *int64 // Domain specific fields - Filename *string `json:"filename"` - Visibility *Visibility `json:"visibility"` + Filename *string `json:"filename"` } type ResourceDelete struct { diff --git a/store/db/migration/dev/LATEST__SCHEMA.sql b/store/db/migration/dev/LATEST__SCHEMA.sql index 60ba74c..a5ac821 100644 --- a/store/db/migration/dev/LATEST__SCHEMA.sql +++ b/store/db/migration/dev/LATEST__SCHEMA.sql @@ -75,8 +75,7 @@ CREATE TABLE resource ( blob BLOB DEFAULT NULL, external_link TEXT NOT NULL DEFAULT '', type TEXT NOT NULL DEFAULT '', - size INTEGER NOT NULL DEFAULT 0, - visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED', 'PRIVATE')) DEFAULT 'PRIVATE' + size INTEGER NOT NULL DEFAULT 0 ); -- memo_resource diff --git a/store/db/migration/prod/0.9/00__resource_visibility.sql b/store/db/migration/prod/0.9/00__resource_visibility.sql deleted file mode 100644 index a2c2e05..0000000 --- a/store/db/migration/prod/0.9/00__resource_visibility.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Add visibility field to resource -ALTER TABLE resource ADD COLUMN visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PROTECTED' 'PRIVATE')) DEFAULT 'PRIVATE'; diff --git a/store/resource.go b/store/resource.go index 2b0ef6c..eb8703b 100644 --- a/store/resource.go +++ b/store/resource.go @@ -22,11 +22,10 @@ type resourceRaw struct { UpdatedTs int64 // Domain specific fields - Filename string - Blob []byte - Type string - Size int64 - Visibility api.Visibility + Filename string + Blob []byte + Type string + Size int64 } func (raw *resourceRaw) toResource() *api.Resource { @@ -39,11 +38,10 @@ func (raw *resourceRaw) toResource() *api.Resource { UpdatedTs: raw.UpdatedTs, // Domain specific fields - Filename: raw.Filename, - Blob: raw.Blob, - Type: raw.Type, - Size: raw.Size, - Visibility: raw.Visibility, + Filename: raw.Filename, + Blob: raw.Blob, + Type: raw.Type, + Size: raw.Size, } } @@ -219,20 +217,18 @@ func createResource(ctx context.Context, tx *sql.Tx, create *api.ResourceCreate) blob, type, size, - visibility, creator_id ) - VALUES (?, ?, ?, ?, ?, ?) - RETURNING id, filename, blob, type, size, visibility, creator_id, created_ts, updated_ts + VALUES (?, ?, ?, ?, ?) + RETURNING id, filename, blob, type, size, creator_id, created_ts, updated_ts ` var resourceRaw resourceRaw - if err := tx.QueryRowContext(ctx, query, create.Filename, create.Blob, create.Type, create.Size, create.Visibility, create.CreatorID).Scan( + if err := tx.QueryRowContext(ctx, query, create.Filename, create.Blob, create.Type, create.Size, create.CreatorID).Scan( &resourceRaw.ID, &resourceRaw.Filename, &resourceRaw.Blob, &resourceRaw.Type, &resourceRaw.Size, - &resourceRaw.Visibility, &resourceRaw.CreatorID, &resourceRaw.CreatedTs, &resourceRaw.UpdatedTs, @@ -252,9 +248,6 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (* if v := patch.Filename; v != nil { set, args = append(set, "filename = ?"), append(args, *v) } - if v := patch.Visibility; v != nil { - set, args = append(set, "visibility = ?"), append(args, *v) - } args = append(args, patch.ID) @@ -262,7 +255,7 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (* UPDATE resource SET ` + strings.Join(set, ", ") + ` WHERE id = ? - RETURNING id, filename, blob, type, size, visibility, creator_id, created_ts, updated_ts + RETURNING id, filename, blob, type, size, creator_id, created_ts, updated_ts ` var resourceRaw resourceRaw if err := tx.QueryRowContext(ctx, query, args...).Scan( @@ -271,7 +264,6 @@ func patchResource(ctx context.Context, tx *sql.Tx, patch *api.ResourcePatch) (* &resourceRaw.Blob, &resourceRaw.Type, &resourceRaw.Size, - &resourceRaw.Visibility, &resourceRaw.CreatorID, &resourceRaw.CreatedTs, &resourceRaw.UpdatedTs, @@ -294,9 +286,6 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) ( if v := find.Filename; v != nil { where, args = append(where, "filename = ?"), append(args, *v) } - if v := find.Visibility; v != nil { - where, args = append(where, "visibility = ?"), append(args, *v) - } if v := find.MemoID; v != nil { where, args = append(where, "id in (SELECT resource_id FROM memo_resource WHERE memo_id = ?)"), append(args, *v) } @@ -308,7 +297,6 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) ( blob, type, size, - visibility, creator_id, created_ts, updated_ts @@ -331,7 +319,6 @@ func findResourceList(ctx context.Context, tx *sql.Tx, find *api.ResourceFind) ( &resourceRaw.Blob, &resourceRaw.Type, &resourceRaw.Size, - &resourceRaw.Visibility, &resourceRaw.CreatorID, &resourceRaw.CreatedTs, &resourceRaw.UpdatedTs,