deep-sql-debug.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'dotenv/config';
  2. import { Pool } from 'pg';
  3. async function debugInsert() {
  4. const pool = new Pool({
  5. connectionString: process.env.DATABASE_URL,
  6. });
  7. console.log('🚀 Starting Deep SQL Debugging...');
  8. const testData = {
  9. filename: 'test-video.mp4',
  10. storageKey: `uploads/${Date.now()}-test.mp4`,
  11. mimeType: 'video/mp4',
  12. size: 1024, // Using number first
  13. status: 'pending'
  14. };
  15. try {
  16. console.log('\n--- Test 1: Basic Insert with Number for size ---');
  17. const res1 = await pool.query(
  18. `INSERT INTO media (filename, storage_key, mime_type, size, status)
  19. VALUES ($1, $2, $3, $4, $5) RETURNING id`,
  20. [testData.filename, testData.storageKey, testData.mimeType, testData.size, testData.status]
  21. );
  22. console.log('✅ Success! ID:', res1.rows[0].id);
  23. console.log('\n--- Test 2: Insert with BigInt string for size ---');
  24. const res2 = await pool.query(
  25. `INSERT INTO media (filename, storage_key, mime_type, size, status)
  26. VALUES ($1, $2, $3, $4, $5) RETURNING id`,
  27. [testData.filename, testData.storageKey, testData.mimeType, '1024', testData.status]
  28. );
  29. console.log('✅ Success! ID:', res2.rows[0].id);
  30. console.log('\n--- Test 3: Insert with actual BigInt ---');
  31. const res3 = await pool.query(
  32. `INSERT INTO media (filename, storage_key, mime_type, size, status)
  33. VALUES ($1, $2, $3, $4, $5) RETURNING id`,
  34. [testData.filename, testData.storageKey, testData.mimeType, BigInt(testData.size), testData.status]
  35. );
  36. console.log('✅ Success! ID:', res3.rows[0].id);
  37. } catch (err: any) {
  38. console.error('\n❌ SQL Error Detected!');
  39. console.error('Message:', err.message);
  40. console.error('Code:', err.code);
  41. console.error('Detail:', err.detail);
  42. console.error('Hint:', err.hint);
  43. console.error('Table:', err.table);
  44. } finally {
  45. await pool.end();
  46. }
  47. }
  48. debugInsert();