Skip to content

Commit 118ec7a

Browse files
author
Jens Winter-Huebenthal
committed
Merge remote-tracking branch 'origin/master' into main-magdeburg
# Conflicts: # .github/workflows/deploy-to-supabase-production.yml # .github/workflows/deploy-to-supabase-staging.yml # supabase/functions/gdk_stats/index.ts
2 parents 2373a52 + 8ebb1c3 commit 118ec7a

14 files changed

+283
-74
lines changed

.github/workflows/deploy-to-supabase-production.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- uses: supabase/setup-cli@v1
2424
with:
25-
version: 2.19.7
25+
version: 2.20.3
2626

2727
- run: |
2828
supabase link --project-ref $PRODUCTION_PROJECT_ID

.github/workflows/deploy-to-supabase-staging.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- uses: supabase/setup-cli@v1
2424
with:
25-
version: 2.19.7
25+
version: 2.20.3
2626

2727
- run: |
2828
supabase link --project-ref $STAGING_PROJECT_ID

.github/workflows/tests.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
# TODO: adjust ci workflow to use new testing setup (vercel and supabase)
55
name: Node.js CI
6+
permissions:
7+
contents: write
8+
packages: write
69
env:
710
CI: "true"
811
NODE_ENV: "test"
@@ -41,7 +44,7 @@ jobs:
4144
node-version-file: ".nvmrc"
4245
- uses: supabase/setup-cli@v1
4346
with:
44-
version: 1.142.2
47+
version: 2.20.3
4548
- run: supabase start
4649
- run: npm ci
4750
- run: npm run build --if-present

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,6 @@ cython_debug/
281281
sql/trees_trees_2022-11-09T12-28-18.sql
282282
sql/trees_bezirk_mitte_table_2022-11-08T16-32-58.sql
283283
sql/*.dump
284+
# user specific cursor rules
285+
.cursor/rules/*
286+
.cursor/mcp.json

.tool-versions

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
supabase-cli 2.20.3
2+
direnv 2.35.0

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,40 @@ npm test
168168

169169
On CI the Supabase is started automagically. See [.github/workflows/tests.yml](.github/workflows/tests.yml)
170170

171+
172+
## Database Caveats
173+
174+
To not hardcode values in the edge functions we are using materialized views.
175+
176+
- `most_frequent_tree_species`
177+
- `total_tree_species_count`
178+
- `waterings_with_location`
179+
180+
In case you need to restore the data from a backup you need to disable the triggers first.
181+
182+
```sql
183+
ALTER TABLE trees DISABLE TRIGGER tg_refresh_trees_count_mv;
184+
ALTER TABLE trees DISABLE TRIGGER tg_refresh_most_frequent_tree_species_mv;
185+
ALTER TABLE trees DISABLE TRIGGER tg_refresh_total_tree_species_count_mv;
186+
```
187+
188+
After restore is done, refresh the materialized views and re-enable our specific triggers.
189+
190+
```sql
191+
-- Manually refresh all materialized views
192+
REFRESH MATERIALIZED VIEW CONCURRENTLY total_tree_species_count;
193+
REFRESH MATERIALIZED VIEW CONCURRENTLY most_frequent_tree_species;
194+
REFRESH MATERIALIZED VIEW CONCURRENTLY trees_count;
195+
196+
-- Re-enable our specific triggers
197+
ALTER TABLE trees ENABLE TRIGGER tg_refresh_trees_count_mv;
198+
ALTER TABLE trees ENABLE TRIGGER tg_refresh_most_frequent_tree_species_mv;
199+
ALTER TABLE trees ENABLE TRIGGER tg_refresh_total_tree_species_count_mv;
200+
```
201+
202+
203+
204+
171205
## Contributors ✨
172206

173207
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
"scripts": {
77
"test": "jest --runInBand",
88
"lint": "eslint ./**/*.ts ",
9-
"format": "prettier ./**/*.ts --write"
9+
"format": "prettier ./**/*.ts --write",
10+
"dev:supabase:functions": "supabase functions serve --no-verify-jwt --env-file supabase/.env",
11+
"supabase:types:local": "supabase gen types --local > src/database.ts"
1012
},
1113
"engines": {
12-
"node": ">=18"
14+
"node": ">=20"
1315
},
1416
"dependencies": {
1517
"@supabase/supabase-js": "2.43.5"

src/database.ts

+69-26
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,7 @@ export type Database = {
3434
id?: string
3535
user_id?: string
3636
}
37-
Relationships: [
38-
{
39-
foreignKeyName: "contact_requests_contact_id_fkey"
40-
columns: ["contact_id"]
41-
isOneToOne: false
42-
referencedRelation: "users"
43-
referencedColumns: ["id"]
44-
},
45-
{
46-
foreignKeyName: "contact_requests_user_id_fkey"
47-
columns: ["user_id"]
48-
isOneToOne: false
49-
referencedRelation: "users"
50-
referencedColumns: ["id"]
51-
},
52-
]
37+
Relationships: []
5338
}
5439
daily_weather_data: {
5540
Row: {
@@ -124,15 +109,7 @@ export type Database = {
124109
id?: string
125110
username?: string | null
126111
}
127-
Relationships: [
128-
{
129-
foreignKeyName: "fk_users_profiles"
130-
columns: ["id"]
131-
isOneToOne: false
132-
referencedRelation: "users"
133-
referencedColumns: ["id"]
134-
},
135-
]
112+
Relationships: []
136113
}
137114
radolan_data: {
138115
Row: {
@@ -368,7 +345,25 @@ export type Database = {
368345
}
369346
}
370347
Views: {
371-
[_ in never]: never
348+
most_frequent_tree_species: {
349+
Row: {
350+
gattung_deutsch: string | null
351+
percentage: number | null
352+
}
353+
Relationships: []
354+
}
355+
total_tree_species_count: {
356+
Row: {
357+
count: number | null
358+
}
359+
Relationships: []
360+
}
361+
trees_count: {
362+
Row: {
363+
count: number | null
364+
}
365+
Relationships: []
366+
}
372367
}
373368
Functions: {
374369
accumulated_weather_per_month: {
@@ -391,12 +386,20 @@ export type Database = {
391386
avg_wind_gust_speed_kmh: number
392387
}[]
393388
}
389+
calculate_adoptions: {
390+
Args: Record<PropertyKey, never>
391+
Returns: {
392+
total_adoptions: number
393+
very_thirsty_adoptions: number
394+
}[]
395+
}
394396
calculate_avg_waterings_per_month: {
395397
Args: Record<PropertyKey, never>
396398
Returns: {
397399
month: string
398400
watering_count: number
399401
avg_amount_per_watering: number
402+
total_sum: number
400403
}[]
401404
}
402405
calculate_top_tree_species: {
@@ -413,6 +416,15 @@ export type Database = {
413416
}
414417
Returns: number
415418
}
419+
get_monthly_weather: {
420+
Args: Record<PropertyKey, never>
421+
Returns: {
422+
month: string
423+
avg_temperature_celsius: number
424+
max_temperature_celsius: number
425+
total_rainfall_liters: number
426+
}[]
427+
}
416428
get_user_data_for_id: {
417429
Args: {
418430
u_id: string
@@ -430,6 +442,22 @@ export type Database = {
430442
watered: number
431443
}[]
432444
}
445+
get_waterings_with_location: {
446+
Args: Record<PropertyKey, never>
447+
Returns: {
448+
id: string
449+
lat: number
450+
lng: number
451+
amount: number
452+
timestamp: string
453+
}[]
454+
}
455+
is_username_taken: {
456+
Args: {
457+
given_username: string
458+
}
459+
Returns: boolean
460+
}
433461
remove_account: {
434462
Args: Record<PropertyKey, never>
435463
Returns: undefined
@@ -557,3 +585,18 @@ export type Enums<
557585
? PublicSchema["Enums"][PublicEnumNameOrOptions]
558586
: never
559587

588+
export type CompositeTypes<
589+
PublicCompositeTypeNameOrOptions extends
590+
| keyof PublicSchema["CompositeTypes"]
591+
| { schema: keyof Database },
592+
CompositeTypeName extends PublicCompositeTypeNameOrOptions extends {
593+
schema: keyof Database
594+
}
595+
? keyof Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"]
596+
: never = never,
597+
> = PublicCompositeTypeNameOrOptions extends { schema: keyof Database }
598+
? Database[PublicCompositeTypeNameOrOptions["schema"]]["CompositeTypes"][CompositeTypeName]
599+
: PublicCompositeTypeNameOrOptions extends keyof PublicSchema["CompositeTypes"]
600+
? PublicSchema["CompositeTypes"][PublicCompositeTypeNameOrOptions]
601+
: never
602+

supabase/config.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ project_id = "magdeburggiesst-supabase"
77
port = 54321
88
# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API
99
# endpoints. public and storage are always included.
10-
schemas = []
11-
# Extra schemas to add to the search_path of every request.
12-
extra_search_path = ["extensions"]
10+
schemas = ["public", "storage", "graphql_public"]
11+
extra_search_path = ["public", "extensions"]
1312
# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size
1413
# for accidental or malicious requests.
1514
max_rows = 10000

supabase/functions/_shared/errors.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ export enum ErrorTypes {
55
GdkStatsAdoption = "gdk_stats_adoptions",
66
GdkStatsTreeSpecie = "gdk_stats_tree_species",
77
GdkStatsWeather = "gdk_stats_weather",
8+
GdkStatsTreeCount = "gdk_stats_tree_count",
9+
GdkStatsTreeSpeciesCount = "gdk_stats_tree_species_count",
10+
GdkStatsMostFrequentTreeSpecies = "gdk_stats_most_frequent_tree_species",
811
}
912

1013
export class GdkError extends Error {

0 commit comments

Comments
 (0)