From 542e7bf15a87d6db56497642636c47060d39f838 Mon Sep 17 00:00:00 2001 From: Kubernetes87 <94650596+Kubernetes87@users.noreply.github.com> Date: Wed, 20 May 2026 00:54:43 -0500 Subject: [PATCH 1/4] Add workflow for creating and deleting Neon branches --- .github/workflows/neon_workflow.yml | 97 +++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 .github/workflows/neon_workflow.yml diff --git a/.github/workflows/neon_workflow.yml b/.github/workflows/neon_workflow.yml new file mode 100644 index 0000000..d542f8e --- /dev/null +++ b/.github/workflows/neon_workflow.yml @@ -0,0 +1,97 @@ +name: Create/Delete Branch for Pull Request + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - closed + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + setup: + name: Setup + outputs: + branch: ${{ steps.branch_name.outputs.current_branch }} + runs-on: ubuntu-latest + steps: + - name: Get branch name + id: branch_name + uses: tj-actions/branch-names@v8 + + create_neon_branch: + name: Create Neon Branch + outputs: + db_url: ${{ steps.create_neon_branch_encode.outputs.db_url }} + db_url_with_pooler: ${{ steps.create_neon_branch_encode.outputs.db_url_with_pooler }} + needs: setup + if: | + github.event_name == 'pull_request' && ( + github.event.action == 'synchronize' + || github.event.action == 'opened' + || github.event.action == 'reopened') + runs-on: ubuntu-latest + steps: + - name: Get branch expiration date as an env variable (2 weeks from now) + id: get_expiration_date + run: echo "EXPIRES_AT=$(date -u --date '+14 days' +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_ENV" + - name: Create Neon Branch + id: create_neon_branch + uses: neondatabase/create-branch-action@v6 + with: + project_id: ${{ vars.NEON_PROJECT_ID }} + branch_name: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} + api_key: ${{ secrets.NEON_API_KEY }} + expires_at: ${{ env.EXPIRES_AT }} + +# The step above creates a new Neon branch. +# You may want to do something with the new branch, such as run migrations, run tests +# on it, or send the connection details to a hosting platform environment. +# The branch DATABASE_URL is available to you via: +# "${{ steps.create_neon_branch.outputs.db_url_with_pooler }}". +# It's important you don't log the DATABASE_URL as output as it contains a username and +# password for your database. +# For example, you can uncomment the lines below to run a database migration command: +# - name: Run Migrations +# run: npm run db:migrate +# env: +# # to use pooled connection +# DATABASE_URL: "${{ steps.create_neon_branch.outputs.db_url_with_pooler }}" +# # OR to use unpooled connection +# # DATABASE_URL: "${{ steps.create_neon_branch.outputs.db_url }}" + +# Following the step above, which runs database migrations, you may want to check +# for schema changes in your database. We recommend using the following action to +# post a comment to your pull request with the schema diff. For this action to work, +# you also need to give permissions to the workflow job to be able to post comments +# and read your repository contents. Add the following permissions to the workflow job: +# +# permissions: +# contents: read +# pull-requests: write +# +# You can also check out https://github.com/neondatabase/schema-diff-action for more +# information on how to use the schema diff action. +# You can uncomment the lines below to enable the schema diff action. +# - name: Post Schema Diff Comment to PR +# uses: neondatabase/schema-diff-action@v1 +# with: +# project_id: ${{ vars.NEON_PROJECT_ID }} +# compare_branch: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} +# api_key: ${{ secrets.NEON_API_KEY }} + + delete_neon_branch: + name: Delete Neon Branch + needs: setup + if: github.event_name == 'pull_request' && github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - name: Delete Neon Branch + uses: neondatabase/delete-branch-action@v3 + with: + project_id: ${{ vars.NEON_PROJECT_ID }} + branch: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} + api_key: ${{ secrets.NEON_API_KEY }} From f952167844a4321c37e676c7d02aa5c04ef9f249 Mon Sep 17 00:00:00 2001 From: Kubernetes87 <94650596+Kubernetes87@users.noreply.github.com> Date: Wed, 20 May 2026 01:05:04 -0500 Subject: [PATCH 2/4] Add step to run database migrations in workflow --- .github/workflows/neon_workflow.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/neon_workflow.yml b/.github/workflows/neon_workflow.yml index d542f8e..c29e475 100644 --- a/.github/workflows/neon_workflow.yml +++ b/.github/workflows/neon_workflow.yml @@ -82,7 +82,12 @@ jobs: # project_id: ${{ vars.NEON_PROJECT_ID }} # compare_branch: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} # api_key: ${{ secrets.NEON_API_KEY }} - +Run_Migrations: + name: Run Migrations + run: npm run db:migrate + env: + DATABASE_URL: "${{ steps.create_neon_branch.outputs.db_url_with_pooler }}" + delete_neon_branch: name: Delete Neon Branch needs: setup From 1a978c37572dc3932178f05706af8db2de300b9e Mon Sep 17 00:00:00 2001 From: Kubernetes87 <94650596+Kubernetes87@users.noreply.github.com> Date: Wed, 20 May 2026 01:38:27 -0500 Subject: [PATCH 3/4] Add GitHub Actions workflow for Neon branch management --- .github/workflows/neon_workflow_new.yml | 72 +++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 .github/workflows/neon_workflow_new.yml diff --git a/.github/workflows/neon_workflow_new.yml b/.github/workflows/neon_workflow_new.yml new file mode 100644 index 0000000..b5466c9 --- /dev/null +++ b/.github/workflows/neon_workflow_new.yml @@ -0,0 +1,72 @@ +name: Create/Delete Branch for Pull Request + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - closed + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + setup: + name: Setup + outputs: + branch: ${{ steps.branch_name.outputs.current_branch }} + runs-on: ubuntu-latest + steps: + - name: Get branch name + id: branch_name + uses: tj-actions/branch-names@v8 + + create_neon_branch: + name: Create Neon Branch + needs: setup + if: | + github.event_name == 'pull_request' && ( + github.event.action == 'synchronize' || + github.event.action == 'opened' || + github.event.action == 'reopened') + runs-on: ubuntu-latest + outputs: + db_url: ${{ steps.create_neon_branch.outputs.db_url }} + db_url_with_pooler: ${{ steps.create_neon_branch.outputs.db_url_with_pooler }} + steps: + - name: Get branch expiration date (2 weeks from now) + id: get_expiration_date + run: echo "EXPIRES_AT=$(date -u --date '+14 days' +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_ENV" + + - name: Create Neon Branch + id: create_neon_branch + uses: neondatabase/create-branch-action@v6 + with: + project_id: ${{ vars.NEON_PROJECT_ID }} + branch_name: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} + api_key: ${{ secrets.NEON_API_KEY }} + expires_at: ${{ env.EXPIRES_AT }} + + Run_Migrations: + name: Run Migrations + needs: create_neon_branch + runs-on: ubuntu-latest + steps: + - name: Run Migrations + run: npm run db:migrate + env: + DATABASE_URL: "${{ needs.create_neon_branch.outputs.db_url_with_pooler }}" + + delete_neon_branch: + name: Delete Neon Branch + needs: setup + if: github.event_name == 'pull_request' && github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - name: Delete Neon Branch + uses: neondatabase/delete-branch-action@v3 + with: + project_id: ${{ vars.NEON_PROJECT_ID }} + branch: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} + api_key: ${{ secrets.NEON_API_KEY }} From 9e3b1ff2b0fd31a52017c4e68ffdfb7101e40ae0 Mon Sep 17 00:00:00 2001 From: Kubernetes87 <94650596+Kubernetes87@users.noreply.github.com> Date: Wed, 20 May 2026 01:50:37 -0500 Subject: [PATCH 4/4] Add Run Migrations step in neon_workflow Added a new step to run database migrations after creating a Neon branch. --- .github/workflows/neon_workflow.yml | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/neon_workflow.yml b/.github/workflows/neon_workflow.yml index c29e475..bc98d1f 100644 --- a/.github/workflows/neon_workflow.yml +++ b/.github/workflows/neon_workflow.yml @@ -25,8 +25,8 @@ jobs: create_neon_branch: name: Create Neon Branch outputs: - db_url: ${{ steps.create_neon_branch_encode.outputs.db_url }} - db_url_with_pooler: ${{ steps.create_neon_branch_encode.outputs.db_url_with_pooler }} + db_url: ${{ steps.create_neon_branch.outputs.db_url }} + db_url_with_pooler: ${{ steps.create_neon_branch.outputs.db_url_with_pooler }} needs: setup if: | github.event_name == 'pull_request' && ( @@ -46,6 +46,18 @@ jobs: branch_name: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} api_key: ${{ secrets.NEON_API_KEY }} expires_at: ${{ env.EXPIRES_AT }} + Run_Migrations: + name: Run Migrations + needs: create_neon_branch + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run Migrations + run: npm run db:migrate + env: + DATABASE_URL: "${{ needs.create_neon_branch.outputs.db_url_with_pooler }}" # The step above creates a new Neon branch. # You may want to do something with the new branch, such as run migrations, run tests @@ -82,12 +94,7 @@ jobs: # project_id: ${{ vars.NEON_PROJECT_ID }} # compare_branch: preview/pr-${{ github.event.number }}-${{ needs.setup.outputs.branch }} # api_key: ${{ secrets.NEON_API_KEY }} -Run_Migrations: - name: Run Migrations - run: npm run db:migrate - env: - DATABASE_URL: "${{ steps.create_neon_branch.outputs.db_url_with_pooler }}" - + delete_neon_branch: name: Delete Neon Branch needs: setup