source: add-church-booking.js@ b7d8a4d

main
Last change on this file since b7d8a4d was d8deee6, checked in by GitHub <noreply@…>, 3 months ago

Add files via upload

  • Property mode set to 100644
File size: 2.0 KB
LineĀ 
1// Church booking table migration
2require('dotenv').config();
3const { Pool } = require('pg');
4
5const pool = new Pool({
6 user: process.env.DB_USER,
7 host: process.env.DB_HOST,
8 database: process.env.DB_NAME,
9 password: process.env.DB_PASSWORD,
10 port: parseInt(process.env.DB_PORT, 10),
11 ssl: { rejectUnauthorized: false }
12});
13
14async function addChurchBookingTable() {
15 try {
16 console.log('šŸ“‹ Creating church_booking table...');
17
18 const sql = `
19 CREATE TABLE IF NOT EXISTS project.church_booking (
20 booking_id SERIAL PRIMARY KEY,
21 "date" DATE NOT NULL,
22 start_time TIME NOT NULL,
23 end_time TIME NOT NULL,
24 status VARCHAR(30) NOT NULL,
25 church_id INTEGER NOT NULL,
26 wedding_id INTEGER NOT NULL,
27 CONSTRAINT fk_cb_church FOREIGN KEY (church_id) REFERENCES project.church(church_id) ON UPDATE CASCADE ON DELETE CASCADE,
28 CONSTRAINT fk_cb_wedding FOREIGN KEY (wedding_id) REFERENCES project.wedding(wedding_id) ON UPDATE CASCADE ON DELETE CASCADE,
29 CONSTRAINT chk_cb_time CHECK (end_time > start_time)
30 );
31 `;
32
33 await pool.query(sql);
34 console.log('āœ… church_booking table created successfully!');
35 console.log('\nšŸ“Œ Church booking endpoints are now available:');
36 console.log(' GET /api/weddings/:wid/church-bookings');
37 console.log(' POST /api/weddings/:wid/church-bookings');
38 console.log(' DELETE /api/church-bookings/:id\n');
39
40 await pool.end();
41 process.exit(0);
42 } catch (err) {
43 console.error('āŒ Error creating table:');
44 console.error(err.message);
45 console.error('\nNote: Table might already exist. Check with your database client.\n');
46 await pool.end();
47 process.exit(1);
48 }
49}
50
51addChurchBookingTable();
Note: See TracBrowser for help on using the repository browser.