Skip to content

Commit

Permalink
Merge pull request #76 from filipedeschamps/actions
Browse files Browse the repository at this point in the history
Adiciona Github Actions para rodar os testes
  • Loading branch information
filipedeschamps authored Jul 21, 2021
2 parents f2546b1 + 4af4440 commit bbd1903
Show file tree
Hide file tree
Showing 15 changed files with 13,893 additions and 4,756 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["next/babel"]
}
5 changes: 5 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
POSTGRES_USER=local
POSTGRES_PASSWORD=local
POSTGRES_DB=tabnews
POSTGRES_HOST=localhost
POSTGRES_PORT=54321
14 changes: 14 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "14"
- run: npm ci
- run: npm test
2 changes: 1 addition & 1 deletion docker-compose.development.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.8"
version: "2.4"
services:
postgres:
container_name: "postgres"
Expand Down
9 changes: 9 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: "2.4"
services:
postgres_test:
container_name: "postgres-test"
image: "postgres:13.3-alpine"
env_file:
- .env.test
ports:
- "54321:5432"
15 changes: 13 additions & 2 deletions models/migrator.js → infra/migrator.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import databaseFactory from "infra/database.js";
import migrationRunner from "node-pg-migrate";

export default function Migrator(options = {}) {
export default function Migrator() {
const defaultConfigurations = {
dbClient: options.databaseClient,
dir: "./infra/migrations",
direction: "up",
migrationsTable: "migrations",
verbose: true,
};

async function listPendingMigrations() {
const database = databaseFactory();
const databaseClient = await database.getNewConnectionClient();
const pendingMigrations = await migrationRunner({
...defaultConfigurations,
dbClient: databaseClient,
dryRun: true,
});

await databaseClient.end();

return pendingMigrations;
}

async function runPendingMigrations() {
const database = databaseFactory();
const databaseClient = await database.getNewConnectionClient();

const migratedMigrations = await migrationRunner({
...defaultConfigurations,
dbClient: databaseClient,
dryRun: false,
});

await databaseClient.end();

return migratedMigrations;
}

Expand Down
Loading

1 comment on commit bbd1903

@vercel
Copy link

@vercel vercel bot commented on bbd1903 Jul 21, 2021

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.