Unverified Commit c4ad4ace authored by Simon Esposito's avatar Simon Esposito Committed by GitHub
Browse files

Update get purchase/subscription signature (#990)

Set deleted user purchases/subs as belonging to system user.
Return empty user id when retrieving purchases/subscriptions belonging to the system user.
Do not return error when purchases validation contain mismatching userIDs.
parent 5b4416e1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr

### Changed
- Improve graceful shutdown of Google IAP receipt processor.
- If In-App Purchases validation contain mismatching userIDs, do not return an error.

### Fixed
- Consistent validation of override operator in runtime leaderboard record writes.
+1 −3
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ require (
	github.com/gorilla/mux v1.8.0
	github.com/gorilla/websocket v1.5.0
	github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3
	github.com/heroiclabs/nakama-common v1.26.0
	github.com/heroiclabs/nakama-common v1.26.1-0.20230227112928-be92be890386
	github.com/jackc/pgconn v1.13.0
	github.com/jackc/pgerrcode v0.0.0-20220416144525-469b46aa5efa
	github.com/jackc/pgtype v1.12.0
@@ -75,5 +75,3 @@ require (
	golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect
	golang.org/x/text v0.3.7 // indirect
)

replace github.com/heroiclabs/nakama-common => ../nakama-common
+2 −2
+67 −0
Original line number Diff line number Diff line
/*
 * Copyright 2021 The Nakama Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

-- +migrate Up
ALTER TABLE purchase
    DROP CONSTRAINT purchase_user_id_fkey;
ALTER TABLE subscription
    DROP CONSTRAINT subscription_user_id_fkey;

UPDATE purchase
    SET user_id = '00000000-0000-0000-0000-000000000000' WHERE user_id IS NULL;
UPDATE subscription
    SET user_id = '00000000-0000-0000-0000-000000000000' WHERE user_id IS NULL;

ALTER TABLE purchase
    ALTER COLUMN user_id SET NOT NULL;
ALTER TABLE purchase
    ALTER COLUMN user_id SET DEFAULT '00000000-0000-0000-0000-000000000000';

ALTER TABLE subscription
    ALTER COLUMN user_id SET NOT NULL;
ALTER TABLE subscription
    ALTER COLUMN user_id SET DEFAULT '00000000-0000-0000-0000-000000000000';

ALTER TABLE purchase
    ADD CONSTRAINT purchase_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET DEFAULT;
ALTER TABLE subscription
    ADD CONSTRAINT subscription_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET DEFAULT;

-- +migrate Down
ALTER TABLE purchase
    DROP CONSTRAINT purchase_user_id_fkey;
ALTER TABLE subscription
    DROP CONSTRAINT subscription_user_id_fkey;

ALTER TABLE purchase
    ALTER COLUMN user_id DROP DEFAULT;
ALTER TABLE purchase
    ALTER COLUMN user_id DROP NOT NULL;

ALTER TABLE subscription
    ALTER COLUMN user_id DROP DEFAULT;
ALTER TABLE subscription
    ALTER COLUMN user_id DROP NOT NULL;

UPDATE purchase
    SET user_id = NULL WHERE user_id = '00000000-0000-0000-0000-000000000000';
UPDATE subscription
    SET user_id = NULL WHERE user_id = '00000000-0000-0000-0000-000000000000';

ALTER TABLE purchase
    ADD CONSTRAINT purchase_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL;
ALTER TABLE subscription
    ADD CONSTRAINT subscription_user_id_fkey FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL;
+1 −1
Original line number Diff line number Diff line
@@ -216,7 +216,7 @@ func (s *ApiServer) GetSubscription(ctx context.Context, in *api.GetSubscription
		}
	}

	_, sub, err := GetSubscriptionByProductId(ctx, s.logger, s.db, userID.String(), in.ProductId)
	sub, err := GetSubscriptionByProductId(ctx, s.logger, s.db, userID.String(), in.ProductId)
	if err != nil {
		if err == ErrSubscriptionNotFound {
			return nil, status.Error(codes.NotFound, err.Error())
Loading