Fix database schema compatibility - remove invalid fields
- Remove id, created_at, updated_at from client-side fileData - Extract only valid database fields in addFile and updateFile functions - Let database handle UUID generation and timestamps automatically - Clean separation between client data structure and database schema - Fix persistent createdAt column error by filtering client-side fields This should resolve: "Could not find the 'createdAt' column of 'files' in the schema cache" 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
13
script.js
13
script.js
@@ -433,11 +433,12 @@ class FileManager {
|
|||||||
|
|
||||||
// localStorage 폴백 메서드들
|
// localStorage 폴백 메서드들
|
||||||
addFileLocally(fileData) {
|
addFileLocally(fileData) {
|
||||||
// 로컬 저장시에도 올바른 컬럼명 사용
|
// 로컬 저장용 데이터 생성 (ID와 타임스탬프 추가)
|
||||||
const localFileData = {
|
const localFileData = {
|
||||||
|
id: this.generateId(),
|
||||||
...fileData,
|
...fileData,
|
||||||
created_at: fileData.created_at || new Date().toISOString(),
|
created_at: new Date().toISOString(),
|
||||||
updated_at: fileData.updated_at || new Date().toISOString()
|
updated_at: new Date().toISOString()
|
||||||
};
|
};
|
||||||
|
|
||||||
this.files.push(localFileData);
|
this.files.push(localFileData);
|
||||||
@@ -445,6 +446,7 @@ class FileManager {
|
|||||||
this.renderFiles();
|
this.renderFiles();
|
||||||
this.updateEmptyState();
|
this.updateEmptyState();
|
||||||
this.showNotification('새 자료가 성공적으로 추가되었습니다! (로컬 저장)', 'success');
|
this.showNotification('새 자료가 성공적으로 추가되었습니다! (로컬 저장)', 'success');
|
||||||
|
this.clearForm(); // 폼 초기화
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFileLocally(id, updates) {
|
updateFileLocally(id, updates) {
|
||||||
@@ -635,14 +637,11 @@ class FileManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fileData = {
|
const fileData = {
|
||||||
id: this.generateId(),
|
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
category,
|
category,
|
||||||
tags,
|
tags,
|
||||||
files: [],
|
files: [] // 첨부파일 임시 저장용 (Supabase 전송시 제외됨)
|
||||||
created_at: new Date().toISOString(),
|
|
||||||
updated_at: new Date().toISOString()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (fileInput.files.length > 0) {
|
if (fileInput.files.length > 0) {
|
||||||
|
@@ -122,12 +122,19 @@ const SupabaseHelper = {
|
|||||||
async addFile(fileData, userId) {
|
async addFile(fileData, userId) {
|
||||||
if (!supabase) throw new Error('Supabase가 초기화되지 않았습니다.');
|
if (!supabase) throw new Error('Supabase가 초기화되지 않았습니다.');
|
||||||
|
|
||||||
|
// 데이터베이스 스키마에 맞는 필드만 추출
|
||||||
|
const dbFileData = {
|
||||||
|
title: fileData.title,
|
||||||
|
description: fileData.description || '',
|
||||||
|
category: fileData.category,
|
||||||
|
tags: fileData.tags || [],
|
||||||
|
user_id: userId
|
||||||
|
// created_at, updated_at은 데이터베이스에서 자동 생성
|
||||||
|
};
|
||||||
|
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from('files')
|
.from('files')
|
||||||
.insert([{
|
.insert([dbFileData])
|
||||||
...fileData,
|
|
||||||
user_id: userId
|
|
||||||
}])
|
|
||||||
.select()
|
.select()
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
@@ -139,12 +146,18 @@ const SupabaseHelper = {
|
|||||||
async updateFile(id, updates, userId) {
|
async updateFile(id, updates, userId) {
|
||||||
if (!supabase) throw new Error('Supabase가 초기화되지 않았습니다.');
|
if (!supabase) throw new Error('Supabase가 초기화되지 않았습니다.');
|
||||||
|
|
||||||
|
// 데이터베이스 스키마에 맞는 필드만 추출
|
||||||
|
const dbUpdates = {
|
||||||
|
title: updates.title,
|
||||||
|
description: updates.description,
|
||||||
|
category: updates.category,
|
||||||
|
tags: updates.tags || []
|
||||||
|
// updated_at은 트리거에 의해 자동 업데이트됨
|
||||||
|
};
|
||||||
|
|
||||||
const { data, error } = await supabase
|
const { data, error } = await supabase
|
||||||
.from('files')
|
.from('files')
|
||||||
.update({
|
.update(dbUpdates)
|
||||||
...updates,
|
|
||||||
updated_at: new Date().toISOString()
|
|
||||||
})
|
|
||||||
.eq('id', id)
|
.eq('id', id)
|
||||||
.eq('user_id', userId)
|
.eq('user_id', userId)
|
||||||
.select()
|
.select()
|
||||||
|
Reference in New Issue
Block a user