feat: add postgres config and migration route

This commit is contained in:
2026-03-16 07:20:08 -03:00
parent cf90973671
commit ede8c21c8d
5 changed files with 237 additions and 1 deletions

View File

@@ -35,7 +35,44 @@ app.use(extractUser);
// Static Uploads
app.use('/uploads', express.static(path.join(process.cwd(), 'uploads')));
// Routes
import pool from '../src/server/config/postgres.js';
// ... (existing routes)
app.get('/api/admin/migrate-to-gpi', async (req, res) => {
const TABLES = [
"organizations",
"users",
"user_organizations",
"projects",
"parts",
"painting_schemes",
"inspections",
"instruments",
"stock_items",
"stock_movements"
];
try {
const client = await pool.connect();
await client.query("CREATE SCHEMA IF NOT EXISTS gpi;");
const results = [];
for (const table of TABLES) {
try {
await client.query(`ALTER TABLE public.${table} SET SCHEMA gpi;`);
results.push({ table, status: 'success' });
} catch (err: any) {
results.push({ table, status: 'failed', error: err.message });
}
}
client.release();
res.json({ message: "Migration completed", results });
} catch (error: any) {
res.status(500).json({ error: error.message });
}
});
app.use('/api/auth', authRoutes);
app.use('/api/users', userRoutes);
app.use('/api/projects', projectRoutes);