#!/usr/bin/env tsx
import { readFileSync } from 'fs';
import { join } from 'path';
import { supabase } from './client.js';
async function testInsert(): Promise<void> {
console.log('π§ͺ Testing simple insert...');
const serviceClient = supabase.getServiceClient();
try {
// Test with a simple style record
const testStyle = {
id: 'TEST01',
name: 'Test Style',
industry: 'Test',
style_dna: { test: 'value' },
dos: ['Test do'],
donts: ['Test dont'],
tokens: 'test tokens',
raw_length: 100,
businesses: ['Test Business'],
category: 'test',
category_label: 'Test Category'
};
console.log('π€ Inserting test style:', testStyle);
const { data, error } = await serviceClient
.from('design_styles')
.insert(testStyle)
.select();
if (error) {
console.error('β Insert error:', error);
console.error('Error details:', JSON.stringify(error, null, 2));
} else {
console.log('β
Insert successful:', data);
// Now delete the test record
const { error: deleteError } = await serviceClient
.from('design_styles')
.delete()
.eq('id', 'TEST01');
if (deleteError) {
console.error('β οΈ Could not delete test record:', deleteError);
} else {
console.log('ποΈ Test record deleted');
}
}
} catch (error) {
console.error('π₯ Test failed:', error);
}
}
async function inspectSchema(): Promise<void> {
console.log('π Inspecting table schema...');
const client = supabase.getAnonClient();
try {
// Try to get existing records to understand the schema
const { data, error } = await client
.from('design_styles')
.select('*')
.limit(1);
if (error) {
console.error('β Schema inspection error:', error);
} else {
console.log('β
Schema inspection:', data);
if (data && data.length > 0) {
console.log('π Example record structure:', Object.keys(data[0]));
} else {
console.log('π Table is empty');
}
}
} catch (error) {
console.error('π₯ Schema inspection failed:', error);
}
}
async function main(): Promise<void> {
console.log('π Starting diagnostic tests...');
try {
const isConnected = await supabase.testConnection();
if (!isConnected) {
throw new Error('Failed to connect to Supabase');
}
await inspectSchema();
await testInsert();
console.log('π Diagnostic tests completed!');
} catch (error) {
console.error('π₯ Diagnostic failed:', error);
process.exit(1);
}
}
if (import.meta.url === `file://${process.argv[1]}`) {
main();
}