hey all, im having some trouble running a migratio...
# orm-help
a
hey all, im having some trouble running a migration script inside of a github action. I am trying to connect to a google cloud sql database with a connection string. (I am able to use the same connection string to connect via GUI and command line, so I know it works), however inside the github action after running
npx prisma migrate deploy
I get this error:
Copy code
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "postgres", schema "public" at "IP"
Error: P1001: Can't reach database server at `IP`:`5432`

Please make sure your database server is running at `IP`:`5432`.
Error: Process completed with exit code 1.
j
I am able to use the same connection string to connect via GUI and command line
With Prisma locally?
a
yup!
I believe I know the answer though, I think it has to do with Google’s public IP connection. You have to use a proxy or authorize a network (ip), so I need to setup the google auth proxy inside of a github action in order to access the db
👍 1
ill report back
j
@Sytten might be able to help you if you can not figure it out
a
was able to make it work utilizing this github action which sets up a google sql auth proxy, provided a service account and its accompanying credentials. Something worth noting is the
DATABASE_URL
still needs to include the password so it would look like this in your secrets:
postgres://<USERNAME>:<PASSWORD>@localhost/<DATABASE_NAME>?host=localhost
s
Yeah that is what I do too for github actions, I usually just start the sql proxy directly
a
how do you do that? im curious
s
Copy code
- name: Get Cloud SQL Proxy
        run: |
          wget <https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64> -O cloud_sql_proxy
          chmod +x cloud_sql_proxy

      - name: Install prisma
        run: npm install -g prisma@2.20.1

      - name: Run migration
        run: |
          ./cloud_sql_proxy -instances=${{ env.PROJECT }}:us-east4:${{ env.DATABASE }}=tcp:65432 &
          sleep 5
          DATABASE_URL=$(gcloud secrets versions access latest --secret ${{ env.DATABASE_SECRET }} --project ${{ env.PROJECT }}) prisma migrate deploy --schema ./packages/*******/prisma/schema.prisma
a
oooh this is way fancier than what im doing
thanks for this
👍 1