Skip to content

Commit

Permalink
Updated setup to allow more customization, remove database.dev (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiniscule authored Apr 14, 2024
1 parent ff82ab0 commit 6e8af0a
Show file tree
Hide file tree
Showing 56 changed files with 1,654 additions and 4,325 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/dbdev.yml

This file was deleted.

52 changes: 52 additions & 0 deletions .github/workflows/setup-testing.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
create extension pgtap with schema extensions;

/*---------------------
---- install dbdev ----
----------------------
Requires:
- pg_tle: https://github.com/aws/pg_tle
- pgsql-http: https://github.com/pramsey/pgsql-http
*/
create extension if not exists http with schema extensions;
create extension if not exists pg_tle;
drop extension if exists "supabase-dbdev";
select pgtle.uninstall_extension_if_exists('supabase-dbdev');
select
pgtle.install_extension(
'supabase-dbdev',
resp.contents ->> 'version',
'PostgreSQL package manager',
resp.contents ->> 'sql'
)
from http(
(
'GET',
'https://api.database.dev/rest/v1/'
|| 'package_versions?select=sql,version'
|| '&package_name=eq.supabase-dbdev'
|| '&order=version.desc'
|| '&limit=1',
array[
(
'apiKey',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJp'
|| 'c3MiOiJzdXBhYmFzZSIsInJlZiI6InhtdXB0cHBsZnZpaWZyY'
|| 'ndtbXR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2ODAxMDczNzI'
|| 'sImV4cCI6MTk5NTY4MzM3Mn0.z2CN0mvO2No8wSi46Gw59DFGCTJ'
|| 'rzM0AQKsu_5k134s'
)::http_header
],
null,
null
)
) x,
lateral (
select
((row_to_json(x) -> 'content') #>> '{}')::json -> 0
) resp(contents);
create extension "supabase-dbdev";
select dbdev.install('supabase-dbdev');
drop extension if exists "supabase-dbdev";
create extension "supabase-dbdev";

select dbdev.install('basejump-supabase_test_helpers');
83 changes: 4 additions & 79 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,95 +3,20 @@ on:
pull_request:
branches: [ main ]
jobs:
dbdev:
uses: ./.github/workflows/dbdev.yml
pg_tap_tests:
name: PGTap Tests
runs-on: ubuntu-latest
needs: dbdev
steps:
- name: Download DBDev
uses: actions/download-artifact@master
with:
name: dbdev-output
path: ~/.cargo/bin
- name: Make dbdev executable
run: chmod +x ~/.cargo/bin/dbdev
- uses: actions/checkout@v3
- uses: supabase/setup-cli@v1
with:
version: latest
- name: Supabase Start
run: supabase init && supabase start
- name: Install core extension using dbdev cli
run: supabase start
- name: Setup supabase testing
run: |
~/.cargo/bin/dbdev install --connection postgres://postgres:postgres@localhost:54322/postgres --path .
psql -v ON_ERROR_STOP=1 -U postgres -d postgres -h localhost -p 54322 -c 'CREATE EXTENSION IF NOT EXISTS basejump_core with schema extensions;'
psql -v ON_ERROR_STOP=1 -U postgres -d postgres -h localhost -p 54322 -f .github/workflows/setup-testing.sql
env:
PGPASSWORD: postgres
- name: Run Tests
run: supabase test db
stripe_tests:
name: Stripe Tests
runs-on: ubuntu-latest
needs: dbdev
steps:
- name: Download DBDev
uses: actions/download-artifact@master
with:
name: dbdev-output
path: ~/.cargo/bin
- name: Make dbdev executable
run: chmod +x ~/.cargo/bin/dbdev
- uses: actions/checkout@v3
- uses: supabase/setup-cli@v1
with:
version: latest
- name: Install stripe
run: |
# Download linux version as per Stripe documentation
curl -L https://github.com/stripe/stripe-cli/releases/download/v1.18.0/stripe_1.18.0_linux_x86_64.tar.gz --output stripe.tar.gz
# Unzip
tar -xvf stripe.tar.gz
- name: Create supabase/functions/.env including stripe webhook secrets
run: |
echo "STRIPE_WEBHOOK_SIGNING_SECRET=$(./stripe listen --print-secret)" >> supabase/functions/.env
echo "STRIPE_API_KEY=${{ secrets.STRIPE_API_KEY }}" >> supabase/functions/.env
echo "STRIPE_DEFAULT_PLAN_ID=${{ secrets.STRIPE_DEFAULT_PLAN_ID }}" >> supabase/functions/.env
echo "STRIPE_DEFAULT_TRIAL_DAYS=7" >> supabase/functions/.env
env:
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
STRIPE_DEFAULT_PLAN_ID: ${{ secrets.STRIPE_DEFAULT_PLAN_ID }}
- name: Setup and start Supabase
run: |
supabase init
echo -e "\n\n[functions.test-stripe-billing-webhooks]\nverify_jwt = false" >> supabase/config.toml
supabase start
- name: Install core extension using dbdev cli
run: |
~/.cargo/bin/dbdev install --connection postgres://postgres:postgres@localhost:54322/postgres --path .
psql -v ON_ERROR_STOP=1 -U postgres -d postgres -h localhost -p 54322 -c 'CREATE EXTENSION IF NOT EXISTS basejump_core with schema extensions;'
env:
PGPASSWORD: postgres
- name: Yarn install supabase/tests/integration
run: cd supabase/tests/integration && yarn --frozen-lockfile
- name: Install playwright browsers
run: cd supabase/tests/integration && yarn test:setup
- name: Run tests without webhooks
run: cd supabase/tests/integration && yarn test:invalid && yarn test:stripe-no-webhooks
env:
SUPABASE_URL: http://127.0.0.1:54321
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
STRIPE_DEFAULT_PLAN_ID: ${{ secrets.STRIPE_DEFAULT_PLAN_ID }}
STRIPE_DEFAULT_TRIAL_DAYS: 7
- name: Run tests with webhooks
run: |
./stripe listen --api-key ${{ secrets.STRIPE_API_KEY }} --forward-to http://127.0.0.1:54321/functions/v1/test-stripe-billing-webhooks &
cd supabase/tests/integration && yarn test:stripe-webhooks
env:
SUPABASE_URL: http://127.0.0.1:54321
SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
STRIPE_API_KEY: ${{ secrets.STRIPE_API_KEY }}
STRIPE_DEFAULT_PLAN_ID: ${{ secrets.STRIPE_DEFAULT_PLAN_ID }}
STRIPE_DEFAULT_TRIAL_DAYS: 7
run: supabase test db
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2022 usebasejump.com
Copyright 2024 usebasejump.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
43 changes: 19 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# Basejump

> If you're looking for the original Basejump which included a NextJS SaaS starter
> template, [check out the legacy repo](https://github.com/usebasejump/legacy-basejump-template).
Basejump adds personal accounts, team accounts, permissions and billing support to Supabase Auth.

[Learn more at usebasejump.com](https://usebasejump.com).
[Learn more at usebasejump.com](https://usebasejump.com). Ask questions [on X / Twitter](https://twitter.com/tiniscule)

## Features

Expand All @@ -26,36 +23,34 @@ Basejump adds personal accounts, team accounts, permissions and billing support

Check out the getting started guide at [usebasejump.com](https://usebasejump.com).

## Contributing

Yes please! Here's how you can get started locally
## Running tests
Basejump includes comprehensive pgtap testing for all included functionality - but it's not enabled by default in case that's not your jam. To run the tests, you'll need to add a few dependencies.

#### Initialize Supabase
#### Install pgtap

```bash
supabase init && supabase start
```sql
create extension pgtap with schema extensions;
```

#### Install local version of basejump_core

```bash
dbdev install --connection postgres://postgres:postgres@localhost:54322/postgres --path .
```
#### Install dbdev
Follow the directions at [database.dev](https://database.dev/supabase/dbdev) to install dbdev.

#### Enable basejump_core
#### Install supabase_test_helpers

```sql
CREATE EXTENSION IF NOT EXISTS basejump_core;
select dbdev.install('basejump-supabase_test_helpers');
```

#### Make sure tests can run

#### Run the tests
```bash
supabase test db
supabase test db
```

### Add your changes and write tests.

Make sure you're following the database.dev upgrade guidelines. you should NEVER be updating/changing existing version
files. All changes should have valid migration files for postgres extensions. I'll try to flesh this section out more
later.
## Contributing

Yes please! Please submit a PR with your changes to [the basejump github repo](https://github.com/usebasejump/basejump). Please make sure your changes are well tested and documented.

You can contribute in the following places:
- [Basejump core](https://github.com/usebasejump/basejump)
- [Basejump edge functions / billing functions](https://github.com/usebasejump/basejump-deno-packages)
Loading

0 comments on commit 6e8af0a

Please sign in to comment.