Files
zellyy-finance/src/lib/supabase/setup/status.ts
gpt-engineer-app[bot] f335a381e3 Refactor Supabase setup file
Refactor src/lib/supabase/setup.ts into smaller files for better maintainability and readability.
2025-03-15 13:10:22 +00:00

69 lines
1.6 KiB
TypeScript

import { supabase } from '../client';
/**
* 테이블 상태를 확인합니다.
*/
export const checkTablesStatus = async (): Promise<{
transactions: boolean;
budgets: boolean;
tests: boolean;
}> => {
const tables = {
transactions: false,
budgets: false,
tests: false
};
try {
// transactions 테이블 확인
const { count: transactionsCount, error: transactionsError } = await supabase
.from('transactions')
.select('*', { count: 'exact', head: true });
tables.transactions = !transactionsError;
// budgets 테이블 확인
const { count: budgetsCount, error: budgetsError } = await supabase
.from('budgets')
.select('*', { count: 'exact', head: true });
tables.budgets = !budgetsError;
// _tests 테이블 확인
const { count: testsCount, error: testsError } = await supabase
.from('_tests')
.select('*', { count: 'exact', head: true });
tables.tests = !testsError;
return tables;
} catch (error) {
console.error('테이블 상태 확인 중 오류 발생:', error);
return tables;
}
};
/**
* 기존 테이블 목록을 가져옵니다.
*/
export const getExistingTables = async (): Promise<string[] | null> => {
try {
const { data, error } = await supabase.rpc('get_tables');
if (error) {
console.error('테이블 목록 가져오기 실패:', error);
return null;
}
if (Array.isArray(data)) {
return data.map(t => t.name);
}
return [];
} catch (error) {
console.error('테이블 목록 확인 중 오류 발생:', error);
return null;
}
};