Skip to content

Commit

Permalink
Merge pull request #188 from h8570rg/develop
Browse files Browse the repository at this point in the history
Prd
  • Loading branch information
h8570rg authored Sep 17, 2024
2 parents c18214b + e2d01a1 commit 771cfa1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 4 additions & 0 deletions lib/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ export type Database = {
updated_at: string;
}[];
};
operation: {
Args: Record<PropertyKey, never>;
Returns: string;
};
search: {
Args: {
prefix: string;
Expand Down
5 changes: 4 additions & 1 deletion lib/migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ lib/migration

```bash
npm run supabase:start
npx supabase status
```

##### ユーザーID の取得
Expand All @@ -72,13 +73,15 @@ npm run supabase:start
以下のコマンドを実行し、データを新サービスに移行します:

```bash
SUPABASE_URL=<API URL> SERVICE_ROLE_KEY=<service_role key> npm run migration
SUPABASE_URL=<API URL> SERVICE_ROLE_KEY=<service_role key> npm run migrate
```

コマンド実行後、移管前ユーザーIDと移管後ユーザーIDを入力するプロンプトが表示されるので、準備した情報を入力してください。


## 注意事項

- 実行する前に必ず開発環境で動作確認を行ってください。
- service_role key は他者に漏洩しないよう注意してください。
- 複数回実行するとデータが重複して登録されるため、移行処理は1回のみ実行してください。
- 対象ユーザーの対戦相手はすべて新規ユーザーとして登録されます。
7 changes: 1 addition & 6 deletions lib/services/features/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,12 @@ export function matchService(supabase: Supabase) {
page?: number;
size?: number;
}): Promise<Match[]> {
const userResponse = await supabase.auth.getUser();
if (userResponse.error) throw userResponse.error;
const user = userResponse.data.user;

const matchesResponse = await supabase
.from("matches")
.select(
"*, match_players!inner(*, profiles!inner(*)), rules(*), games(*, game_players(*))",
"*, match_players(*, profiles!inner(*)), rules(*), games(*, game_players(*))",
{ count: "exact" },
)
.eq("match_players.player_id", user.id)
.range((page - 1) * size, page * size - 1)
.order("created_at", { ascending: false });

Expand Down
13 changes: 13 additions & 0 deletions supabase/migrations/20240917132542_local.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
drop policy "Authenticated users can select matches" on "public"."matches";

create policy "Authenticated users can select matches"
on "public"."matches"
as permissive
for select
to authenticated
using ((EXISTS ( SELECT 1
FROM match_players
WHERE ((match_players.match_id = matches.id) AND (match_players.player_id = auth.uid())))));



13 changes: 13 additions & 0 deletions supabase/migrations/20240917134035_local.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
drop policy "Authenticated users can select matches" on "public"."matches";

create policy "Authenticated users can select matches"
on "public"."matches"
as permissive
for select
to authenticated
using (((EXISTS ( SELECT 1
FROM match_players
WHERE ((match_players.match_id = matches.id) AND (match_players.player_id = auth.uid())))) OR (created_by = auth.uid())));



0 comments on commit 771cfa1

Please sign in to comment.