{"id":40429171,"url":"https://github.com/neondatabase/preview-branches-with-fly","last_synced_at":"2026-01-20T16:01:15.007Z","repository":{"id":220295802,"uuid":"751214407","full_name":"neondatabase/preview-branches-with-fly","owner":"neondatabase","description":"A Neon branch for every Fly Preview app","archived":false,"fork":false,"pushed_at":"2025-12-17T11:20:16.000Z","size":182,"stargazers_count":22,"open_issues_count":7,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-01-19T18:23:41.489Z","etag":null,"topics":["drizzle-orm","fly","github-actions","postgres","postgresql","pr-preview"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neondatabase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-02-01T06:44:46.000Z","updated_at":"2026-01-15T01:57:13.000Z","dependencies_parsed_at":"2024-11-06T09:12:33.485Z","dependency_job_id":"40403c15-a42e-4e22-987e-92ac1c71c993","html_url":"https://github.com/neondatabase/preview-branches-with-fly","commit_stats":null,"previous_names":["neondatabase/preview-branches-with-fly","neondatabase-labs/preview-branches-with-fly"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/neondatabase/preview-branches-with-fly","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fpreview-branches-with-fly","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fpreview-branches-with-fly/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fpreview-branches-with-fly/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fpreview-branches-with-fly/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neondatabase","download_url":"https://codeload.github.com/neondatabase/preview-branches-with-fly/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neondatabase%2Fpreview-branches-with-fly/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28606287,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T14:45:23.139Z","status":"ssl_error","status_checked_at":"2026-01-20T14:44:16.929Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drizzle-orm","fly","github-actions","postgres","postgresql","pr-preview"],"created_at":"2026-01-20T16:00:35.628Z","updated_at":"2026-01-20T16:01:14.998Z","avatar_url":"https://github.com/neondatabase.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Preview branches with Fly.io and Neon\n\nThis is an example project that shows how you can create a branch for every [Fly.io](https://fly.io) preview deployment.\n\n## Tech Stack\n- DB: [Neon](https://neon.tech/)\n- Hosting: [Fly.io](https://fly.io)\n- App: [Fastify](https://fastify.dev/)\n- Node Package Management: [pnpm](https://pnpm.io/)\n- ORM: [Drizzle](https://orm.drizzle.team/)\n\n## Getting started\n\nYou can copy the files located at [`.github/workflows/`](./.github/workflows/) and add them to your own project. \n\nYou will then need to set the following secrets in your repository:\n\n- `FLY_API_TOKEN`: Your Fly.io API token, you can find it in your Fly.io account settings.\n- `NEON_API_KEY`: Your Neon API key, you can find it in your Neon account settings.\n- `DATABASE_URL`: The connection string for your production database. You can find it in your Neon project's connection details.\n- `GH_TOKEN`: A GitHub token with access to your repository, you can create one in your GitHub account settings. You will need to give it access to the `repo` scope so that the `deploy-preview` workflow can comment on the pull request. You can uncomment the step which uses this token in the `.github/workflows/deploy-preview.yml` workflow file.\n\nYou will then need to set the following variables:\n\n- `NEON_PROJECT_ID`: The ID of your Neon project, you can find it in your Neon project settings.\n\n## How it works\n\n### Preview deployment\n[`.github/workflows/deploy-preview.yml`](./.github/workflows/deploy-preview.yml) automates the deployment process to a preview environment.\n\nActivated on a `pull_request` event \n```yaml\non: [pull_request]\n```\n\nRequires the `NEON_API_KEY`, `NEON_PROJECT_ID`, `GH_TOKEN`, and `FLY_API_TOKEN` secrets that are set in the repository.\n\nThe workflow has a single job called `deploy-preview`\n```yaml\njobs:\n  deploy-preview:\n```\n \nIn that job it consists of the following steps:\n\n1. Ensures concurrency control, allowing only one deployment at a time per pull request.\n```yaml\n    concurrency:\n      group: pr-${{ github.event.number }}\n```\n\n1. Check out the codebase using [`actions/checkout@v4`](https://github.com/marketplace/actions/checkout).\n```yaml\n      - uses: actions/checkout@v4\n```\n1. Sets up PNPM with [`pnpm/action-setup@v2`](https://github.com/marketplace/actions/setup-pnpm). (You can use another package manager depending on your setup.)\n```yaml\n      - uses: pnpm/action-setup@v2\n        with:\n          version: 8\n```\n1. Configures Node.js version with caching for PNPM via `actions/setup-node@v4`.\n```yaml\n      - name: Use Node.js 18\n        uses: actions/setup-node@v4\n        with:\n          node-version: 18\n          cache: \"pnpm\"\n```\n1. Installs dependencies using `pnpm install`.\n```yaml\n      - name: Install dependencies\n        run: pnpm install\n```\n1. Retrieves and normalizes the branch name using [`tj-actions/branch-names@v8`](https://github.com/marketplace/actions/branch-names).\n```yaml\n      - name: Get branch name\n        id: branch-name\n        uses: tj-actions/branch-names@v8\n```\n1. Creates a Neon database branch for the pull request with [`neondatabase/create-branch-action@v5`](https://github.com/marketplace/actions/neon-database-create-branch-action). By default, the branch name will be `preview/\u003cgit-branch-name\u003e`\n```yaml\n      - name: Create Neon Branch\n        id: create-branch\n        uses: neondatabase/create-branch-action@v4\n        with:\n          project_id: ${{ env.NEON_PROJECT_ID }}\n          # parent: dev # optional (defaults to your primary branch)\n          branch_name: preview/${{ steps.branch-name.outputs.current_branch }}\n          username: \"neondb_owner\" # change this to your Neon database username if you're not using the default\n          api_key: ${{ env.NEON_API_KEY }}\n```\n1. Executes database migrations by setting up the `.env` file and running migration scripts.\n```\n      - run: |\n          echo \"DATABASE_URL=${{ steps.create-branch.outputs.db_url_with_pooler }}\" \u003e\u003e \"$GITHUB_ENV\"\n\n      - run: pnpm run db:migrate\n```\n1. Deploys the application with [`superfly/fly-pr-review-apps@1.2.1`](https://github.com/marketplace/actions/github-action-for-deplying-staging-apps-on-fly-io), while including the Neon database URL.\n```yaml\n      - name: Deploy\n        id: deploy\n        uses: superfly/fly-pr-review-apps@1.2.1\n        with:\n          secrets: DATABASE_URL=${{ steps.create-branch.outputs.db_url }}?sslmode=require\n```\n1.  Comments on the pull request with deployment and database branch details using `thollander/actions-comment-pull-request@v2`. Here's an [example comment](https://github.com/neondatabase/preview-branches-with-fly/pull/9#issuecomment-1924660371)\n```yaml\n      - name: Comment on Pull Request\n        uses: thollander/actions-comment-pull-request@v2\n        with:\n          # GITHUB_TOKEN: ${{ env.GH_TOKEN }} # Required for commenting on pull requests for private repos\n          message: |\n            Fly Preview URL :balloon: : ${{ steps.deploy.outputs.url }}\n            Neon branch :elephant: : https://console.neon.tech/app/projects/${{ secrets.NEON_PROJECT_ID }}/branches/${{ steps.create-branch.outputs.branch_id }}\n```\n\n### Production deployment\n\n[`.github/workflows/deploy-production.yml`](./.github/workflows/deploy-production.yml) automates the deployment process to a production environment. It is activated on a `push` event to the `main` branch and uses the `FLY_API_TOKEN` and `DATABASE_URL` secrets that are set in the repository.\n\nThe workflow has a single job called `production-deploy` and it consists of the following steps:\n1. Checks out the codebase using `actions/checkout@v4`\n2. Sets up PNPM using `pnpm/action-setup@v2` and specifies version 8. (You can use another package manager depending on your setup.)\n3. Configures the environment to use Node.js version 18 using actions/setup-node@v4, with a cache configured for PNPM.\n4. Installs project dependencies using pnpm install.\n5. Runs database migrations with the command pnpm run db:migrate.\n6. Sets up Fly CLI (flyctl) using [superfly/flyctl-actions/setup-flyctl@master](https://github.com/marketplace/actions/github-action-for-flyctl).\n7. Finally, deploys the application using Fly CLI with the command `flyctl deploy --remote-only`.\n\n\n### Neon branch cleanup\n\n`.github/workflows/delete-neon-branch.yml` automates the cleanup of branches in Neon. It is activated on a `pull_request` event with the action `closed`. This will ensure that Neon branches are deleted when a pull request is closed/merged.\n\nThe workflow uses [`neondatabase/delete-branch-action@v3.1.3`](https://github.com/neondatabase/delete-branch-action/tree/v3.1.3/) action which uses the `NEON_API_KEY` and `NEON_PROJECT_ID` secrets that are set in the repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneondatabase%2Fpreview-branches-with-fly","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneondatabase%2Fpreview-branches-with-fly","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneondatabase%2Fpreview-branches-with-fly/lists"}