Skip to content

Instantly share code, notes, and snippets.

@vqc1909a
Last active December 29, 2025 23:06
Show Gist options
  • Select an option

  • Save vqc1909a/176b380561bc14689eaa76360713a34c to your computer and use it in GitHub Desktop.

Select an option

Save vqc1909a/176b380561bc14689eaa76360713a34c to your computer and use it in GitHub Desktop.
SUPABASE_CLI

The Supabase CLI is a powerful tool that enables developers to manage their Supabase projects directly from the terminal. It provides a suite of commands for various tasks, including:

  • Setting up and managing local development environments
  • Generating TypeScript types for your database schema
  • Handling database migrations
  • Managing environment variables and secrets
  • Deploying your project to the Supabase platform

With the CLI, you can streamline your development workflow, automate repetitive tasks, and maintain consistency across different environments. It's an essential tool for both local development and CI/CD pipelines.

General Commands

image

The Supabase CLI enables you to run the entire Supabase stack locally, on your machine or in a CI environment. With just two commands, you can set up and start a new local project:

supabase init //to create a new local project
supabase start //to launch the Supabase services

What you CAN do with local Supabase: ✅ One local database instance ✅ Test schema changes ✅ Experiment with data ✅ Offline development ✅ Run migrations locally

What you CANNOT do: ❌ Create multiple Supabase projects locally ❌ Have multiple databases like separate projects ❌ Simulate production environment completely ❌ Test different Supabase configurations simultaneously Expected Results: image

Updating the Supabase CLI

  pnpx update supabase --save-dev

Stopping local services

  pnpx supabase stop

Watch the credentials of your database

  pnpx supabase status

Since the first time you get up your local supabase and begin doing some changes.

  • When you are of your first changes, you have to apply the following command especifying what you did as a message

      pnpx supabase db diff --schema public -f create_notes_table
      //or
      supabase db diff --schema public -f create_notes_table
  • Create supabase/seed.sql and export the data of all the tables that you created except the auth table image You'll have something like this in the supabase folder image

  • You have to execute the next command to reset and apply all the migrations and seed that you have within supabase folder

      pnpx supabase db reset
  • You have to login first

      pnpx supabase login
  • List your Supabase projects to find your project ID: image

      pnpx supabase projects list
  • You have to link your local project to the cloud project image

      pnpx supabase link --project-ref <project-id>
  • You have to pull any changes that you did in your cloud database first

      pnpx supabase db pull

    NOTE: If you have not made any changes to the remote database, skip this step

  • Reset local database completely with new migrations

      pnpx supabase db reset
  • Finally you have to push your changes

      pnpx supabase db push

    NOTE: If you want to verify if you have some changes in your local database, you have to apply the following

      pnpx supabase db diff --schema public

Get up a legacy local project from scratch where might be problems if you execute "pnpx supabase db pull" and you have to delete the supabase folder and begin from scratch

  • Removes all unused Docker data (containers, networks, images, and optionally volumes).

      docker system prune -af --volumes
  • Stop any existing local Supabase containers and clean up old data:

      pnpx supabase stop --no-backup
  • Delete the respective supabase folder and init one new

      sudo rm -rf supabase/
      //and
      pnpx supabase init
  • Pull schema

    When you run npx supabase db pull without specifying a schema, it pulls ALL schemas including:

    • public (your application tables)
    • auth (authentication tables)
    • storage (storage buckets and objects)
    • Any other custom schemas
      SUPABASE_DB_PASSWORD="FanIQ2025@1!" npx supabase db pull 

    NOTE: you have to init with npx supabase@beta for all the commands meanwhile fixing of the latest version supabase issue

  • Repair every migrations showned just after execution the previous command

      SUPABASE_DB_PASSWORD="FanIQ2025@1!" npx supabase migration repair --status reverted 20251106230721
  • Execute again the previous command

   SUPABASE_DB_PASSWORD="FanIQ2025@1!" npx supabase db pull
  • Finally if all is okey, start local supabase
      npx supabase stop && npx supabase start
  • Now Download all your edge functions Copy and Page the next file SCRIPT_DOWNLOAD_ALL_EDGE_FUNCTIONS within your project and execute the next command
      chmod +x download_all_functions.sh && ./download_all_functions.sh
image image image
  • Generate a new Edge Function with a basic template

      pnpx supabase functions new hello-world
  • Start the local development server to test your function (it's like node server.js)

      pnpx supabase functions serve hello-world
  • Start the local development server to test all the functions (it's like node server.js)

      pnpx supabase functions serve
  • Send a test request (You need to set up this in Postman or execute it directly in the CMD)

      curl -i --location --request POST 'http://localhost:54321/functions/v1/hello-world' \
      --header 'Authorization: Bearer SUPABASE_PUBLISHABLE_KEY' \
      --header 'Content-Type: application/json' \
      --data '{"name":"Functions"}'
  • Deploy your edge function

      pnpx supabase functions deploy hello-world
    
      # If you want to deploy all functions, run the `deploy` command without specifying a function name:
      pnpx supabase functions deploy

You can create your bucket in the local environment this way, only replace your-bucket with the bucket name that you can set up

  • First you have to create a folder within supabase where you have to save specific data related to the name of the folder image

  • Then you have to set up this configuration within config.tml to create your bucket in the local dashboard, make sure the path name is the same to the name of the folder

       [storage]
       enabled = true
       # The maximum file size allowed (e.g. "5MB", "500KB").
       # file_size_limit = "50MiB"
    
       # Image transformation API is available to Supabase Pro plan.
       # [storage.image_transformation]
       # enabled = true
    
       # Uncomment to configure local storage buckets
       [storage.buckets.avatars]
       public = true
       file_size_limit = "50MiB"
       allowed_mime_types = ["image/png", "image/jpeg"]
       objects_path = "./avatars" 
  • Then you have to apply the next command

      pnpx supabase db reset
  • And you will be able to watch the bucket in the supabase dashboard image

Commands to export data from cloud database to local database

Export only the data (not the schema) from the auth schema of your linked cloud Supabase project, using the beta version of the Supabase CLI.

  //(auth.users)
  npx supabase@beta db dump --data-only --schema auth --linked > supabase/seed/01_auth_users.sql
  //(all the tables)
  npx supabase@beta db dump --data-only --schema public --linked > supabase/seed/02_profiles_data.sql
  //(both tables)
  npx supabase@beta db dump --data-only --schema auth --schema public --linked > supabase/seed.sql
  //(your local database)
  npx supabase@beta db dump --data-only --schema public > supabase/seed/02_profiles_data.sql

Create another branch

  • You have to create other branch repository and upload
      git checkout -b feature/my-feature
      &&
      git push -u origin feature/my-feature
  • You have to create supabase branch and link to the branch repository created already image

Delete branch created locally and in GitHub

 # Delete the local Git branch
 git branch -d feature/branch-name

 # If the branch has unmerged changes, force delete:
 git branch -D feature/branch-name

 # Delete the remote branch on GitHub
 git push origin --delete feature/branch-name

Command to change the permission of any file or folder so that the current user can do the proper changes

 sudo chown -R $USER:$USER supabase/functions
 
 //Make uploads and outputs writable by all
 sudo chmod -R 777 /home/rosec/PROGRAMACION/FanIQ/video-converter-api

Make any script executable

 chmod +x scripts/setup-ssl.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment