-- Add normalized ledger plate components without changing the tractor matching key.
|
|
SET @add_plate_no_raw = (
|
SELECT IF(
|
COUNT(*) = 0,
|
'ALTER TABLE `ledger_inspection_route` ADD COLUMN `plate_no_raw` VARCHAR(100) NULL AFTER `plate_no`',
|
'SELECT 1'
|
)
|
FROM information_schema.COLUMNS
|
WHERE TABLE_SCHEMA = DATABASE()
|
AND TABLE_NAME = 'ledger_inspection_route'
|
AND COLUMN_NAME = 'plate_no_raw'
|
);
|
PREPARE add_plate_no_raw_stmt FROM @add_plate_no_raw;
|
EXECUTE add_plate_no_raw_stmt;
|
DEALLOCATE PREPARE add_plate_no_raw_stmt;
|
|
SET @add_trailer_plate_no = (
|
SELECT IF(
|
COUNT(*) = 0,
|
'ALTER TABLE `ledger_inspection_route` ADD COLUMN `trailer_plate_no` VARCHAR(30) NULL AFTER `plate_no_raw`',
|
'SELECT 1'
|
)
|
FROM information_schema.COLUMNS
|
WHERE TABLE_SCHEMA = DATABASE()
|
AND TABLE_NAME = 'ledger_inspection_route'
|
AND COLUMN_NAME = 'trailer_plate_no'
|
);
|
PREPARE add_trailer_plate_no_stmt FROM @add_trailer_plate_no;
|
EXECUTE add_trailer_plate_no_stmt;
|
DEALLOCATE PREPARE add_trailer_plate_no_stmt;
|