Skip to content

Commit

Permalink
Merge pull request #5 from marmelab/features/supabase
Browse files Browse the repository at this point in the history
replace postgrest docker-compose with supabase
  • Loading branch information
slax57 authored Jan 31, 2025
2 parents b944fd0 + b681157 commit 248235a
Show file tree
Hide file tree
Showing 15 changed files with 1,636 additions and 188 deletions.
12 changes: 4 additions & 8 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# Configure your dev environment
DATABASE_PORT=<wanted postgres database port>
DATABASE_USER=<wanted postgres database username>
DATABASE_PASSWORD=<wanted postgres database password>

DATABASE_NAME=connect_four_reboot_admin
PGRST_DB_ANON_ROLE=web_anon
PGRST_DB_SCHEMA=public
## Please update those values if you modify the supabase default configuration
SUPABASE_DB_URL=postgresql://postgres:postgres@127.0.0.1:54322/postgres ## supabase default url
VITE_SUPABASE_URL= http://127.0.0.1:54321 ## supabase url for react admin dataprovider
VITE_SUPABASE_API_KEY= eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0 ## please put your supabase anon key
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy to prod

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
environment: production
permissions:
pages: write
id-token: write

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

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Install dependencies
run: npm install

- name: Build the app
env:
VITE_SUPABASE_URL: ${{ secrets.VITE_SUPABASE_API_URL }}
VITE_SUPABASE_ANON_KEY: ${{ secrets.VITE_SUPABASE_ANON_KEY }}
run: npm run build

- name: Link Supabase && init db && populate
env:
SUPABASE_PROJECT_REF: ${{ vars.SUPABASE_PROJECT_REF }}
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
SUPABASE_DB_URL: ${{ secrets.SUPABASE_DB_URL }}
run: |
npx supabase link --project-ref $SUPABASE_PROJECT_REF
npx tsx tools/populateDbWithFakeData.ts
- name: Upload to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: dist

- name: 🚀 Deploy to github pages
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: CI tests

on:
push:
Expand Down
60 changes: 9 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,32 @@
Connect-four-reboot game administration using:

- react-admin as a frontEnd typescript app
- postgrest inside a docker, as a standalone web server that turns a PostgreSQL database directly into a RESTful API.
- postgrest with Supabase, an opensource Firebase alternative.

To run connect-four-reboot-admin, you have to run the both components.

The postgrest docker-compose contains two dockers:

- postgres
- postgrest

## Run the connect-four-reboot-admin api (postrgrest)

Copy the .env.sample file to create your development environment file .env
You have to configure the port, the username and password for the postgrest configuration.

Then run:

```sh
make run-postgrest-docker
```

The docker start with an empty, ready to use, database.

You have to create the db tables runing:

```sh
make create-model
```

Next, you must generate fake data:

```sh
make populate-db
```

You can test the configuration runing:
First install the app with :

```sh
make connect-db
```

If necessary, for dev purpose you have the ability to drop and recreate the
database with:

```sh
make drop-db
make install
```

database with:
Then, copy the .env.sample file to create your development environment file .env.

```sh
make create-db
```

tips:
Now run:

```sh
make run
```

this goal do all for you.

## Installation connect-four-reboot-admin frontend
This command will start both components:

Install the react-admin application dependencies by running:
- Supbase with a populated, ready to use database
- react-admin front end vite server

```sh
make install
```
If you want go into details, you have several goals in the makefile related to supabase. Please see [the makefile](makefile).

## Development connect-four-reboot-admin frontend

Expand Down
39 changes: 0 additions & 39 deletions docker-compose.yml

This file was deleted.

41 changes: 14 additions & 27 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include .env
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'


## Install - react-admin
########################

Expand All @@ -24,43 +25,29 @@ run-ra-dev: ## run the react-admin server.
########

run: ## fresh run of all you need to use the app
make run-postgrest-docker && make create-model && make populate-db && make run-ra-dev
make start-supabase && make supabase-migrate-database && make run-ra-dev

stop: ## stop the docker
make stop-postgrest-docker

## Docker - postrgrest / postgres
#################################

run-postgrest-docker: ## run the postgrest docker-compose containing 2 dockers: postgres (db) & postgrest (api). The postgres docker start with a ready to use empty db.
docker-compose --env-file .env -f docker-compose.yml up --build -d
make stop-supabase

stop-postgrest-docker: ## stop the postgrest docker-compose
docker-compose --env-file .env -f docker-compose.yml down
## Supabase (postrgrest / postgres)
###################################

## Database
###########
start-supabase: ## start supabase locally
npx supabase start

connect-db: ## connect into the postres docker.
docker exec -it connect-four-reboot-admin-database-postgres-1 sh -c 'psql -U $(DATABASE_USER) -d $(DATABASE_NAME)'
stop-supabase: ## stop supabase locally
npx supabase stop

create-db: ## initialize an empty ready to use db inside the docker - use it only after drop.
docker exec -i connect-four-reboot-admin-database-postgres-1 sh -c 'psql -U $(DATABASE_USER) -c "CREATE DATABASE $(DATABASE_NAME);"'
supabase-migrate-database: ## apply the migrations to the database
npx supabase migration up

drop-db: ## drop the postgres db inside the docker.
docker exec -i connect-four-reboot-admin-database-postgres-1 sh -c \
'psql -U postgres -c "SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname = '\''connect_four_reboot_admin'\'';"' && docker exec -i connect-four-reboot-admin-database-postgres-1 sh -c 'psql -U $(DATABASE_USER) -c "DROP DATABASE IF EXISTS $(DATABASE_NAME);"'
supabase-reset-database: ## reset (and clear!) the database
npx supabase db reset

create-model: ## create the connect-four-reboot-admin tables.
docker exec connect-four-reboot-admin-database-postgres-1 sh -c 'psql -U $(DATABASE_USER) -d $(DATABASE_NAME) -f /scripts/create_model.sql'

populate-db: ## populate database with fake values
supabase-populate: ## populate database with fake values
npx tsx tools/populateDbWithFakeData.ts

reset-db:
make drop-db && make create-db && make create-model && make populate-db


## Dev quality
##############

Expand Down
Loading

0 comments on commit 248235a

Please sign in to comment.