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,43 @@
|
||||
import { InfisicalSDK } from "@infisical/sdk";
|
||||
|
||||
export type SecretMap = Record<string, string | boolean | undefined>;
|
||||
|
||||
const INFISICAL_SITE_URL = "https://secret-manager.dahyeon.us/"
|
||||
|
||||
const INFISICAL_CLIENT_SECRET = process.env.INFISICAL_CLIENT_SECRET;
|
||||
const INFISICAL_CLIENT_ID = process.env.INFISICAL_CLIENT_ID;
|
||||
const INFISICAL_PROJECT_ID = process.env.INFISICAL_PROJECT_ID;
|
||||
|
||||
const infisicalClient = new InfisicalSDK({ siteUrl: INFISICAL_SITE_URL })
|
||||
|
||||
export let secrets: SecretMap | null = null;
|
||||
|
||||
export const fetchSecrets = async (): Promise<SecretMap> => {
|
||||
if (!INFISICAL_CLIENT_SECRET || !INFISICAL_CLIENT_ID || !INFISICAL_PROJECT_ID) {
|
||||
throw new Error("Missing infisical environment variables")
|
||||
}
|
||||
|
||||
await infisicalClient.auth().universalAuth.login({
|
||||
clientId: INFISICAL_CLIENT_ID,
|
||||
clientSecret: INFISICAL_CLIENT_SECRET,
|
||||
});
|
||||
|
||||
const res = await infisicalClient.secrets().listSecrets({
|
||||
environment: process.env.NODE_ENV === 'prod' ? 'prod' : process.env.NODE_ENV === 'test' ? 'staging' : 'dev',
|
||||
projectId: INFISICAL_PROJECT_ID,
|
||||
});
|
||||
|
||||
const map: SecretMap = {};
|
||||
for (const s of res.secrets) {
|
||||
map[s.secretKey] = s.secretValue;
|
||||
}
|
||||
|
||||
return map
|
||||
}
|
||||
|
||||
export const initSecrets = async () => {
|
||||
if (!secrets) {
|
||||
secrets = await fetchSecrets();
|
||||
}
|
||||
return secrets;
|
||||
}
|
||||
Reference in new issue
Block a user