From 2c380b0f939aec28570dfd5e27e3a988d3ff2023 Mon Sep 17 00:00:00 2001 From: Rafael do Amaral Costa Date: Sat, 12 Sep 2026 19:22:38 -0300 Subject: [PATCH] add: knex file and migrations base --- back/.env.example | 10 ++++- back/knexfile.ts | 44 +++++++++++++++++++ back/package.json | 7 ++- .../migrations/20260911201457_user.ts | 12 +++++ .../migrations/20260912221551_campanhas.ts | 10 +++++ .../migrations/20260912221614_vaquinhas.ts | 10 +++++ .../migrations/20260912221623_rifas.ts | 10 +++++ .../20260912221823_redes_sociais.ts | 10 +++++ .../migrations/20260912221836_comprovantes.ts | 10 +++++ .../migrations/20260912221841_inscricao.ts | 10 +++++ 10 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 back/knexfile.ts create mode 100644 back/src/database/migrations/20260911201457_user.ts create mode 100644 back/src/database/migrations/20260912221551_campanhas.ts create mode 100644 back/src/database/migrations/20260912221614_vaquinhas.ts create mode 100644 back/src/database/migrations/20260912221623_rifas.ts create mode 100644 back/src/database/migrations/20260912221823_redes_sociais.ts create mode 100644 back/src/database/migrations/20260912221836_comprovantes.ts create mode 100644 back/src/database/migrations/20260912221841_inscricao.ts diff --git a/back/.env.example b/back/.env.example index 7f244a5..c49a529 100644 --- a/back/.env.example +++ b/back/.env.example @@ -1,3 +1,11 @@ PORT= HOST= -NODE_ENV= \ No newline at end of file + +NODE_ENV= + +DB_HOST= +DB_PORT= +DB_USER= +DB_PASSWORD= +DB_NAME= +DATABASE_URL= \ No newline at end of file diff --git a/back/knexfile.ts b/back/knexfile.ts new file mode 100644 index 0000000..afa1eae --- /dev/null +++ b/back/knexfile.ts @@ -0,0 +1,44 @@ +import type { Knex } from "knex"; +import "dotenv/config"; + +function requireEnv(name: string): string { + const value = process.env[name]; + if (!value) { + throw new Error(`Variável de ambiente obrigatória ausente: ${name}`); + } + return value; + } + + const config: Record = { + development: { + client: "pg", + connection: { + host: String(process.env.DB_HOST ), + port: Number(process.env.DB_PORT), + user: requireEnv("DB_USER"), + password: requireEnv("DB_PASSWORD"), + database: requireEnv("DB_NAME"), + }, + migrations: { + directory: "./src/database/migrations", + extension: "ts", + }, + seeds: { + directory: "./src/database/seeds", + extension: "ts", + }, + pool: { min: 2, max: 10 }, + }, + + production: { + client: "pg", + connection: requireEnv("DATABASE_URL"), + migrations: { + directory: "./src/database/migrations", + extension: "ts", + }, + pool: { min: 2, max: 10 }, + }, +}; + +export default config; \ No newline at end of file diff --git a/back/package.json b/back/package.json index fe1618c..818748f 100644 --- a/back/package.json +++ b/back/package.json @@ -4,7 +4,12 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "dev": "tsx watch src/server.ts" + "dev": "tsx watch src/server.ts", + "migrate:make": "tsx node_modules/knex/bin/cli.js migrate:make --knexfile knexfile.ts", + "migrate:latest": "tsx node_modules/knex/bin/cli.js migrate:latest --knexfile knexfile.ts", + "migrate:rollback": "tsx node_modules/knex/bin/cli.js migrate:rollback --knexfile knexfile.ts", + "seed:make": "tsx node_modules/knex/bin/cli.js seed:make --knexfile knexfile.ts", + "seed:run": "tsx node_modules/knex/bin/cli.js seed:run --knexfile knexfile.ts" }, "type": "module", "keywords": [], diff --git a/back/src/database/migrations/20260911201457_user.ts b/back/src/database/migrations/20260911201457_user.ts new file mode 100644 index 0000000..f8858f3 --- /dev/null +++ b/back/src/database/migrations/20260911201457_user.ts @@ -0,0 +1,12 @@ +import type { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { + +} + + +export async function down(knex: Knex): Promise { + +} + diff --git a/back/src/database/migrations/20260912221551_campanhas.ts b/back/src/database/migrations/20260912221551_campanhas.ts new file mode 100644 index 0000000..9270377 --- /dev/null +++ b/back/src/database/migrations/20260912221551_campanhas.ts @@ -0,0 +1,10 @@ +import type { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { +} + + +export async function down(knex: Knex): Promise { +} + diff --git a/back/src/database/migrations/20260912221614_vaquinhas.ts b/back/src/database/migrations/20260912221614_vaquinhas.ts new file mode 100644 index 0000000..9270377 --- /dev/null +++ b/back/src/database/migrations/20260912221614_vaquinhas.ts @@ -0,0 +1,10 @@ +import type { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { +} + + +export async function down(knex: Knex): Promise { +} + diff --git a/back/src/database/migrations/20260912221623_rifas.ts b/back/src/database/migrations/20260912221623_rifas.ts new file mode 100644 index 0000000..9270377 --- /dev/null +++ b/back/src/database/migrations/20260912221623_rifas.ts @@ -0,0 +1,10 @@ +import type { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { +} + + +export async function down(knex: Knex): Promise { +} + diff --git a/back/src/database/migrations/20260912221823_redes_sociais.ts b/back/src/database/migrations/20260912221823_redes_sociais.ts new file mode 100644 index 0000000..9270377 --- /dev/null +++ b/back/src/database/migrations/20260912221823_redes_sociais.ts @@ -0,0 +1,10 @@ +import type { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { +} + + +export async function down(knex: Knex): Promise { +} + diff --git a/back/src/database/migrations/20260912221836_comprovantes.ts b/back/src/database/migrations/20260912221836_comprovantes.ts new file mode 100644 index 0000000..9270377 --- /dev/null +++ b/back/src/database/migrations/20260912221836_comprovantes.ts @@ -0,0 +1,10 @@ +import type { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { +} + + +export async function down(knex: Knex): Promise { +} + diff --git a/back/src/database/migrations/20260912221841_inscricao.ts b/back/src/database/migrations/20260912221841_inscricao.ts new file mode 100644 index 0000000..9270377 --- /dev/null +++ b/back/src/database/migrations/20260912221841_inscricao.ts @@ -0,0 +1,10 @@ +import type { Knex } from "knex"; + + +export async function up(knex: Knex): Promise { +} + + +export async function down(knex: Knex): Promise { +} +