Skip to content

Commit

Permalink
Merge pull request #16 from vratix-dev/feature/db-migrations-cofig
Browse files Browse the repository at this point in the history
FEATURE: DB Migrations Config
  • Loading branch information
ivan-ivanovv authored Nov 15, 2024
2 parents 41b3108 + 0d5e5e8 commit 5f47ea5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 16 deletions.
13 changes: 3 additions & 10 deletions docs/postgres.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,14 @@ Our CLI generates migration files for each module, making it easy to handle your

> **NOTE:** All of our modules that have a DB repository implementation come with schema and migration files, which are added to your project when installing them.
1. **Run Migrations** from your project root:
We add a `package.json` file in `/src/db-migrations` to enable `db-migrate` to work with our ESM project. **Do not modify the contents of this file.**

To run migrations, execute the following command from your project root:
```bash
npm run migrate:up
```

This command will execute migration files in the order specified, ensuring your database schema is up-to-date.

3. **Rollback (Optional):** If you need to undo the latest migration, you can roll it back by running:

```bash
npm run migrate:down
```

This will reverse the latest migration, which is useful for testing changes or rolling back in development environments.
To create new migration files for your SQL schemas, follow the `db-migrate` [package guide](https://db-migrate.readthedocs.io/en/latest/Getting%20Started/usage/#creating-migrations).

## Template Repository

Expand Down
41 changes: 41 additions & 0 deletions docs/test.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
title: Testing
description: Guide for running the tests that come with each API Module
---

Our API modules come with pre-written tests for controllers and middleware, making it easy to ensure your service functions as expected.
We have included the test coverage for each module in the documentation.

## Setup

Make sure to configure `.env` variables in your `vitest.config.ts` file so the tests can run. You can use mock values.

```json
{
"env": {
"JWT_SECRET_KEY": "testSecretKey",
"JWT_ISSUER": "api.tests",
"S3_BUCKET_NAME": "mockBucketName",
"S3_BUCKET_REGION": "us-east-1",
"POSTMARK_SERVER_TOKEN": "xxxx-xxxxx-xxxx-xxxxx-xxxxxx"
}
}
```

## Running Tests

To execute tests, run the following command from the root of your project:

```bash
npm run test
```

## Coverage Report

To generate a test coverage report, use:

```bash
npm run coverage
```

This command will create a detailed report, allowing you to identify which parts of your code are covered by tests.
4 changes: 4 additions & 0 deletions registry/dbConfig/postgres/database.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"postgres": { "ENV": "PG_CONNECTION_STRING" },
"sql-file": true
}
16 changes: 10 additions & 6 deletions templates/node-ts/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { configDefaults, defineConfig } from "vitest/config";
import path from "path";

export default defineConfig({
test: {
Expand All @@ -12,16 +13,19 @@ export default defineConfig({
reporter: ["text", "json", "html"],
exclude: [
...configDefaults.coverage.exclude || [],
"repositories/*",
"schemaValidators/*",
"**/router/*",
"**/repositories/*",
"**/schemas/*",
"**/routes/*",
"**/middleware/*",
"**/errors/*"
],
},
env: {},
alias: {
"@/": new URL("./", import.meta.url).pathname,
},
alias: [
{
find: new RegExp('^@/(.*)$'),
replacement: path.resolve(__dirname, './src/$1'),
}
],
},
});

0 comments on commit 5f47ea5

Please sign in to comment.