From 613a41fc64868442ea38aa8ac7e7f47fa68188b3 Mon Sep 17 00:00:00 2001 From: Abyan Nawaz Date: Mon, 7 Oct 2024 20:46:16 -0400 Subject: [PATCH] Added README for tutorial on migrations as well as changed the .yml file for github actions --- .github/workflows/db-migrations.yml | 4 +- backend/supabase/README.md | 68 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 backend/supabase/README.md diff --git a/.github/workflows/db-migrations.yml b/.github/workflows/db-migrations.yml index ded15bb..6e280a6 100644 --- a/.github/workflows/db-migrations.yml +++ b/.github/workflows/db-migrations.yml @@ -20,7 +20,7 @@ jobs: with: version: latest - - run: supabase link --project-ref $SUPABASE_PROJECT_ID + - run: cd backend && supabase link --project-ref $SUPABASE_PROJECT_ID - run: supabase db push apply: @@ -39,4 +39,4 @@ jobs: terraform_wrapper: false - run: terraform init - - run: terraform apply -auto-approve -no-color \ No newline at end of file + - run: terraform apply -auto-approve -no-color diff --git a/backend/supabase/README.md b/backend/supabase/README.md new file mode 100644 index 0000000..842ac1e --- /dev/null +++ b/backend/supabase/README.md @@ -0,0 +1,68 @@ +# Supabase Migrations and Table Alterations Guide + +This guide will help you through the process of altering database tables using the Supabase Table Editor, managing migrations, and pushing changes. + +--- + +## Running the Database + +To work with the Supabase database, you can start the database using the following command: + +Start the Supabase DB: + +```bash +make db-run +``` +Then you want to link to the remote database we have setup: + +```bash +cd backend + +supabase link --project-ref nydgnuqtgjljprotsccz +``` +Enter in the password +```bash +NightlifeGenerateSpring +``` +If successful, you should see "Finished supabase link." + +--- + +# Alter the tables using Supabase Table Editor +### Open the [Table Editor](https://supabase.com/dashboard/project/nydgnuqtgjljprotsccz/editor): + +Use the interface to add, modify, or delete columns in your tables. + +Once you are done and all changes were successful and saved, you can go on to migrating the database. + +--- +# Create a new migration file + +```bash +supabase db diff --use-migra -f +``` +The name here should be what the change reflected. If you have changed a column in user_id, then name should be something like "alter_user_id_column". Keep the names the same in both placeholders. + +This should create a new file in the supabase/migrations folder. + +--- + +### What to do with the Migration: + +Review the migration file in the supabase/migrations folder to ensure it reflects the changes you made in the Table Editor. + +--- + +# Push the migration to the database + +To run the migrations manually (safer option), you can do the following: + +```bash +supabase db push +``` + +There are github actions set up to run the migrations on the database. Once your PR is merged into main, the migrations +should be automatically pushed/ran. You must add and commit the migration file to your PR. + + +After we have done some migrations manually, we can look into the github actions to automatically push the migrations, this is more useful once we have a testing environment and production environment.