Skip to content

Commit 8661af2

Browse files
authored
Finish Remix migration (#77)
1 parent 1d3284d commit 8661af2

File tree

86 files changed

+1935
-6036
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1935
-6036
lines changed

.github/workflows/branch-created.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Branch - Created
2+
3+
on: create
4+
5+
jobs:
6+
create-planetscale-db-branch-and-vercel-branch-env:
7+
name: Create PlanetScale DB branch and set DATABASE_URL env for Vercel branch
8+
runs-on: ubuntu-latest
9+
env:
10+
PLANETSCALE_SERVICE_TOKEN_NAME: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }}
11+
PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}
12+
defaults:
13+
run:
14+
working-directory: remix
15+
steps:
16+
- name: Check out code
17+
uses: actions/checkout@v2
18+
19+
- name: Set branch name as env variable
20+
uses: nelonoel/[email protected]
21+
22+
- name: Set up pscale CLI
23+
run: |
24+
wget https://github.com/planetscale/cli/releases/download/v0.91.0/pscale_0.91.0_linux_amd64.deb
25+
sudo dpkg -i pscale_0.91.0_linux_amd64.deb
26+
27+
- name: Create pscale DB branch
28+
run: |
29+
pscale branch create trad_archive ${BRANCH_NAME} --org tradarchive --region us-east --from master
30+
31+
- name: Create connection info for this DB branch
32+
id: create-password
33+
run: |
34+
JSON=$(pscale password create trad_archive ${BRANCH_NAME} ${{ github.sha }} --org tradarchive -f json)
35+
echo "::set-output name=dbHost::$(echo "${JSON}" | jq '.database_branch.access_host_url')"
36+
echo "::set-output name=dbUsername::$(echo "${JSON}" | jq '.id')"
37+
echo "::set-output name=dbPassword::$(echo "${JSON}" | jq '.plain_text')"
38+
39+
- name: Set DB branch password as env variable on Vercel for this branch
40+
run: |
41+
touch .env.preview
42+
echo "mysql://${{ steps.create-password.outputs.dbUsername }}:${{ steps.create-password.outputs.dbPassword }}@${{ steps.create-password.outputs.dbHost }}/trad_archive?sslaccept=strict" > .env.preview
43+
vercel env add DATABASE_URL preview ${BRANCH_NAME} < .env.preview --token ${{ secrets.VERCEL_SERVICE_TOKEN }}

.github/workflows/branch-deleted.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Branch - Deleted
2+
3+
on: delete
4+
5+
jobs:
6+
clean-up-planetscale-branch-and-ssm-envs:
7+
name: Delete PlanetScale DB branch
8+
if: github.event.ref_type == 'branch'
9+
runs-on: ubuntu-latest
10+
env:
11+
PLANETSCALE_SERVICE_TOKEN_NAME: ${{ secrets.PLANETSCALE_SERVICE_TOKEN_NAME }}
12+
PLANETSCALE_SERVICE_TOKEN: ${{ secrets.PLANETSCALE_SERVICE_TOKEN }}
13+
defaults:
14+
run:
15+
working-directory: remix
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v2
19+
20+
- name: Set BRANCH_NAME as env variable
21+
run: |
22+
echo "BRANCH_NAME=$(echo ${{ github.event.ref }} | sed -e "s#refs/heads/##g")" >> $GITHUB_ENV
23+
24+
- name: Set up pscale CLI
25+
run: |
26+
wget https://github.com/planetscale/cli/releases/download/v0.88.0/pscale_0.88.0_linux_amd64.deb
27+
sudo dpkg -i pscale_0.88.0_linux_amd64.deb
28+
29+
- name: Delete pscale DB branch
30+
run: |
31+
echo "Deleting pscale DB branch ${{ env.BRANCH_NAME }}..."
32+
pscale branch delete trad_archive ${{ env.BRANCH_NAME }} --org tradarchive --force
33+
34+
- name: Delete Vercel preview env variable
35+
run: |
36+
vercel env rm DATABASE_URL preview ${{ env.BRANCH_NAME }} --token ${{ secrets.VERCEL_SERVICE_TOKEN }} -y

.github/workflows/pr-opened.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
defaults:
1212
run:
13-
working-directory: api
13+
working-directory: remix
1414
steps:
1515
- name: Check out code
1616
uses: actions/checkout@v2
@@ -37,9 +37,9 @@ jobs:
3737
const commentBody = `\
3838
PlanetScale deploy request created for this DB branch! View it at https://app.planetscale.com/tradarchive/trad_archive/deploy-requests.
3939
40-
**The deploy request must be MANUALLY DEPLOYED before merging this PR.**
40+
⚠️ **The deploy request must be MANUALLY DEPLOYED _before_ merging this PR.**
4141
42-
Try the preview app at https://trad-archive-git-${{ github.head_ref }}-dangurney.vercel.app
42+
Try the preview app at https://trad-archive-remix-git-${{ github.head_ref }}-dangurney.vercel.app
4343
`;
4444
4545
await github.rest.issues.createComment({

.github/workflows/pr-updated.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
defaults:
1212
run:
13-
working-directory: api
13+
working-directory: remix
1414
steps:
1515
- name: Check out this branch's code
1616
uses: actions/checkout@v2
@@ -20,10 +20,10 @@ jobs:
2020
- name: Fetch master branch so we can diff against it
2121
run: git fetch origin master
2222

23-
- name: Check if models directory has changed relative to master branch
24-
id: diff-models
23+
- name: Check if schema.prisma file has changed relative to master branch
24+
id: diff-schema
2525
run: |
26-
echo "::set-output name=diff::$(git diff origin/master src/models)"
26+
echo "::set-output name=diff::$(git diff origin/master prisma/schema.prisma)"
2727
2828
- name: Add "db schema" label if so; remove if not
2929
uses: actions/github-script@v5
@@ -32,7 +32,7 @@ jobs:
3232
const { repo: { owner, repo }, payload } = context;
3333
const { pull_request } = payload;
3434
35-
const diff = "${{ steps.diff-models.outputs.diff }}"
35+
const diff = "${{ steps.diff-schema.outputs.diff }}"
3636
3737
if (diff) {
3838
await github.rest.issues.addLabels({

README.md

+25-46
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,18 @@ This is an open source experiment in collaboration with the Irish Traditional Mu
1313
With this project, community members can...
1414

1515
- Listen to previously unreleased archival recordings
16-
- Help by tagging each recording with People, Places, Tunes, Instruments, and Collections
16+
- Help by tagging each recording with People, Tunes, Instruments, and Collections
1717
- Save favorites to listen later
1818

1919
## Local Setup
2020

2121
### Dependencies
2222

23-
- [Node 14.x](https://nodejs.org/en/)
23+
- [Node 16.10 or above](https://nodejs.org/en/)
2424
- Recommended to install and manage via [nvm](https://github.com/nvm-sh/nvm#installing-and-updating)
2525
- [yarn](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable)
2626
- [PlanetScale CLI](https://github.com/planetscale/cli#installation)
2727
- Version 0.91 or above
28-
- [mysql CLI](https://dev.mysql.com/doc/refman/8.0/en/mysql.html)
29-
- Instructions for Mac users [here](https://stackoverflow.com/a/55692783/7426333)
3028

3129
### Database
3230

@@ -35,64 +33,45 @@ With this project, community members can...
3533
- Run local MYSQL instance
3634

3735
- For Mac, try [DBngin](https://dbngin.com/) for an easy way to get started
38-
- Initialize your DB schema by running
36+
- Initialize your DB:
3937

4038
```sh
41-
# Switch to API directory
42-
> cd api
39+
# Switch to remix directory
40+
> cd remix
4341

44-
# Take the schema in `src/seed/init-db-schema.sql` and apply it to your local database
45-
> make init-local-db-schema
46-
```
42+
# Make sure all dependencies are installed
43+
> yarn install --frozen-lockfile
44+
45+
# Take the schema in `prisma/schema.prisma` and apply it to your local DB
46+
> npx prisma db push
47+
48+
# Seed the database with some sample data
49+
> npx prisma db seed
4750

48-
- If you already have a local MYSQL instance but the schema is out of date, you can run the same command above and it will refresh your schema. Note that any local data you had will be deleted.
51+
# Open a browser tab to view DB data
52+
> npx prisma studio
53+
54+
# If you want to completely reset your DB and wipe all the data
55+
> npx prisma migrate reset
56+
```
4957

5058
- Expose PlanetScale DB branch locally
5159
- This project uses a service called [PlanetScale](https://planetscale.com/) which applies the Git branching model to databases.
5260
- There is a `master` DB branch which always contains the most up-to-date production schema and can only be updated by a "deploy request" (essentially a pull request).
5361
- When you create a new Git branch and push it up to GitHub, CI/CD will automatically create a matching PlanetScale branch of the same name.
54-
- You can then expose that branch locally by running `cd api && make pscale-db`, and connect to it as if it were a local MYSQL DB.
62+
- You can then expose that branch locally by running `pscale connect trad_archive [your-branch-name]`, and connect to it like a local MYSQL DB.
5563

56-
### API
64+
### Run the App
5765

5866
```sh
59-
# Switch to api directory
60-
> cd api
67+
# Go to remix directory
68+
> cd remix
6169
6270
# Install dependencies
6371
> yarn install --frozen-lockfile
6472
65-
# Run the API via Serverless Offline, similar to how it runs in production
66-
> make api
67-
68-
# Or, run the API via Express which is faster locally
69-
> make api-express
70-
```
71-
72-
### Web
73-
74-
```sh
75-
# Switch to web directory
76-
> cd web
77-
78-
# Install dependencies
79-
> yarn install --frozen-lockfile
80-
81-
# Serve the website at http://localhost:3000
73+
# Start the dev server
8274
> yarn dev
83-
```
84-
85-
### Updating DB Schema
86-
87-
```sh
88-
# Switch to api directory
89-
cd api
90-
91-
# Add the SQL commands you'd like to run in `src/migration.sql`
92-
...
93-
ALTER TABLE user ADD COLUMN test varchar(255);
94-
...
9575
96-
# Apply the migration simultaneously to your local MYSQL DB and the PlanetScale DB branch. If the migration succeeds, it will then update `src/seed/init-db-schema.sql` with the new schema.
97-
> make migrate
76+
# Visit the app at http://localhost:3000
9877
```

api/serverless.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ custom:
7272
prod: https://www.tradarchive.com
7373
shouldRunImportItmaAtomCollections:
7474
dev: false
75-
preview: true
76-
prod: true
75+
preview: false
76+
prod: false
7777
shouldRunImportTunes:
7878
dev: false
79-
preview: true
80-
prod: true
79+
preview: false
80+
prod: false
8181
shouldRunKeepWarm:
8282
dev: false
83-
preview: true
84-
prod: true
83+
preview: false
84+
prod: false
8585
webpack:
8686
webpackConfig: "webpack.config.js"
8787
includeModules:

remix/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ node_modules
55
/functions/\[\[path\]\].js.map
66
/public/build
77
.env
8-
.vercel
8+
.vercel

0 commit comments

Comments
 (0)