diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6064d9c..f03648a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -291,33 +291,25 @@ jobs: run: | git clone https://x-access-token:${{ steps.infra-token.outputs.token }}@github.com/groombook/infra.git /tmp/infra - - name: Update image tags + - name: Install yq + run: | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 + sudo chmod +x /usr/local/bin/yq + + - name: Update dev overlay image tags env: TAG: ${{ needs.docker.outputs.tag }} run: | if [ -z "$TAG" ]; then TAG="$(date -u +%Y.%m.%d)-${GITHUB_SHA::7}" fi - echo "Updating image tags to: $TAG" - + echo "Updating dev overlay image tags to: $TAG" cd /tmp/infra - - # Update api.yaml - sed -i "s|ghcr.io/groombook/api:[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-[a-f0-9]*|ghcr.io/groombook/api:${TAG}|g" apps/groombook/base/api.yaml - sed -i "s|groombook.dev/image-version: \"[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-[a-f0-9]*\"|groombook.dev/image-version: \"${TAG}\"|g" apps/groombook/base/api.yaml - - # Update web.yaml - sed -i "s|ghcr.io/groombook/web:[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-[a-f0-9]*|ghcr.io/groombook/web:${TAG}|g" apps/groombook/base/web.yaml - sed -i "s|groombook.dev/image-version: \"[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-[a-f0-9]*\"|groombook.dev/image-version: \"${TAG}\"|g" apps/groombook/base/web.yaml - - # Update migrate-job.yaml - sed -i "s|ghcr.io/groombook/migrate:[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-[a-f0-9]*|ghcr.io/groombook/migrate:${TAG}|g" apps/groombook/base/migrate-job.yaml - sed -i "s|groombook.app/deploy-version: \"[a-zA-Z0-9-]*\"|groombook.app/deploy-version: \"${TAG}\"|g" apps/groombook/base/migrate-job.yaml - - # Update seed-job.yaml - sed -i "s|ghcr.io/groombook/seed:[0-9][0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]-[a-f0-9]*|ghcr.io/groombook/seed:${TAG}|g" apps/groombook/base/seed-job.yaml - sed -i "s|groombook.app/deploy-version: \"[a-zA-Z0-9-]*\"|groombook.app/deploy-version: \"${TAG}\"|g" apps/groombook/base/seed-job.yaml - + DEV_KUST="apps/groombook/overlays/dev/kustomization.yaml" + yq -i '(.images[] | select(.name == "ghcr.io/groombook/api")).newTag = env(TAG)' "$DEV_KUST" + yq -i '(.images[] | select(.name == "ghcr.io/groombook/web")).newTag = env(TAG)' "$DEV_KUST" + yq -i '(.images[] | select(.name == "ghcr.io/groombook/migrate")).newTag = env(TAG)' "$DEV_KUST" + yq -i '(.images[] | select(.name == "ghcr.io/groombook/seed")).newTag = env(TAG)' "$DEV_KUST" git -C /tmp/infra diff --stat - name: Create PR on groombook/infra @@ -333,8 +325,8 @@ jobs: git config user.name "groombook-engineer[bot]" git config user.email "3141748+groombook-engineer[bot]@users.noreply.github.com" git checkout -b "chore/update-image-tags-${TAG}" - git add apps/groombook/base/ - git commit -m "chore: update image tags to ${TAG}" + git add apps/groombook/overlays/dev/ + git commit -m "chore: deploy ${TAG} to dev" git push -u origin "chore/update-image-tags-${TAG}" @@ -343,6 +335,6 @@ jobs: --repo groombook/infra \ --base main \ --head "chore/update-image-tags-${TAG}" \ - --title "chore: update image tags to ${TAG}" \ + --title "chore: deploy ${TAG} to dev" \ --body "[GRO-178](/GRO/issues/GRO-178) — automated image tag update from main merge") gh pr merge "$PR_URL" --auto --merge diff --git a/packages/db/src/seed.ts b/packages/db/src/seed.ts index f7936be..dc6ddfa 100644 --- a/packages/db/src/seed.ts +++ b/packages/db/src/seed.ts @@ -407,14 +407,19 @@ async function seed() { const allStaff = [...managerStaff, ...receptionistStaff, ...groomers, ...bathers]; for (const s of allStaff) { - await db.insert(schema.staff).values({ - id: s.id, - name: s.name, - email: s.email, - role: s.role, - isSuperUser: s.isSuperUser, - active: true, - }); + await db.insert(schema.staff) + .values({ + id: s.id, + name: s.name, + email: s.email, + role: s.role, + isSuperUser: s.isSuperUser, + active: true, + }) + .onConflictDoUpdate({ + target: schema.staff.email, + set: { name: s.name, role: s.role, isSuperUser: s.isSuperUser, active: true }, + }); } console.log(`✓ Created ${allStaff.length} staff (1 manager, 1 receptionist, 3 groomers, 3 bathers)`); @@ -423,14 +428,19 @@ async function seed() { for (const s of servicesDef) { const id = uuid(); serviceIds.push(id); - await db.insert(schema.services).values({ - id, - name: s.name, - description: s.desc, - basePriceCents: s.price, - durationMinutes: s.dur, - active: true, - }); + await db.insert(schema.services) + .values({ + id, + name: s.name, + description: s.desc, + basePriceCents: s.price, + durationMinutes: s.dur, + active: true, + }) + .onConflictDoUpdate({ + target: schema.services.id, + set: { name: s.name, description: s.desc, basePriceCents: s.price, durationMinutes: s.dur, active: true }, + }); } console.log(`✓ Created ${servicesDef.length} services`); @@ -502,8 +512,36 @@ async function seed() { } } - await db.insert(schema.clients).values(clientBatch); - await db.insert(schema.pets).values(petBatch); + for (const client of clientBatch) { + await db.insert(schema.clients) + .values(client) + .onConflictDoUpdate({ + target: schema.clients.email, + set: { name: client.name, phone: client.phone, address: client.address, notes: client.notes, emailOptOut: client.emailOptOut }, + }); + } + + for (const pet of petBatch) { + await db.insert(schema.pets) + .values(pet) + .onConflictDoUpdate({ + target: schema.pets.id, + set: { + clientId: pet.clientId, + name: pet.name, + species: pet.species, + breed: pet.breed, + weightKg: pet.weightKg, + dateOfBirth: pet.dateOfBirth, + healthAlerts: pet.healthAlerts, + groomingNotes: pet.groomingNotes, + cutStyle: pet.cutStyle, + shampooPreference: pet.shampooPreference, + specialCareNotes: pet.specialCareNotes, + customFields: pet.customFields, + }, + }); + } } console.log(`✓ Created 500 clients with ${petRecords.length} pets`);