Skip to content

Commit

Permalink
Log cron job connection to database. (#137)
Browse files Browse the repository at this point in the history
* Prepare for sample cronjob.

* Bump readme.

* Remove vercel.json

* Readd vercel.job.

* Add database connection to planetscale and write during cron.

* Fix linting.
  • Loading branch information
yoonghan authored Feb 25, 2023
1 parent 608a926 commit 0ee80c9
Show file tree
Hide file tree
Showing 15 changed files with 465 additions and 25 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,13 @@ FIREBASE_PRIVATE_KEY=""
FIREBASE_CLIENT_EMAIL=""
FIREBASE_CLIENT_ID=""
FIREBASE_CLIENT_X509_CERT_URL=""


# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL=''
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ git push
1. NextJS on vercel re-uses .next build cache. This sometimes creates an issue, e.g. a page that was once deployed as AMP will forever be recognized as AMP until the cache is cleared.
2. To build without previous build cache; click redeploy button from Vercel dashboard (a menu from the 3 vertical dots) and uncheck "Build with previous build cache".

# Prisma

1. Add new schema into prisma/schema.prisma file.
2. Any new tables created, run prisma generate.

```
npm run prisma:generate //create ts schema
npm run prisma:push //push to PlanetScale, main branch
```
=======

[build-badge]: https://img.shields.io/github/actions/workflow/status/yoonghan/Walcron/pull-request.yml
[build]: https://github.com/yoonghan/Walcron/actions?query=workflow%3Avalidator
[coverage-badge]: https://img.shields.io/codecov/c/github/yoonghan/Walcron.svg?style=flat-square
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const customJestConfig = {
"^@/pageComponents/(.*)$": "<rootDir>/src/pageComponents/$1",
"^@/pages/(.*)$": "<rootDir>/src/pages/$1",
"^@/config/(.*)$": "<rootDir>/src/config/$1",
"^@/transport/(.*)$": "<rootDir>/src/transport/$1",
"^@/images/*": "<rootDir>/public/img/$1",
},
testEnvironment: "jest-environment-jsdom",
Expand Down
172 changes: 172 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
"backstop:approve": "backstop approve",
"backstop:test": "backstop test",
"playwright:test": "playwright test",
"prisma:push": "dotenv -e .env.local prisma db push",
"prisma:generate": "prisma generate",
"analyze": "ANALYZE=true next build"
},
"dependencies": {
"@prisma/client": "^4.10.1",
"@react-spring/web": "^9.6.1",
"backstopjs": "^6.1.1",
"cookies-next": "^2.1.1",
"firebase-admin": "^11.4.1",
"next": "latest",
"next-pwa": "^5.6.0",
"prisma": "^4.10.1",
"pusher": "^5.1.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
Expand All @@ -37,6 +41,7 @@
"@types/react-confirm": "^0.2.0",
"@types/react-toggle": "^4.0.3",
"@types/uuid": "^9.0.0",
"dotenv-cli": "^7.0.0",
"eslint": "^8.23.1",
"eslint-config-next": "^13.1.1",
"eslint-config-prettier": "^8.5.0",
Expand All @@ -46,6 +51,7 @@
"formidable": "^3.2.5",
"jest": "^29.3.1",
"jest-environment-jsdom": "28.1.0",
"jest-mock-extended": "^3.0.2",
"next-router-mock": "^0.7.4",
"pusher-js": "^7.5.0",
"react-autosuggest": "^10.1.0",
Expand Down
18 changes: 18 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "mysql"
url = env("DATABASE_URL")
relationMode = "prisma"
}

model CronJob {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
jobName String @db.VarChar(100)
}
15 changes: 15 additions & 0 deletions src/__mocks__/prismaMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PrismaClient } from "@prisma/client"
import { mockDeep, mockReset, DeepMockProxy } from "jest-mock-extended"

import prisma from "../transport/prismaClient"

jest.mock("../transport/prismaClient", () => ({
__esModule: true,
default: mockDeep<PrismaClient>(),
}))

beforeEach(() => {
mockReset(prismaMock)
})

export const prismaMock = prisma as unknown as DeepMockProxy<PrismaClient>
Loading

1 comment on commit 0ee80c9

@vercel
Copy link

@vercel vercel bot commented on 0ee80c9 Feb 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.