Adds Drizzle ORM with Infisical for secure database management
Integrates Drizzle ORM to provide a type-safe and modern solution for PostgreSQL database interactions. Establishes Infisical as the central secret management system, ensuring sensitive database credentials and other environment variables are securely loaded dynamically based on the active environment. Includes a PowerShell script to standardize environment setup for Drizzle CLI operations, fetching secrets from Infisical and local configuration files. New npm scripts `drizzle:push` and `drizzle:pull` are added to streamline database schema migrations. Sets up an initial database module with a `DatabaseService` and a sample `users` schema to demonstrate Drizzle's functionality and integration with Infisical secrets.
This commit is contained in:
1 parent
6aec3e91b8
commit
469e799b01
13 files changed
+1651
-4
No files matched your search
@@ -0,0 +1,91 @@
|
||||
# [System.Environment]::SetEnvironmentVariable("NODE_ENV", $null)
|
||||
|
||||
param(
|
||||
[Parameter(ValueFromRemainingArguments = $true)]
|
||||
[string[]] $Rest
|
||||
)
|
||||
|
||||
# NODE_ENV 환경 변수가 설정되어 있지 않으면 'dev'로 설정
|
||||
if (-not $env:NODE_ENV) {
|
||||
$env:NODE_ENV = 'dev'
|
||||
}
|
||||
|
||||
if ($isMacOS -or $isLinux) {
|
||||
$env:ENV_FILE = "$PSScriptRoot/../env-vars/$env:NODE_ENV.env"
|
||||
$env:AWS_CREDENTIALS_FILE = "$env:HOME/.aws/credentials"
|
||||
$env:DAHYEON_GLOBAL_ENVIRONMENT_FILE = "$env:HOME/source/global-env-vars.txt"
|
||||
} elseif ($isWindows) {
|
||||
$env:ENV_FILE = "$PSScriptRoot\env-vars\$env:NODE_ENV.env"
|
||||
$env:AWS_CREDENTIALS_FILE = "$env:USERPROFILE\.aws\credentials"
|
||||
$env:DAHYEON_GLOBAL_ENVIRONMENT_FILE = "$env:USERPROFILE/source/global-env-vars.txt"
|
||||
}
|
||||
|
||||
# 환경 변수 파일 확인
|
||||
if (-Not (Test-Path $env:ENV_FILE)) {
|
||||
Write-Error "The file '$env:ENV_FILE' does not exist."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 'dahyeon-local.env' 파일에서 환경 변수 설정
|
||||
Get-Content $env:ENV_FILE | ForEach-Object {
|
||||
if ($_ -match '^\s*([^#]+?)\s*=\s*(.*)$') {
|
||||
$key, $value = $matches[1].Trim(), $matches[2].Trim().Trim("`"")
|
||||
[System.Environment]::SetEnvironmentVariable($key, $value)
|
||||
}
|
||||
}
|
||||
|
||||
# AWS 자격 증명 파일 확인
|
||||
if (-Not (Test-Path $env:AWS_CREDENTIALS_FILE)) {
|
||||
Write-Error "The AWS credentials file '$env:AWS_CREDENTIALS_FILE' does not exist."
|
||||
exit 1
|
||||
}
|
||||
|
||||
# 공통 환경변수 파일 확인
|
||||
if (-Not (Test-Path $env:DAHYEON_GLOBAL_ENVIRONMENT_FILE)) {
|
||||
Write-Error "The global environment variables file '$env:DAHYEON_GLOBAL_ENVIRONMENT_FILE' does not exist."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# AWS 자격 증명 파일에서 환경 변수 설정
|
||||
Get-Content $env:AWS_CREDENTIALS_FILE | Where-Object { $_ -match '^\s*([^#=\[]+?)\s*=\s*(.*)$' } | ForEach-Object {
|
||||
$key, $value = $matches[1].Trim(), $matches[2].Trim()
|
||||
$envKey = ($key -replace ' ', '_').ToUpper()
|
||||
[System.Environment]::SetEnvironmentVariable($envKey, $value)
|
||||
}
|
||||
|
||||
# 공통 환경변수 파일에서 환경 변수 설정
|
||||
Get-Content $env:DAHYEON_GLOBAL_ENVIRONMENT_FILE | Where-Object { $_ -match '^\s*([^#=\[]+?)\s*=\s*(.*)$' } | ForEach-Object {
|
||||
$key, $value = $matches[1].Trim(), $matches[2].Trim()
|
||||
$envKey = ($key -replace ' ', '_').ToUpper()
|
||||
[System.Environment]::SetEnvironmentVariable($envKey, $value)
|
||||
}
|
||||
|
||||
# Load secrets from Infisical using Node.js script
|
||||
Write-Host "Loading secrets from Infisical..."
|
||||
$secretsOutput = & node "$PSScriptRoot/load-secrets.mjs"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Error "Failed to load secrets from Infisical"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Parse and set environment variables from Infisical
|
||||
$secretsOutput | ForEach-Object {
|
||||
if ($_ -match '^\s*([^=]+?)\s*=\s*(.*)$') {
|
||||
$key, $value = $matches[1].Trim(), $matches[2].Trim()
|
||||
[System.Environment]::SetEnvironmentVariable($key, $value)
|
||||
}
|
||||
}
|
||||
|
||||
Get-ChildItem Env: | Where-Object { $_.Name -like "*DATABASE*" -or $_.Name -like "*AWS*" -or $_.Name -eq "NODE_ENV" }
|
||||
|
||||
if ($Rest -and $Rest.Count -gt 0) {
|
||||
$exe = $Rest[0]
|
||||
$exeArgs = @()
|
||||
if ($Rest.Count -gt 1) { $exeArgs = $Rest[1..($Rest.Count - 1)] }
|
||||
|
||||
Write-Host "→ Running (array):" $exe $exeArgs
|
||||
& $exe @exeArgs
|
||||
} else {
|
||||
Write-Host "No command provided. Nothing to run."
|
||||
}
|
||||
Reference in new issue
Block a user