wisie
wisie
Explore posts from servers
DTDrizzle Team
Created by wisie on 2/9/2024 in #help
cannot generate migrations, getting a weird ReferenceError I don't know how to debug
db/index.ts - connection is created here
import { Pool } from 'pg';
import { NodePgDatabase, drizzle } from 'drizzle-orm/node-postgres';
import 'dotenv/config';

import * as postSchema from './schema/post';
import * as userSchema from './schema/user';

import logger from '../utils/logger';

function main() {
if (
!process.env.DB_HOST ||
!process.env.DB_NAME ||
!process.env.DB_USER ||
!process.env.DB_PASSWORD
) {
throw new Error('Database credentials missing.');
}

return new Pool({
port: 5432,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
ssl: true,
});
}

export let connection: Pool;
try {
connection = main();
logger.info('Database connection successful');
} catch (err) {
logger.error(
`An error has occurred while connecting to the database:\n${err}\nThe app will be shut down.`
);
process.exit(1);
}

const combinedSchemas = {
...postSchema,
...userSchema,
};

export const db: NodePgDatabase<typeof combinedSchemas> = drizzle(connection, {
schema: combinedSchemas,
});
import { Pool } from 'pg';
import { NodePgDatabase, drizzle } from 'drizzle-orm/node-postgres';
import 'dotenv/config';

import * as postSchema from './schema/post';
import * as userSchema from './schema/user';

import logger from '../utils/logger';

function main() {
if (
!process.env.DB_HOST ||
!process.env.DB_NAME ||
!process.env.DB_USER ||
!process.env.DB_PASSWORD
) {
throw new Error('Database credentials missing.');
}

return new Pool({
port: 5432,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
ssl: true,
});
}

export let connection: Pool;
try {
connection = main();
logger.info('Database connection successful');
} catch (err) {
logger.error(
`An error has occurred while connecting to the database:\n${err}\nThe app will be shut down.`
);
process.exit(1);
}

const combinedSchemas = {
...postSchema,
...userSchema,
};

export const db: NodePgDatabase<typeof combinedSchemas> = drizzle(connection, {
schema: combinedSchemas,
});
(ran out of characters)
2 replies