refactor: centralize configuration
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import { config } from "@basango/domain/config";
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import { Pool } from "pg";
|
||||
|
||||
import { env } from "#db/config";
|
||||
import * as schema from "#db/schema";
|
||||
|
||||
const isDevelopment = process.env.NODE_ENV === "development";
|
||||
|
||||
const pool = new Pool({
|
||||
allowExitOnIdle: true,
|
||||
connectionString: env("BASANGO_DATABASE_URL"),
|
||||
connectionString: config.database.url,
|
||||
connectionTimeoutMillis: 15_000,
|
||||
idleTimeoutMillis: isDevelopment ? 5_000 : 60_000,
|
||||
max: isDevelopment ? 8 : 12,
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import path from "node:path";
|
||||
|
||||
import { loadConfig } from "@devscast/config";
|
||||
import { z } from "zod";
|
||||
|
||||
const PROJECT_DIR = path.resolve(__dirname, "../");
|
||||
|
||||
export const { env, config } = loadConfig({
|
||||
env: {
|
||||
knownKeys: [
|
||||
"BASANGO_DATABASE_URL",
|
||||
"BASANGO_SOURCE_DATABASE_HOST",
|
||||
"BASANGO_SOURCE_DATABASE_USER",
|
||||
"BASANGO_SOURCE_DATABASE_PASS",
|
||||
"BASANGO_SOURCE_DATABASE_NAME",
|
||||
] as const,
|
||||
path: path.join(PROJECT_DIR, ".env"),
|
||||
},
|
||||
schema: z.object({}),
|
||||
});
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
import { md5 } from "@basango/encryption";
|
||||
import type { SQL } from "drizzle-orm";
|
||||
import { count, desc, eq, getTableColumns, sql } from "drizzle-orm";
|
||||
import { v7 as uuidV7 } from "uuid";
|
||||
import * as uuid from "uuid";
|
||||
|
||||
import { Database } from "#db/client";
|
||||
import { getSourceIdByName } from "#db/queries/sources";
|
||||
@@ -56,7 +56,7 @@ export async function createArticle(db: Database, params: CreateArticleParams) {
|
||||
|
||||
const [result] = await db
|
||||
.insert(articles)
|
||||
.values({ id: uuidV7(), ...data })
|
||||
.values({ id: uuid.v7(), ...data })
|
||||
.returning({
|
||||
id: articles.id,
|
||||
sourceId: articles.sourceId,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DEFAULT_CATEGORY_SHARES_LIMIT, DEFAULT_TIMEZONE } from "@basango/domain/constants";
|
||||
import { ID, Publication, Publications } from "@basango/domain/models";
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { v7 as uuidV7 } from "uuid";
|
||||
import * as uuid from "uuid";
|
||||
|
||||
import { Database } from "#db/client";
|
||||
import { NotFoundError } from "#db/errors";
|
||||
@@ -32,7 +32,7 @@ export async function getSources(db: Database) {
|
||||
export async function createSource(db: Database, params: CreateSourceParams) {
|
||||
const [result] = await db
|
||||
.insert(sources)
|
||||
.values({ id: uuidV7(), ...params })
|
||||
.values({ id: uuid.v7(), ...params })
|
||||
.returning();
|
||||
|
||||
return result;
|
||||
|
||||
@@ -114,10 +114,7 @@ export const articles = pgTable(
|
||||
title: varchar({ length: 1024 }).notNull(),
|
||||
tokenStatistics: jsonb("token_statistics").$type<TokenStatistics>(),
|
||||
tsv: tsvector("tsv").generatedAlwaysAs(
|
||||
sql`(
|
||||
setweight(to_tsvector('french'::regconfig, COALESCE(title, '')::text), 'A'::"char")
|
||||
|| setweight(to_tsvector('french'::regconfig, COALESCE(body, ''::text)), 'B'::"char")
|
||||
)`,
|
||||
sql`setweight(to_tsvector('french'::regconfig, COALESCE(title, '')::text), 'A'::"char")`,
|
||||
),
|
||||
updatedAt: timestamp("updated_at"),
|
||||
},
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
/** biome-ignore-all lint/correctness/noUnusedPrivateClassMembers: false positive */
|
||||
|
||||
import { config } from "@basango/domain/config";
|
||||
import { RowDataPacket } from "mysql2/promise";
|
||||
import { Pool, PoolClient } from "pg";
|
||||
|
||||
import { env } from "#db/config";
|
||||
import { computeReadingTime } from "#db/utils/computed";
|
||||
|
||||
type SourceOptions = {
|
||||
@@ -598,13 +598,13 @@ async function main() {
|
||||
|
||||
const engine = new Engine(
|
||||
{
|
||||
database: env("BASANGO_SOURCE_DATABASE_NAME"),
|
||||
host: env("BASANGO_SOURCE_DATABASE_HOST"),
|
||||
password: env("BASANGO_SOURCE_DATABASE_PASS"),
|
||||
user: env("BASANGO_SOURCE_DATABASE_USER"),
|
||||
database: config.database.legacy.name,
|
||||
host: config.database.legacy.host,
|
||||
password: config.database.legacy.password,
|
||||
user: config.database.legacy.user,
|
||||
},
|
||||
{
|
||||
database: env("BASANGO_DATABASE_URL"),
|
||||
database: config.database.url,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bun
|
||||
|
||||
import { config } from "@basango/domain/config";
|
||||
import { Pool } from "pg";
|
||||
|
||||
import { env } from "#db/config";
|
||||
import { computeTokenStatistics } from "#db/utils/computed";
|
||||
|
||||
type ArticleRow = {
|
||||
@@ -114,7 +114,7 @@ class Engine {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const engine = new Engine(env("BASANGO_DATABASE_URL"));
|
||||
const engine = new Engine(config.database.url);
|
||||
|
||||
try {
|
||||
await engine.synchronize();
|
||||
|
||||
Reference in New Issue
Block a user