Skip to content

Commit

Permalink
Merge pull request #270 from technologiestiftung/staging
Browse files Browse the repository at this point in the history
Staging to prod
  • Loading branch information
Jaszkowic authored Jul 22, 2024
2 parents 0e41392 + ceb5942 commit 5e6e908
Show file tree
Hide file tree
Showing 26 changed files with 1,699 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-to-supabase-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ jobs:
- run: |
supabase link --project-ref $PRODUCTION_PROJECT_ID
supabase db push
supabase functions deploy
1 change: 1 addition & 0 deletions .github/workflows/deploy-to-supabase-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ jobs:
- run: |
supabase link --project-ref $STAGING_PROJECT_ID
supabase db push
supabase functions deploy
5 changes: 2 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ jobs:
- run: supabase start
- run: npm ci
- run: npm run build --if-present
# Make sure to run tests in band and force exit to avoid hanging tests
# until we know where the open handles are
- run: npm run lint
- run: npm test -- --runInBand --forceExit
- run: supabase stop
- run: npm run lint

release:
name: semantic-release
needs: [test]
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
Expand Down
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ npm test

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

To run the tests for the Supabase Edge Functions, execute locally:

```bash
cd giessdenkiez-de-postgres-api
docker run -p 1025:1025 mailhog/mailhog
supabase start
supabase functions serve --no-verify-jwt --env-file supabase/.env.test
deno test --allow-all supabase/functions/tests/submit-contact-request-tests.ts --env=supabase/.env.test
```

## Supabase

### Migrations and Types
Expand All @@ -106,7 +116,7 @@ On CI the Supabase is started automagically. See [.github/workflows/tests.yml](.
- **(Not recommended but possible)** Link your local project directly to the remote `supabase link --project-ref <YOUR PROJECT REF>` (will ask you for your database password from the creation process)
- **(Not recommended but possible)** Push your local state directly to your remote project `supabase db push` (will ask you for your database password from the creation process)

#### Supabase
#### Supabase Auth

Some of the requests need a authorized user. You can create a new user using email password via the Supabase API.

Expand All @@ -132,6 +142,17 @@ curl --request POST \

See the [docs/api.http](./docs/api.http) file for more examples or take a look into the API documentation in your local supabase instance under http://localhost:54323/project/default/api?page=users

#### Supabase Edge Functions
To run the Supabase Edge Functions locally:

- Setup the .env file in [supabase/.env](supabase/.env) according to [supabase/.env.sample](supabase/.env.sample)
- Note: The env variables `SUPABASE_SERVICE_ROLE_KEY` and `SUPABASE_URL` are injected automatically and can't be set the in the [supabase/.env](supabase/.env) file. If you want to overwrite them, you have to rename the environment variables to not start with `SUPABASE_`. For reference, see: https://supabase.com/docs/guides/functions/secrets
- With the environment variables setup correctly, execute `supabase functions serve --no-verify-jwt --env-file supabase/.env`

To deploy the Edge Functions in your linked remote Supabase project, execute:
- `supabase functions deploy`
- Make sure that you set the proper environment variables in the remote Supabase project too

## Tests

Locally you will need supabase running and a `.env` file with the right values in it.
Expand Down
52 changes: 26 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"node": ">=18"
},
"dependencies": {
"@supabase/supabase-js": "2.43.2"
"@supabase/supabase-js": "2.43.5"
},
"devDependencies": {
"@saithodev/semantic-release-backmerge": "4.0.1",
Expand Down
146 changes: 146 additions & 0 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,108 @@ export type Json =
export type Database = {
public: {
Tables: {
contact_requests: {
Row: {
contact_id: string
contact_mail_id: string | null
contact_message: string | null
created_at: string
id: string
user_id: string
}
Insert: {
contact_id: string
contact_mail_id?: string | null
contact_message?: string | null
created_at?: string
id?: string
user_id: string
}
Update: {
contact_id?: string
contact_mail_id?: string | null
contact_message?: string | null
created_at?: string
id?: string
user_id?: string
}
Relationships: [
{
foreignKeyName: "contact_requests_contact_id_fkey"
columns: ["contact_id"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
},
{
foreignKeyName: "contact_requests_user_id_fkey"
columns: ["user_id"]
isOneToOne: false
referencedRelation: "users"
referencedColumns: ["id"]
},
]
}
daily_weather_data: {
Row: {
avg_cloud_cover_percentage: number | null
avg_dew_point_celcius: number | null
avg_pressure_msl: number | null
avg_relative_humidity_percentage: number | null
avg_temperature_celsius: number | null
avg_visibility_m: number | null
avg_wind_direction_deg: number | null
avg_wind_gust_direction_deg: number | null
avg_wind_gust_speed_kmh: number | null
avg_wind_speed_kmh: number | null
created_at: string
day_finished: boolean
id: number
measure_day: string
source_dwd_station_ids: string[] | null
sum_precipitation_mm_per_sqm: number | null
sum_sunshine_minutes: number | null
}
Insert: {
avg_cloud_cover_percentage?: number | null
avg_dew_point_celcius?: number | null
avg_pressure_msl?: number | null
avg_relative_humidity_percentage?: number | null
avg_temperature_celsius?: number | null
avg_visibility_m?: number | null
avg_wind_direction_deg?: number | null
avg_wind_gust_direction_deg?: number | null
avg_wind_gust_speed_kmh?: number | null
avg_wind_speed_kmh?: number | null
created_at?: string
day_finished?: boolean
id?: number
measure_day: string
source_dwd_station_ids?: string[] | null
sum_precipitation_mm_per_sqm?: number | null
sum_sunshine_minutes?: number | null
}
Update: {
avg_cloud_cover_percentage?: number | null
avg_dew_point_celcius?: number | null
avg_pressure_msl?: number | null
avg_relative_humidity_percentage?: number | null
avg_temperature_celsius?: number | null
avg_visibility_m?: number | null
avg_wind_direction_deg?: number | null
avg_wind_gust_direction_deg?: number | null
avg_wind_gust_speed_kmh?: number | null
avg_wind_speed_kmh?: number | null
created_at?: string
day_finished?: boolean
id?: number
measure_day?: string
source_dwd_station_ids?: string[] | null
sum_precipitation_mm_per_sqm?: number | null
sum_sunshine_minutes?: number | null
}
Relationships: []
}
profiles: {
Row: {
id: string
Expand Down Expand Up @@ -269,13 +371,57 @@ export type Database = {
[_ in never]: never
}
Functions: {
accumulated_weather_per_month: {
Args: {
limit_monts: number
}
Returns: {
measure_day: string
sum_precipitation_mm_per_sqm: number
avg_temperature_celsius: number
avg_pressure_msl: number
sum_sunshine_minutes: number
avg_wind_direction_deg: number
avg_wind_speed_kmh: number
avg_cloud_cover_percentage: number
avg_dew_point_celcius: number
avg_relative_humidity_percentage: number
avg_visibility_m: number
avg_wind_gust_direction_deg: number
avg_wind_gust_speed_kmh: number
}[]
}
calculate_avg_waterings_per_month: {
Args: Record<PropertyKey, never>
Returns: {
month: string
watering_count: number
avg_amount_per_watering: number
}[]
}
calculate_top_tree_species: {
Args: Record<PropertyKey, never>
Returns: {
gattung_deutsch: string
percentage: number
}[]
}
count_by_age: {
Args: {
start_year: number
end_year: number
}
Returns: number
}
get_user_data_for_id: {
Args: {
u_id: string
}
Returns: {
id: string
email: string
}[]
}
get_watered_and_adopted: {
Args: Record<PropertyKey, never>
Returns: {
Expand Down
6 changes: 6 additions & 0 deletions supabase/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALLOWED_ORIGIN=http://localhost:5173
SMTP_HOST=...
SMTP_USER=...
SMTP_PASSWORD=...
SMTP_FROM=...
SMTP_PORT=...
7 changes: 7 additions & 0 deletions supabase/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALLOWED_ORIGIN=http://localhost:5173
SMTP_HOST=host.docker.internal
SMTP_USER=""
SMTP_PASSWORD=""
SMTP_FROM=giessdenkiez@citylab-berlin.org
SMTP_PORT=1025
SMTP_SECURE=false
7 changes: 7 additions & 0 deletions supabase/functions/_shared/check-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const loadEnvVars = (vars: string[]) => {
const missingVars = vars.filter((v) => !Deno.env.get(v));
if (missingVars.length > 0) {
throw new Error(`Missing environment variables: ${missingVars.join(", ")}`);
}
return vars.map((v) => Deno.env.get(v));
};
Loading

0 comments on commit 5e6e908

Please sign in to comment.