Refactor Supabase setup file
Refactor src/lib/supabase/setup.ts into smaller files for better maintainability and readability.
This commit is contained in:
59
src/lib/supabase/setup/index.ts
Normal file
59
src/lib/supabase/setup/index.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
import { createTransactionsTable, createBudgetsTable, createTestsTable } from './tables';
|
||||
import { checkTablesStatus, getExistingTables } from './status';
|
||||
|
||||
/**
|
||||
* Supabase 데이터베이스에 필요한 테이블을 생성합니다.
|
||||
* 이 함수는 로그인 후 실행되어야 합니다.
|
||||
*/
|
||||
export const createRequiredTables = async (): Promise<{ success: boolean; message: string }> => {
|
||||
try {
|
||||
console.log('데이터베이스 테이블 생성 시작...');
|
||||
|
||||
// 테이블이 이미 존재하는지 확인
|
||||
const existingTables = await getExistingTables();
|
||||
|
||||
if (existingTables !== null) {
|
||||
console.log('기존 테이블:', existingTables);
|
||||
|
||||
// 이미 테이블이 존재하는 경우
|
||||
if (existingTables.includes('transactions') && existingTables.includes('budgets')) {
|
||||
return {
|
||||
success: true,
|
||||
message: '필요한 테이블이 이미 존재합니다.'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 필요한 테이블 생성
|
||||
const transactionsResult = await createTransactionsTable();
|
||||
if (!transactionsResult.success) {
|
||||
return transactionsResult;
|
||||
}
|
||||
|
||||
const budgetsResult = await createBudgetsTable();
|
||||
if (!budgetsResult.success) {
|
||||
return budgetsResult;
|
||||
}
|
||||
|
||||
// 테스트 테이블은 선택적으로 생성 (실패해도 진행)
|
||||
const testsResult = await createTestsTable();
|
||||
if (!testsResult.success) {
|
||||
console.warn('테스트 테이블 생성 실패 (무시됨):', testsResult.message);
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: '모든 필수 테이블이 성공적으로 생성되었습니다.'
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('테이블 생성 중 오류 발생:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: `테이블 생성 실패: ${error.message || '알 수 없는 오류'}`
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 기존 checkTablesStatus 함수 내보내기
|
||||
export { checkTablesStatus };
|
||||
Reference in New Issue
Block a user