Skip to content

Commit

Permalink
conf: added deploy githubaction to supabase. Added package.json scrip…
Browse files Browse the repository at this point in the history
…t to init remote supabase. Moved db creation script to migration. Updated supabase conf to match remote one. Improved db creation migration to handle pre-existing web_anon role.
  • Loading branch information
Julien MAIRE authored and Julien MAIRE committed Jan 31, 2025
1 parent e8a7f1e commit 4e1efd9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 41 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Deploy to EC2

on:
push:
branches:
- "**"

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

#Deploy supabase
- name: Run Docker Compose
run: |
npm run supabase:remote:init
#Populate db
- name: Populate DB
env:
SUPABASE_DB_URL: ${{ secrets.SUPABASE_DB_URL }}
run: |
npx tsx tools/populateDbWithFakeData.ts
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"type-check": "tsc --noEmit",
"lint": "eslint --fix --ext .js,.jsx,.ts,.tsx ./src",
"format": "prettier --write ./src",
"clear": "rm -rf node_modules"
"clear": "rm -rf node_modules",
"supabase:remote:init": "yes | npx supabase db reset --linked && yes | npx supabase db push --include-all"
},
"dependencies": {
"@emotion/react": "^11.14.0",
Expand Down
33 changes: 0 additions & 33 deletions scripts/create_model.sql

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/drop_db.sql

This file was deleted.

11 changes: 11 additions & 0 deletions scripts/reset.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity
WHERE pg_stat_activity.datname = current_database() AND pid <> pg_backend_pid();
DO $$
DECLARE
r RECORD;
BEGIN
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = 'public')
LOOP
EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
END LOOP;
END $$;
6 changes: 3 additions & 3 deletions supabase/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ enable_confirmations = false
# If enabled, users will need to reauthenticate or have logged in recently to change their password.
secure_password_change = false
# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email.
max_frequency = "1s"
max_frequency = "1m0s"
# Number of characters used in the email OTP.
otp_length = 6
# Number of seconds before the email OTP expires (defaults to 1 hour).
Expand Down Expand Up @@ -192,8 +192,8 @@ max_enrolled_factors = 10

# Control MFA via App Authenticator (TOTP)
[auth.mfa.totp]
enroll_enabled = false
verify_enabled = false
enroll_enabled = true
verify_enabled = true

# Configure MFA via Phone Messaging
[auth.mfa.phone]
Expand Down
8 changes: 7 additions & 1 deletion supabase/migrations/20240130152000_create_model.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
CREATE ROLE web_anon NOLOGIN;
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'web_anon') THEN
CREATE ROLE web_anon;
END IF;
END $$;

GRANT USAGE ON SCHEMA public TO web_anon;

ALTER DEFAULT PRIVILEGES IN SCHEMA public
Expand Down

0 comments on commit 4e1efd9

Please sign in to comment.