π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[server] Change entity_data.id from uuid to string
Neeraj Gupta9f043eba2425
diff --git a/server/ente/userentity/entity.go b/server/ente/userentity/entity.goindex fc39c0f474..965938b63d 100644--- a/server/ente/userentity/entity.go+++ b/server/ente/userentity/entity.go@@ -1,9 +1,5 @@package userentity-import (- "github.com/google/uuid"-)-type EntityType stringconst (@@ -23,7 +19,7 @@ type EntityKey struct {// EntityData represents a single UserEntitytype EntityData struct {- ID uuid.UUID `json:"id" binding:"required"`+ ID string `json:"id" binding:"required"`UserID int64 `json:"userID" binding:"required"`Type EntityType `json:"type" binding:"required"`EncryptedData *string `json:"encryptedData" binding:"required"`@@ -54,7 +50,7 @@ type EntityDataRequest struct {// UpdateEntityDataRequest updates the current entitytype UpdateEntityDataRequest struct {- ID uuid.UUID `json:"id" binding:"required"`+ ID string `json:"id" binding:"required"`Type EntityType `json:"type" binding:"required"`EncryptedData string `json:"encryptedData" binding:"required"`Header string `json:"header" binding:"required"`diff --git a/server/migrations/90_use_string_id_entity.down.sql b/server/migrations/90_use_string_id_entity.down.sqlnew file mode 100644index 0000000000..7ea155d388--- /dev/null+++ b/server/migrations/90_use_string_id_entity.down.sql@@ -0,0 +1,9 @@+BEGIN;+ALTER TABLE entity_data ADD COLUMN id_uuid UUID;+UPDATE entity_data SET id_uuid = id::UUID;+ALTER TABLE entity_data ALTER COLUMN id_uuid SET NOT NULL;+ALTER TABLE entity_data DROP CONSTRAINT entity_data_pkey;+ALTER TABLE entity_data DROP COLUMN IF EXISTS id;+ALTER TABLE entity_data RENAME COLUMN id_uuid TO id;+ALTER TABLE entity_data ADD PRIMARY KEY (id);+COMMIT;diff --git a/server/migrations/90_use_string_id_entity.up.sql b/server/migrations/90_use_string_id_entity.up.sqlnew file mode 100644index 0000000000..8477eb0de1--- /dev/null+++ b/server/migrations/90_use_string_id_entity.up.sql@@ -0,0 +1,9 @@+BEGIN;+ALTER TABLE entity_data ADD COLUMN id_text TEXT;+UPDATE entity_data SET id_text = id::TEXT;+ALTER TABLE entity_data ALTER COLUMN id_text SET NOT NULL;+ALTER TABLE entity_data DROP CONSTRAINT entity_data_pkey;+ALTER TABLE entity_data DROP COLUMN IF EXISTS id;+ALTER TABLE entity_data RENAME COLUMN id_text TO id;+ALTER TABLE entity_data ADD PRIMARY KEY (id);+END;diff --git a/server/pkg/api/userentity.go b/server/pkg/api/userentity.goindex 1d10b3464a..004eda6137 100644--- a/server/pkg/api/userentity.go+++ b/server/pkg/api/userentity.go@@ -10,7 +10,6 @@ import ("github.com/ente-io/museum/pkg/utils/handler""github.com/ente-io/stacktrace""github.com/gin-gonic/gin"- "github.com/google/uuid")// UserEntityHandler expose request handlers for various operations on user entity@@ -84,12 +83,8 @@ func (h *UserEntityHandler) UpdateEntity(c *gin.Context) {// DeleteEntity...func (h *UserEntityHandler) DeleteEntity(c *gin.Context) {- id, err := uuid.Parse(c.Query("id"))- if err != nil {- handler.Error(c, stacktrace.Propagate(ente.ErrBadRequest, "failed to find id"))- return- }- _, err = h.Controller.Delete(c, id)+ id := c.Query("id")+ _, err := h.Controller.Delete(c, id)if err != nil {handler.Error(c, stacktrace.Propagate(err, "Failed to delete DeleteEntity"))returndiff --git a/server/pkg/controller/userentity/controller.go b/server/pkg/controller/userentity/controller.goindex 827d8708ac..f4fb1c8b9b 100644--- a/server/pkg/controller/userentity/controller.go+++ b/server/pkg/controller/userentity/controller.go@@ -5,8 +5,6 @@ import ("github.com/ente-io/museum/pkg/repo/userentity""github.com/ente-io/museum/pkg/utils/auth""github.com/ente-io/stacktrace"- "github.com/google/uuid"-"github.com/gin-gonic/gin")@@ -52,7 +50,7 @@ func (c *Controller) UpdateEntity(ctx *gin.Context, req model.UpdateEntityDataRe}// Delete...-func (c *Controller) Delete(ctx *gin.Context, entityID uuid.UUID) (bool, error) {+func (c *Controller) Delete(ctx *gin.Context, entityID string) (bool, error) {userID := auth.GetUserID(ctx.Request.Header)return c.Repo.Delete(ctx, userID, entityID)}diff --git a/server/pkg/repo/userentity/data.go b/server/pkg/repo/userentity/data.goindex 86263ff240..25b0e5a52a 100644--- a/server/pkg/repo/userentity/data.go+++ b/server/pkg/repo/userentity/data.go@@ -13,7 +13,7 @@ import ()// Create inserts a new entry-func (r *Repository) Create(ctx context.Context, userID int64, entry model.EntityDataRequest) (uuid.UUID, error) {+func (r *Repository) Create(ctx context.Context, userID int64, entry model.EntityDataRequest) (string, error) {id := uuid.New()err := r.DB.QueryRow(`INSERT into entity_data(id,@@ -28,12 +28,12 @@ func (r *Repository) Create(ctx context.Context, userID int64, entry model.Entitentry.Header). // $5 headerScan(&id)if err != nil {- return id, stacktrace.Propagate(err, "failed to create enity data")+ return id.String(), stacktrace.Propagate(err, "failed to create enity data")}- return id, nil+ return id.String(), nil}-func (r *Repository) Get(ctx context.Context, userID int64, id uuid.UUID) (*model.EntityData, error) {+func (r *Repository) Get(ctx context.Context, userID int64, id string) (*model.EntityData, error) {res := model.EntityData{}row := r.DB.QueryRowContext(ctx, `SELECTid, user_id, type, encrypted_data, header, is_deleted, created_at, updated_at@@ -50,7 +50,7 @@ func (r *Repository) Get(ctx context.Context, userID int64, id uuid.UUID) (*modereturn &res, nil}-func (r *Repository) Delete(ctx context.Context, userID int64, id uuid.UUID) (bool, error) {+func (r *Repository) Delete(ctx context.Context, userID int64, id string) (bool, error) {_, err := r.DB.ExecContext(ctx,`UPDATE entity_data SET is_deleted = true, encrypted_data = NULL, header = NULL where id=$1 and user_id = $2`,id, userID)