veltrixcode commited on
Commit
ffd237a
·
verified ·
1 Parent(s): 33094e5

Update db.js

Browse files
Files changed (1) hide show
  1. db.js +12 -5
db.js CHANGED
@@ -57,7 +57,7 @@ async function initializeDatabase() {
57
  gc_code VARCHAR(255) NOT NULL,
58
  gc_phone VARCHAR(255) NOT NULL,
59
  ticket_number VARCHAR(255) NOT NULL,
60
- upi_id VARCHAR(255) NOT NULL,
61
  amount DECIMAL(10,2) NOT NULL,
62
  proof_video_url TEXT NOT NULL,
63
  status VARCHAR(50) NOT NULL DEFAULT 'pending',
@@ -87,11 +87,18 @@ async function initializeDatabase() {
87
  )
88
  `);
89
 
90
- // Add indexes for better chat performance
91
  await pool.query(`
92
- CREATE INDEX IF NOT EXISTS idx_messages_user_id ON messages(user_id);
93
- CREATE INDEX IF NOT EXISTS idx_messages_created_at ON messages(created_at);
94
- CREATE INDEX IF NOT EXISTS idx_messages_user_created ON messages(user_id, created_at);
 
 
 
 
 
 
 
95
  `);
96
 
97
  console.log('Database tables initialized successfully');
 
57
  gc_code VARCHAR(255) NOT NULL,
58
  gc_phone VARCHAR(255) NOT NULL,
59
  ticket_number VARCHAR(255) NOT NULL,
60
+ payment_address VARCHAR(255) NOT NULL,
61
  amount DECIMAL(10,2) NOT NULL,
62
  proof_video_url TEXT NOT NULL,
63
  status VARCHAR(50) NOT NULL DEFAULT 'pending',
 
87
  )
88
  `);
89
 
90
+ // Migration: Rename upi_id to payment_address if needed
91
  await pool.query(`
92
+ DO $$
93
+ BEGIN
94
+ IF EXISTS (
95
+ SELECT 1 FROM information_schema.columns
96
+ WHERE table_name='submissions' AND column_name='upi_id'
97
+ ) THEN
98
+ EXECUTE 'ALTER TABLE submissions RENAME COLUMN upi_id TO payment_address';
99
+ END IF;
100
+ END
101
+ $$;
102
  `);
103
 
104
  console.log('Database tables initialized successfully');