Skip to content

Commit

Permalink
Pull database schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddaytw committed Sep 11, 2024
1 parent 16e0f20 commit da4ff0f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ Supabase 提供 **Edge Functions**,這些是基於 [Deno](https://deno.land/)
如果你想修改資料庫欄位,請在本地端先進行開發測試,新增 migration 後再提 PR 請求更動正式伺服器。
請參考 Supabase 官方文件的 [Database Migration](https://supabase.com/docs/guides/cli/local-development#database-migrations) 部分

開發完成後,請將變更記錄到 Repository 裡面

```sh
npx supabase gen types typescript --local > src/utils/database.types.ts
npx supabase db pull --local
```

## 開發

我們使用 **ESLint** 來維護程式碼品質,並使用 **TypeScript** 進行型別檢查。這有助於提前發現錯誤,並使程式碼更容易理解。
Expand Down
39 changes: 38 additions & 1 deletion src/utils/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@ export type Json =
| Json[]

export type Database = {
graphql_public: {
Tables: {
[_ in never]: never
}
Views: {
[_ in never]: never
}
Functions: {
graphql: {
Args: {
operationName?: string
query?: string
variables?: Json
extensions?: Json
}
Returns: Json
}
}
Enums: {
[_ in never]: never
}
CompositeTypes: {
[_ in never]: never
}
}
public: {
Tables: {
events: {
Expand All @@ -18,6 +43,7 @@ export type Database = {
id: number
name: string | null
start_time: string | null
user_id: string
}
Insert: {
created_at?: string
Expand All @@ -27,6 +53,7 @@ export type Database = {
id?: number
name?: string | null
start_time?: string | null
user_id: string
}
Update: {
created_at?: string
Expand All @@ -36,8 +63,17 @@ export type Database = {
id?: number
name?: string | null
start_time?: string | null
user_id?: string
}
Relationships: []
Relationships: [
{
foreignKeyName: "events_user_id_fkey"
columns: ["user_id"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
},
]
}
sales: {
Row: {
Expand Down Expand Up @@ -168,3 +204,4 @@ export type Enums<
: PublicEnumNameOrOptions extends keyof PublicSchema["Enums"]
? PublicSchema["Enums"][PublicEnumNameOrOptions]
: never

23 changes: 23 additions & 0 deletions supabase/migrations/20240911215912_remote_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
alter table "public"."events" add column "user_id" uuid not null;

alter table "public"."events" add constraint "events_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE CASCADE ON DELETE CASCADE not valid;

alter table "public"."events" validate constraint "events_user_id_fkey";

create policy "Enable insert for authenticated users only"
on "public"."events"
as permissive
for insert
to authenticated
with check (true);


create policy "Enable update for users based on user_id"
on "public"."events"
as permissive
for update
to public
using ((( SELECT auth.uid() AS uid) = user_id));



0 comments on commit da4ff0f

Please sign in to comment.