Change type of favorite id from int to string

Bug: b/344960153
Change-Id: Ic84d9f867ecab1ec9be1fcdba5b893d9e2150479
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/866599
Reviewed-by: Ashwin Verleker <ashwinpv@google.com>
Commit-Queue: Vidit Chitkara <viditchitkara@google.com>
diff --git a/perf/go/favorites/mocks/Store.go b/perf/go/favorites/mocks/Store.go
index d78dd50..d854081 100644
--- a/perf/go/favorites/mocks/Store.go
+++ b/perf/go/favorites/mocks/Store.go
@@ -33,7 +33,7 @@
 }
 
 // Delete provides a mock function with given fields: ctx, userId, id
-func (_m *Store) Delete(ctx context.Context, userId string, id int64) error {
+func (_m *Store) Delete(ctx context.Context, userId string, id string) error {
 	ret := _m.Called(ctx, userId, id)
 
 	if len(ret) == 0 {
@@ -41,7 +41,7 @@
 	}
 
 	var r0 error
-	if rf, ok := ret.Get(0).(func(context.Context, string, int64) error); ok {
+	if rf, ok := ret.Get(0).(func(context.Context, string, string) error); ok {
 		r0 = rf(ctx, userId, id)
 	} else {
 		r0 = ret.Error(0)
@@ -51,7 +51,7 @@
 }
 
 // Get provides a mock function with given fields: ctx, id
-func (_m *Store) Get(ctx context.Context, id int64) (*favorites.Favorite, error) {
+func (_m *Store) Get(ctx context.Context, id string) (*favorites.Favorite, error) {
 	ret := _m.Called(ctx, id)
 
 	if len(ret) == 0 {
@@ -60,10 +60,10 @@
 
 	var r0 *favorites.Favorite
 	var r1 error
-	if rf, ok := ret.Get(0).(func(context.Context, int64) (*favorites.Favorite, error)); ok {
+	if rf, ok := ret.Get(0).(func(context.Context, string) (*favorites.Favorite, error)); ok {
 		return rf(ctx, id)
 	}
-	if rf, ok := ret.Get(0).(func(context.Context, int64) *favorites.Favorite); ok {
+	if rf, ok := ret.Get(0).(func(context.Context, string) *favorites.Favorite); ok {
 		r0 = rf(ctx, id)
 	} else {
 		if ret.Get(0) != nil {
@@ -71,7 +71,7 @@
 		}
 	}
 
-	if rf, ok := ret.Get(1).(func(context.Context, int64) error); ok {
+	if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
 		r1 = rf(ctx, id)
 	} else {
 		r1 = ret.Error(1)
@@ -111,7 +111,7 @@
 }
 
 // Update provides a mock function with given fields: ctx, req, id
-func (_m *Store) Update(ctx context.Context, req *favorites.SaveRequest, id int64) error {
+func (_m *Store) Update(ctx context.Context, req *favorites.SaveRequest, id string) error {
 	ret := _m.Called(ctx, req, id)
 
 	if len(ret) == 0 {
@@ -119,7 +119,7 @@
 	}
 
 	var r0 error
-	if rf, ok := ret.Get(0).(func(context.Context, *favorites.SaveRequest, int64) error); ok {
+	if rf, ok := ret.Get(0).(func(context.Context, *favorites.SaveRequest, string) error); ok {
 		r0 = rf(ctx, req, id)
 	} else {
 		r0 = ret.Error(0)
diff --git a/perf/go/favorites/sqlfavoritestore/schema/schema.go b/perf/go/favorites/sqlfavoritestore/schema/schema.go
index 2331c04..88fcb7f 100644
--- a/perf/go/favorites/sqlfavoritestore/schema/schema.go
+++ b/perf/go/favorites/sqlfavoritestore/schema/schema.go
@@ -3,7 +3,7 @@
 // FavoriteSchema represents the SQL schema of the Favorites table.
 type FavoriteSchema struct {
 	// Unique identifier of the favorite
-	ID int64 `sql:"id INT PRIMARY KEY DEFAULT unique_rowid()"`
+	ID string `sql:"id UUID PRIMARY KEY DEFAULT gen_random_uuid()"`
 
 	// The user to which this favorite belong. The user id
 	// will be their email as returned by uber-proxy auth
diff --git a/perf/go/favorites/sqlfavoritestore/sqlfavoritestore.go b/perf/go/favorites/sqlfavoritestore/sqlfavoritestore.go
index b7b4401..884a406 100644
--- a/perf/go/favorites/sqlfavoritestore/sqlfavoritestore.go
+++ b/perf/go/favorites/sqlfavoritestore/sqlfavoritestore.go
@@ -82,7 +82,7 @@
 }
 
 // Get implements the favorites.Store interface.
-func (s *FavoriteStore) Get(ctx context.Context, id int64) (*favorites.Favorite, error) {
+func (s *FavoriteStore) Get(ctx context.Context, id string) (*favorites.Favorite, error) {
 	fav := &favorites.Favorite{}
 	if err := s.db.QueryRow(ctx, statements[getFavorite], id).Scan(
 		&fav.ID,
@@ -107,22 +107,22 @@
 }
 
 // Create implements the favorites.Store interface.
-func (s *FavoriteStore) Update(ctx context.Context, req *favorites.SaveRequest, id int64) error {
+func (s *FavoriteStore) Update(ctx context.Context, req *favorites.SaveRequest, id string) error {
 	now := time.Now().Unix()
 	if _, err := s.db.Exec(ctx, statements[updateFavorite], req.Name, req.Url, req.Description, now, id); err != nil {
-		return skerr.Wrapf(err, "Failed to update favorite with id=%d", id)
+		return skerr.Wrapf(err, "Failed to update favorite with id=%s", id)
 	}
 	return nil
 }
 
 // Delete implements the favorites.Store interface.
-func (s *FavoriteStore) Delete(ctx context.Context, userId string, id int64) error {
+func (s *FavoriteStore) Delete(ctx context.Context, userId string, id string) error {
 	call, err := s.db.Exec(ctx, statements[deleteFavorite], id, userId)
 	if err != nil {
-		return skerr.Wrapf(err, "Failed to delete favorite with id=%d", id)
+		return skerr.Wrapf(err, "Failed to delete favorite with id=%s", id)
 	}
 	if call.RowsAffected() != 1 {
-		return skerr.Fmt("Failed to delete favorite with id=%d", id)
+		return skerr.Fmt("No rows changed=%s", id)
 	}
 
 	return nil
diff --git a/perf/go/favorites/sqlfavoritestore/sqlfavoritestore_test.go b/perf/go/favorites/sqlfavoritestore/sqlfavoritestore_test.go
index dddf38c..2e72780 100644
--- a/perf/go/favorites/sqlfavoritestore/sqlfavoritestore_test.go
+++ b/perf/go/favorites/sqlfavoritestore/sqlfavoritestore_test.go
@@ -52,10 +52,11 @@
 	favs, err := store.List(ctx, "a@b.com")
 	require.NoError(t, err)
 
-	favFromDb, err := store.Get(ctx, favs[0].ID)
+	getId := favs[0].ID
+	favFromDb, err := store.Get(ctx, getId)
 	require.NoError(t, err)
 
-	require.Equal(t, f1.Name, favFromDb.Name)
+	require.Equal(t, getId, favFromDb.ID)
 }
 
 func TestGet_NonExistentFavorite_ReturnsError(t *testing.T) {
@@ -72,7 +73,7 @@
 	err := store.Create(ctx, f1)
 	require.NoError(t, err)
 
-	_, err = store.Get(ctx, 10)
+	_, err = store.Get(ctx, "10")
 	require.Error(t, err)
 }
 
@@ -200,7 +201,7 @@
 	err = store.Create(ctx, f3)
 	require.NoError(t, err)
 
-	nonExistentFavId := int64(10)
+	nonExistentFavId := "10"
 
 	req := &favorites.SaveRequest{
 		Name:        "fav1updated",
@@ -208,14 +209,14 @@
 		Description: "Desc for fav1 updated",
 	}
 	err = store.Update(ctx, req, nonExistentFavId)
-	require.NoError(t, err)
+	require.Error(t, err)
 
 	favs, err := store.List(ctx, "a@b.com")
 	require.NoError(t, err)
 
 	require.Len(t, favs, 2)
-	require.Equal(t, favs[0].Name, "fav1")
-	require.Equal(t, favs[1].Name, "fav2")
+	require.Contains(t, []string{favs[0].Name, favs[1].Name}, "fav1")
+	require.Contains(t, []string{favs[0].Name, favs[1].Name}, "fav2")
 }
 
 func TestDelete_FavoriteWithId(t *testing.T) {
@@ -246,12 +247,13 @@
 	require.NoError(t, err)
 	require.Equal(t, 2, len(favsInDb))
 
-	err = store.Delete(ctx, "a@b.com", favsInDb[0].ID)
+	deleteId := favsInDb[0].ID
+	err = store.Delete(ctx, "a@b.com", deleteId)
 	require.NoError(t, err)
 
 	favsInDb, err = store.List(ctx, "a@b.com")
 	require.Equal(t, 1, len(favsInDb))
-	require.Equal(t, "fav2", favsInDb[0].Name)
+	require.NotEqual(t, deleteId, favsInDb[0].ID)
 }
 
 func TestList_ForUserId(t *testing.T) {
@@ -291,8 +293,8 @@
 	favFromDb, err := store.List(ctx, "a@b.com")
 	require.NoError(t, err)
 	require.Len(t, favFromDb, 2)
-	require.Equal(t, "fav1", favFromDb[0].Name)
-	require.Equal(t, "fav2", favFromDb[1].Name)
+	require.Contains(t, []string{favFromDb[0].Name, favFromDb[1].Name}, "fav1")
+	require.Contains(t, []string{favFromDb[0].Name, favFromDb[1].Name}, "fav2")
 }
 
 func TestList_ForUserId_EmptyList(t *testing.T) {
diff --git a/perf/go/favorites/store.go b/perf/go/favorites/store.go
index aaa5ce8..4b67f06 100644
--- a/perf/go/favorites/store.go
+++ b/perf/go/favorites/store.go
@@ -6,7 +6,7 @@
 
 // Favorite is a struct that represents a favorite.
 type Favorite struct {
-	ID           int64
+	ID           string
 	UserId       string
 	Name         string
 	Url          string
@@ -24,16 +24,16 @@
 // Store is the interface used to persist Favorites.
 type Store interface {
 	// Get fetches a favorite with the given id from the db.
-	Get(ctx context.Context, id int64) (*Favorite, error)
+	Get(ctx context.Context, id string) (*Favorite, error)
 
 	// Create inserts a new favorite into the db
 	Create(ctx context.Context, req *SaveRequest) error
 
 	// Update updates an existing favorite into the db based on id
-	Update(ctx context.Context, req *SaveRequest, id int64) error
+	Update(ctx context.Context, req *SaveRequest, id string) error
 
 	// Delete removes the Favorite with the given id.
-	Delete(ctx context.Context, userId string, id int64) error
+	Delete(ctx context.Context, userId string, id string) error
 
 	// List retrieves all the Favorites by user id (email).
 	List(ctx context.Context, userId string) ([]*Favorite, error)
diff --git a/perf/go/frontend/frontend.go b/perf/go/frontend/frontend.go
index 491e80e..fa805da 100644
--- a/perf/go/frontend/frontend.go
+++ b/perf/go/frontend/frontend.go
@@ -1883,7 +1883,7 @@
 
 // UpdateFavRequest is a request to update an existing Favorite
 type UpdateFavRequest struct {
-	Id          int64  `json:"id"`
+	Id          string `json:"id"`
 	Name        string `json:"name"`
 	Description string `json:"description"`
 	Url         string `json:"url"`
@@ -1932,7 +1932,7 @@
 
 // DeleteFavRequest is a request to delete an existing Favorite
 type DeleteFavRequest struct {
-	Id int64 `json:"id"`
+	Id string `json:"id"`
 }
 
 // deleteFavoriteHandler deletes a favorite per id in the db
diff --git a/perf/go/frontend/frontend_test.go b/perf/go/frontend/frontend_test.go
index d70fb7c..47a34bb 100644
--- a/perf/go/frontend/frontend_test.go
+++ b/perf/go/frontend/frontend_test.go
@@ -194,7 +194,7 @@
 func TestFrontendEditFavoriteHandler_Success(t *testing.T) {
 	w := httptest.NewRecorder()
 	updateFavReq := UpdateFavRequest{
-		Id:          12345,
+		Id:          "12345",
 		Name:        "Fav1",
 		Description: "Fav1 desc",
 		Url:         "fav.com",
@@ -205,7 +205,7 @@
 
 	favMocks := favoriteMocks.NewStore(t)
 	favMocks.On("Update", testutils.AnyContext, mock.Anything, updateFavReq.Id).Return(nil)
-	favMocks.On("Get", testutils.AnyContext, updateFavReq.Id).Return(&favorites.Favorite{ID: 12345, UserId: "nobody@example.org"}, nil)
+	favMocks.On("Get", testutils.AnyContext, updateFavReq.Id).Return(&favorites.Favorite{ID: "12345", UserId: "nobody@example.org"}, nil)
 
 	login := mocks.NewLogin(t)
 	login.On("LoggedInAs", r).Return(alogin.EMail("nobody@example.org"))
@@ -223,7 +223,7 @@
 func TestFrontendDeleteFavoriteHandler_Success(t *testing.T) {
 	w := httptest.NewRecorder()
 	deleteFavReq := DeleteFavRequest{
-		Id: 12345,
+		Id: "12345",
 	}
 	favBody, _ := json.Marshal(deleteFavReq)
 	body := bytes.NewReader(favBody)
@@ -258,8 +258,8 @@
 
 	favMocks := favoriteMocks.NewStore(t)
 	fakeUserFavs := []*favorites.Favorite{
-		{ID: 12345, UserId: "nobody@example.org"},
-		{ID: 23456, UserId: "nobody@example.org"},
+		{ID: "12345", UserId: "nobody@example.org"},
+		{ID: "23456", UserId: "nobody@example.org"},
 	}
 	favMocks.On("List", testutils.AnyContext, "nobody@example.org").Return(fakeUserFavs, nil)
 
diff --git a/perf/go/sql/expectedschema/migrate.go b/perf/go/sql/expectedschema/migrate.go
index 3022786..3350563 100644
--- a/perf/go/sql/expectedschema/migrate.go
+++ b/perf/go/sql/expectedschema/migrate.go
@@ -37,8 +37,9 @@
 // DO NOT DROP TABLES IN VAR BELOW.
 // FOR MODIFYING COLUMNS USE ADD/DROP COLUMN INSTEAD.
 var FromLiveToNext = `
+	DROP TABLE IF EXISTS Favorites;
 	CREATE TABLE IF NOT EXISTS Favorites (
-		id INT PRIMARY KEY DEFAULT unique_rowid(),
+		id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
 		user_id STRING NOT NULL,
 		name STRING,
 		url STRING NOT NULL,
@@ -51,7 +52,16 @@
 // ONLY DROP TABLE IF YOU JUST CREATED A NEW TABLE.
 // FOR MODIFYING COLUMNS USE ADD/DROP COLUMN INSTEAD.
 var FromNextToLive = `
-	DROP TABLE IF EXISTS Favorites;
+DROP TABLE IF EXISTS Favorites;
+CREATE TABLE IF NOT EXISTS Favorites (
+	id INT PRIMARY KEY DEFAULT unique_rowid(),
+	user_id STRING NOT NULL,
+	name STRING,
+	url STRING NOT NULL,
+	description STRING,
+	last_modified INT,
+	INDEX by_user_id (user_id)
+  );
 `
 
 // This function will check whether there's a new schema checked-in,
diff --git a/perf/go/sql/expectedschema/schema.json b/perf/go/sql/expectedschema/schema.json
index 6012b58..e52da6a 100644
--- a/perf/go/sql/expectedschema/schema.json
+++ b/perf/go/sql/expectedschema/schema.json
@@ -32,7 +32,7 @@
     "culprits.project": "text def: nullable:YES",
     "culprits.ref": "text def: nullable:YES",
     "culprits.revision": "text def: nullable:YES",
-    "favorites.id": "bigint def:unique_rowid() nullable:NO",
+    "favorites.id": "uuid def:gen_random_uuid() nullable:NO",
     "favorites.user_id": "text def: nullable:NO",
     "favorites.name": "text def: nullable:YES",
     "favorites.description": "text def: nullable:YES",
diff --git a/perf/go/sql/expectedschema/schema_prev.json b/perf/go/sql/expectedschema/schema_prev.json
index f440579..c54e314 100644
--- a/perf/go/sql/expectedschema/schema_prev.json
+++ b/perf/go/sql/expectedschema/schema_prev.json
@@ -32,6 +32,12 @@
     "culprits.project": "text def: nullable:YES",
     "culprits.ref": "text def: nullable:YES",
     "culprits.revision": "text def: nullable:YES",
+    "favorites.id": "bigint def:unique_rowid() nullable:NO",
+    "favorites.user_id": "text def: nullable:NO",
+    "favorites.name": "text def: nullable:YES",
+    "favorites.description": "text def: nullable:YES",
+    "favorites.url": "text def: nullable:NO",
+    "favorites.last_modified": "bigint def: nullable:YES",
     "graphsshortcuts.graphs": "text def: nullable:YES",
     "graphsshortcuts.id": "text def: nullable:NO",
     "paramsets.param_key": "text def: nullable:NO",
@@ -79,6 +85,7 @@
   "IndexNames": [
     "commits.commits_git_hash_key",
     "culprits.by_revision",
+    "favorites.by_user_id",
     "paramsets.by_tile_number",
     "postings.by_trace_id",
     "postings.by_key_value",
diff --git a/perf/go/sql/schema.go b/perf/go/sql/schema.go
index 3bdc48a..73f7efe 100644
--- a/perf/go/sql/schema.go
+++ b/perf/go/sql/schema.go
@@ -45,7 +45,7 @@
   UNIQUE INDEX by_revision (revision, host, project, ref)
 );
 CREATE TABLE IF NOT EXISTS Favorites (
-  id INT PRIMARY KEY DEFAULT unique_rowid(),
+  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
   user_id STRING NOT NULL,
   name STRING,
   url STRING NOT NULL,
diff --git a/perf/go/sql/sql_test.go b/perf/go/sql/sql_test.go
index b32a02d..9f1209c 100644
--- a/perf/go/sql/sql_test.go
+++ b/perf/go/sql/sql_test.go
@@ -72,6 +72,15 @@
 	group_issue_map JSONB,
 	UNIQUE INDEX by_revision (revision, host, project, ref)
   );
+  CREATE TABLE IF NOT EXISTS Favorites (
+	id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
+	user_id STRING NOT NULL,
+	name STRING,
+	url STRING NOT NULL,
+	description STRING,
+	last_modified INT,
+	INDEX by_user_id (user_id)
+  );
   CREATE TABLE IF NOT EXISTS GraphsShortcuts (
 	id TEXT UNIQUE NOT NULL PRIMARY KEY,
 	graphs TEXT