Repository navigation
[feat] db auto-migration #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: manicode | ||
| services: | ||
| db: | ||
| image: postgres:16 | ||
| restart: always | ||
| ports: | ||
| - 5432:5432 | ||
| environment: | ||
| POSTGRES_USER: manicode_user_local | ||
| POSTGRES_PASSWORD: secretpassword_local | ||
| POSTGRES_DB: manicode_db_local | ||
| volumes: | ||
| - db_data:/var/lib/postgresql/data | ||
| volumes: | ||
| # Store data from Postgres so they persist between Docker ups and downs | ||
| db_data: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { defineConfig } from 'drizzle-kit' | ||
| import { env } from './env.mjs' | ||
| import path from 'path' | ||
|
|
||
| export default defineConfig({ | ||
| dialect: 'postgresql', | ||
| schema: path.join(__dirname, 'schema.ts'), | ||
| out: path.join(__dirname, './migrations'), | ||
| dbCredentials: { | ||
| url: env.DATABASE_URL, | ||
| }, | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { createEnv } from '@t3-oss/env-core' | ||
| import { z } from 'zod' | ||
| import dotenv from 'dotenv' | ||
|
|
||
| dotenv.config({ path: '../stack.env' }) | ||
| if (!process.env.ENVIRONMENT) { | ||
| console.error('ENVIRONMENT is not set, please check `stack.env`') | ||
| process.exit(1) | ||
| } | ||
|
|
||
| const DOTENV_PATH = process.env.ENVIRONMENT === 'local' ? '..' : '/etc/secrets' | ||
| const path = `${DOTENV_PATH}/.env.${process.env.ENVIRONMENT}` | ||
| console.log(`Using environment: ${process.env.ENVIRONMENT} (path: ${path})`) | ||
| dotenv.config({ path }) | ||
|
|
||
| export const env = createEnv({ | ||
| server: { | ||
| ENVIRONMENT: z.string().min(1), | ||
| DATABASE_URL: z.string().min(1), | ||
| }, | ||
| runtimeEnv: process.env, | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { drizzle } from 'drizzle-orm/node-postgres' | ||
| import { Pool } from 'pg' | ||
| import { env } from './env.mjs' | ||
| import * as schema from './schema' | ||
|
|
||
| const pool = new Pool({ | ||
| connectionString: env.DATABASE_URL, | ||
| }) | ||
|
|
||
| const db = drizzle(pool, { schema }) | ||
| export default db |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| import { beforeAll } from 'bun:test' | ||
| import dotenv from 'dotenv' | ||
| import path from 'path' | ||
| // import dotenv from 'dotenv' | ||
| import { env } from './env.mjs' | ||
|
|
||
| beforeAll(() => { | ||
| dotenv.config({ | ||
| processEnv: env, | ||
| }) | ||
| // dotenv.config({ | ||
| // processEnv: env, | ||
| // }) | ||
| }) |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging the environment path might expose sensitive information. Consider removing this log or handling it securely.