From 92792c3dfd1791210535fc3c3c9d28283476a869 Mon Sep 17 00:00:00 2001 From: Shadil A M Date: Tue, 7 Jul 2026 00:22:18 +0530 Subject: [PATCH] feat: add CI pipeline for automatic DB updates Adds a GitHub Actions workflow that: - Runs weekly or on manual dispatch - Clones the upstream problem data repository - Spins up a PostgreSQL service container - Runs the Go merger to scrape CSV data into local PG - Syncs to Supabase remote database - Updates the app_metadata.last_db_update timestamp Closes #2 --- .github/workflows/db-update.yml | 52 +++++++++++++++++++++++++++++++++ merger/main.go | 10 +++++-- 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/db-update.yml diff --git a/.github/workflows/db-update.yml b/.github/workflows/db-update.yml new file mode 100644 index 0000000..326158d --- /dev/null +++ b/.github/workflows/db-update.yml @@ -0,0 +1,52 @@ +name: Auto-Update Database + +on: + schedule: + - cron: "0 0 * * 0" # weekly on Sunday midnight + workflow_dispatch: # manual trigger + +jobs: + sync: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: visor + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Clone problem data repository + run: | + rm -rf leetcode-companywise-interview-questions + git clone --depth 1 https://github.com/snehasishroy/leetcode-companywise-interview-questions.git leetcode-companywise-interview-questions + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.25" + + - name: Run data merger + working-directory: merger + run: go run . --ci + env: + LOCAL_DATABASE_URL: postgres://postgres:postgres@localhost:5432/visor?sslmode=disable + SUPABASE_DATABASE_URL: ${{ secrets.SUPABASE_DATABASE_URL }} + ROOT_DIR: ../leetcode-companywise-interview-questions + + - name: Update last_db_update timestamp + run: | + psql "${{ secrets.SUPABASE_DATABASE_URL }}" \ + -c "INSERT INTO app_metadata (id, last_db_update) VALUES (1, now()) ON CONFLICT (id) DO UPDATE SET last_db_update = now();" diff --git a/merger/main.go b/merger/main.go index 252f2f1..1541fd0 100644 --- a/merger/main.go +++ b/merger/main.go @@ -1,7 +1,13 @@ package main +import "os" + func main() { - // scrapeGithubMain() - // scrapeTagsMain() + if len(os.Args) > 1 && os.Args[1] == "--ci" { + scrapeGithubMain() + scrapeTagsMain() + supabaseSyncMain() + return + } supabaseSyncMain() // go run main.go supabase_sync.go }