Skip to content

Commit

Permalink
create reservation table
Browse files Browse the repository at this point in the history
  • Loading branch information
jgravois committed Mar 7, 2024
1 parent 5fa1d93 commit f1960cd
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 32 deletions.
65 changes: 33 additions & 32 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,35 +110,36 @@ jobs:
env:
PORT: 8811

deploy:
name: 🚀 Deploy
runs-on: ubuntu-latest
needs: [lint, typecheck, vitest, cypress]
# only deploy main/dev branch on pushes
if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }}

steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: 👀 Read app name
uses: SebRollen/[email protected]
id: app_name
with:
file: fly.toml
field: app

- name: 🎈 Setup Fly
uses: superfly/flyctl-actions/[email protected]

- name: 🚀 Deploy Staging
if: ${{ github.ref == 'refs/heads/dev' }}
run: flyctl deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }}-staging
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

- name: 🚀 Deploy Production
if: ${{ github.ref == 'refs/heads/main' }}
run: flyctl deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }}
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
# soon
# deploy:
# name: 🚀 Deploy
# runs-on: ubuntu-latest
# needs: [lint, typecheck, vitest, cypress]
# # only deploy main/dev branch on pushes
# if: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev') && github.event_name == 'push' }}

# steps:
# - name: ⬇️ Checkout repo
# uses: actions/checkout@v4

# - name: 👀 Read app name
# uses: SebRollen/[email protected]
# id: app_name
# with:
# file: fly.toml
# field: app

# - name: 🎈 Setup Fly
# uses: superfly/flyctl-actions/[email protected]

# - name: 🚀 Deploy Staging
# if: ${{ github.ref == 'refs/heads/dev' }}
# run: flyctl deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }}-staging
# env:
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}

# - name: 🚀 Deploy Production
# if: ${{ github.ref == 'refs/heads/main' }}
# run: flyctl deploy --remote-only --build-arg COMMIT_SHA=${{ github.sha }} --app ${{ steps.app_name.outputs.value }}
# env:
# FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ node_modules
/cypress/videos
/prisma/data.db
/prisma/data.db-journal

notes
38 changes: 38 additions & 0 deletions app/models/reservation.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { User, Reservation } from "@prisma/client";

import { prisma } from "~/db.server";

export function getReservations() {
return prisma.reservation.findMany({
select: { id: true, start: true, end: true },
});
}

export function createReservation({
start,
end,
userId,
}: Pick<Reservation, "start" | "end"> & {
userId: User["id"];
}) {
return prisma.reservation.create({
data: {
start,
end,
user: {
connect: {
id: userId,
},
},
},
});
}

export function deleteReservation({
id,
userId,
}: Pick<Reservation, "id"> & { userId: User["id"] }) {
return prisma.reservation.deleteMany({
where: { id, userId },
});
}
10 changes: 10 additions & 0 deletions prisma/migrations/20240307052457_create_rez/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- CreateTable
CREATE TABLE "Reservation" (
"id" TEXT NOT NULL PRIMARY KEY,
"start" DATETIME NOT NULL,
"end" DATETIME NOT NULL,
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" DATETIME NOT NULL,
"userId" TEXT NOT NULL,
CONSTRAINT "Reservation_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
13 changes: 13 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ model User {
password Password?
notes Note[]
reservations Reservation[]
}

model Password {
Expand All @@ -36,3 +37,15 @@ model Note {
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String
}

model Reservation {
id String @id @default(cuid())
start DateTime
end DateTime
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String
}
9 changes: 9 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ async function seed() {
},
});

const now = new Date()
await prisma.reservation.create({
data: {
start: now,
end: now,
userId: user.id,
},
});

console.log(`Database has been seeded. 🌱`);
}

Expand Down

0 comments on commit f1960cd

Please sign in to comment.