fix(db-tools): resolve REINDEX transaction error by executing directly via pg client, and dynamically support all database tables in integrity dashboard
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { verifyAdmin } from '@/lib/actions/auth'
|
||||
import { Client } from 'pg'
|
||||
|
||||
export async function getDatabaseIntegrity() {
|
||||
try {
|
||||
@@ -36,12 +37,20 @@ export async function repairDatabaseSchema() {
|
||||
export async function optimizeDatabaseIndices() {
|
||||
try {
|
||||
await verifyAdmin()
|
||||
const supabase = await createClient()
|
||||
const { data, error } = await supabase.rpc('optimize_database_indices')
|
||||
if (error) {
|
||||
return { success: false, error: error.message }
|
||||
}
|
||||
return { success: true, data }
|
||||
|
||||
// REINDEX cannot be run inside a transaction block (such as inside a PL/pgSQL function).
|
||||
// Therefore, we connect directly using pg client and execute raw query.
|
||||
const connectionString = process.env.DATABASE_URL || 'postgresql://postgres:postgres@localhost:54322/postgres';
|
||||
const client = new Client({
|
||||
connectionString,
|
||||
connectionTimeoutMillis: 10000,
|
||||
});
|
||||
|
||||
await client.connect();
|
||||
await client.query('REINDEX SCHEMA public;');
|
||||
await client.end();
|
||||
|
||||
return { success: true }
|
||||
} catch (err: any) {
|
||||
console.error("Error in optimizeDatabaseIndices:", err)
|
||||
return { success: false, error: err.message || "Unerwarteter Fehler bei der Indexoptimierung." }
|
||||
|
||||
Reference in New Issue
Block a user