Skip to content

Commit

Permalink
chore: upgrade dependencies and add test suite (#36)
Browse files Browse the repository at this point in the history
* test: add vitest

* test: setup ci to run the tests

* feat: update drizzle

* refactor: tsc fixes

* chore: swap `nodemon + ts-node` for `tsx`

* build: ci test script
  • Loading branch information
SeanCassiere authored Jun 17, 2024
1 parent fcb9a99 commit 68b96c5
Show file tree
Hide file tree
Showing 12 changed files with 2,735 additions and 1,858 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/build.yml

This file was deleted.

70 changes: 70 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: pr

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test:
name: test
runs-on: ubuntu-latest
steps:
# This step uses the actions/checkout action to download a copy of your repository on the runner.
- name: Checkout repo
uses: actions/checkout@v4

# This step uses the pnpm/action-setup action to set up pnpm on the runner.
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9

# This step uses the actions/setup-node action to set up a Node.js environment on the runner.
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm

# This step runs the install script for the selected node package manager.
- name: Install dependencies
run: pnpm install

# This step runs the test script if there is one specified under the scripts key in your package.json file.
- name: Test
run: pnpm test:ci

build:
name: build
needs: [test]
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20]
steps:
# This step uses the actions/checkout action to download a copy of your repository on the runner.
- name: Checkout repo
uses: actions/checkout@v4

# This step uses the pnpm/action-setup action to set up pnpm on the runner.
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9

# This step uses the actions/setup-node action to set up a Node.js environment on the runner.
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm

# This step runs the install script for the selected node package manager.
- name: Install dependencies
run: pnpm install

# This step runs the build script if there is one specified under the scripts key in your package.json file.
- name: Build
run: pnpm build
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v21.7.1
10 changes: 5 additions & 5 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import "dotenv/config";
import type { Config } from "drizzle-kit";
import { defineConfig } from "drizzle-kit";

const DB_URL = process.env.DATABASE_URL;

if (!DB_URL) {
throw new Error("DATABASE_URL is not defined");
}

export default {
export default defineConfig({
schema: "./src/config/db/schema.ts",
out: "./drizzle",
driver: "pg",
dialect: "postgresql",
dbCredentials: {
connectionString: DB_URL,
url: DB_URL,
},
} satisfies Config;
});
6 changes: 4 additions & 2 deletions migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ if (!DB_URL) {
const main = async () => {
const start = new Date();

const migrationClient = postgres(DB_URL, { max: 1 });
const db = drizzle(migrationClient);
const client = postgres(DB_URL, { max: 1 });
const db = drizzle(client);

await migrate(db, { migrationsFolder: "./drizzle" });
await client.end();

const end = new Date();
console.log(`Migrations complete in ${end.getTime() - start.getTime()}ms`);
Expand Down
6 changes: 0 additions & 6 deletions nodemon.json

This file was deleted.

22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,42 @@
"lint:fix": "eslint --fix --max-warnings=0 src",
"format": "prettier --write 'src/**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc",
"start": "NODE_ENV=production node dist/index.js",
"dev": "NODE_ENV=development nodemon",
"dev": "NODE_ENV=development tsx --watch ./src/index.ts",
"test": "vitest --typecheck",
"test:ci": "vitest run --typecheck",
"build:kill-dist": "rimraf ./dist",
"build:code": "tsc",
"build": "pnpm run build:kill-dist && pnpm run build:code",
"db:explorer": "drizzle-kit studio --port 3590",
"db:explorer": "drizzle-kit studio",
"db:migrate-generate": "drizzle-kit generate:pg",
"db:migrate-run": "ts-node ./migrator.ts"
"db:migrate-run": "tsx ./migrator.ts"
},
"keywords": [],
"author": "Sean Cassiere",
"license": "MIT",
"devDependencies": {
"@types/node": "^20.10.6",
"@types/node": "^20.14.3",
"@typescript-eslint/eslint-plugin": "^6.18.0",
"@typescript-eslint/parser": "^6.18.0",
"drizzle-kit": "^0.20.9",
"drizzle-kit": "^0.22.7",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.2",
"nodemon": "^3.0.2",
"pg": "^8.11.3",
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"tsx": "^4.15.6",
"typescript": "^5.3.3",
"vitest": "^1.6.0"
},
"dependencies": {
"@fastify/rate-limit": "^9.1.0",
"@paralleldrive/cuid2": "^2.2.2",
"dotenv": "^16.3.1",
"drizzle-orm": "^0.29.3",
"drizzle-orm": "^0.31.2",
"fastify": "^4.25.2",
"fastify-zod": "^1.4.0",
"postgres": "^3.4.3",
"postgres": "^3.4.4",
"zod": "^3.22.4",
"zod-to-json-schema": "^3.22.3"
}
Expand Down
Loading

0 comments on commit 68b96c5

Please sign in to comment.