Files
kokken/scripts/alter-image-column.mjs
Alex Polo fdbc422c95 feat: add image upload functionality to MenuForm and update image handling in database
- Implemented image upload feature in MenuForm with file size validation and preview.
- Updated the API response for blocked dates to include block_date and note.
- Enhanced booking page to handle URL parameters for date and guests.
- Improved date picker component with better styling and functionality.
- Added CSS styles for a more user-friendly calendar interface.
- Created scripts to alter the image column in the database and embed images as base64.
2025-11-05 10:43:03 +01:00

39 lines
1.3 KiB
JavaScript

import mysql from 'mysql2/promise';
import dotenv from 'dotenv';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
dotenv.config({ path: path.join(__dirname, '..', '.env') });
const connection = await mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
});
console.log('🔧 Updating menus table schema...\n');
// Check current column type
const [columns] = await connection.execute(
"SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'menus' AND COLUMN_NAME = 'image'"
);
console.log(`Current image column type: ${columns[0]?.COLUMN_TYPE || 'NOT FOUND'}\n`);
// Alter column to MEDIUMTEXT to support base64 images (up to 16MB)
console.log('Changing image column to MEDIUMTEXT...');
await connection.execute('ALTER TABLE menus MODIFY COLUMN image MEDIUMTEXT');
console.log('✅ Column updated successfully!\n');
// Verify
const [newColumns] = await connection.execute(
"SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'menus' AND COLUMN_NAME = 'image'"
);
console.log(`New image column type: ${newColumns[0]?.COLUMN_TYPE}\n`);
await connection.end();
console.log('✅ Schema migration complete!');