- Replace ESLint with Biome for linting and formatting - Configure Biome with tabs, double quotes, and organized imports - Move all SQL/Drizzle queries from page.tsx files to data.ts files - Create new data.ts files for: ajustes, dashboard, relatorios/categorias - Update existing data.ts files: extrato, fatura (add lancamentos queries) - Remove all drizzle-orm imports from page.tsx files - Update README.md with new tooling info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
import * as fs from "node:fs";
|
|
import * as path from "node:path";
|
|
import { config } from "dotenv";
|
|
import { drizzle } from "drizzle-orm/node-postgres";
|
|
import { Pool } from "pg";
|
|
|
|
// Load environment variables from .env
|
|
config();
|
|
|
|
async function initDatabase() {
|
|
const databaseUrl = process.env.DATABASE_URL;
|
|
|
|
if (!databaseUrl) {
|
|
console.error("DATABASE_URL environment variable is required");
|
|
process.exit(1);
|
|
}
|
|
|
|
const pool = new Pool({ connectionString: databaseUrl });
|
|
const db = drizzle(pool);
|
|
|
|
try {
|
|
console.log("🔧 Initializing database extensions...");
|
|
|
|
// Read and execute init.sql as a single query
|
|
const initSqlPath = path.join(
|
|
process.cwd(),
|
|
"scripts",
|
|
"postgres",
|
|
"init.sql",
|
|
);
|
|
const initSql = fs.readFileSync(initSqlPath, "utf-8");
|
|
|
|
console.log("Executing init.sql...");
|
|
await db.execute(initSql);
|
|
|
|
console.log("✅ Database initialization completed");
|
|
} catch (error) {
|
|
console.error("❌ Database initialization failed:", error);
|
|
process.exit(1);
|
|
} finally {
|
|
await pool.end();
|
|
}
|
|
}
|
|
|
|
initDatabase();
|