Add stock pricelist admin flow with mapping placeholders and warehouse details
This commit is contained in:
14
migrations/014_add_stock_log.sql
Normal file
14
migrations/014_add_stock_log.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE TABLE IF NOT EXISTS stock_log (
|
||||
stock_log_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
lot VARCHAR(255) NOT NULL,
|
||||
supplier VARCHAR(255) NULL,
|
||||
date DATE NOT NULL,
|
||||
price DECIMAL(12,2) NOT NULL,
|
||||
quality VARCHAR(255) NULL,
|
||||
comments TEXT NULL,
|
||||
vendor VARCHAR(255) NULL,
|
||||
qty DECIMAL(14,3) NULL,
|
||||
INDEX idx_stock_log_lot_date (lot, date),
|
||||
INDEX idx_stock_log_date (date),
|
||||
INDEX idx_stock_log_vendor (vendor)
|
||||
);
|
||||
7
migrations/015_add_lot_partnumbers.sql
Normal file
7
migrations/015_add_lot_partnumbers.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE IF NOT EXISTS lot_partnumbers (
|
||||
partnumber VARCHAR(255) NOT NULL,
|
||||
lot_name VARCHAR(255) NOT NULL DEFAULT '',
|
||||
description VARCHAR(10000) NULL,
|
||||
PRIMARY KEY (partnumber, lot_name),
|
||||
INDEX idx_lot_partnumbers_lot_name (lot_name)
|
||||
);
|
||||
25
migrations/016_add_price_level_pricelist_bindings.sql
Normal file
25
migrations/016_add_price_level_pricelist_bindings.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- Add per-source pricelist bindings for configurations
|
||||
ALTER TABLE qt_configurations
|
||||
ADD COLUMN IF NOT EXISTS warehouse_pricelist_id BIGINT UNSIGNED NULL AFTER pricelist_id,
|
||||
ADD COLUMN IF NOT EXISTS competitor_pricelist_id BIGINT UNSIGNED NULL AFTER warehouse_pricelist_id,
|
||||
ADD COLUMN IF NOT EXISTS disable_price_refresh BOOLEAN NOT NULL DEFAULT FALSE AFTER competitor_pricelist_id;
|
||||
|
||||
ALTER TABLE qt_configurations
|
||||
ADD INDEX IF NOT EXISTS idx_qt_configurations_warehouse_pricelist_id (warehouse_pricelist_id),
|
||||
ADD INDEX IF NOT EXISTS idx_qt_configurations_competitor_pricelist_id (competitor_pricelist_id);
|
||||
|
||||
-- Optional FK bindings (safe if re-run due IF NOT EXISTS on columns/indexes)
|
||||
-- If your MariaDB version does not support IF NOT EXISTS for FK names, duplicate-FK errors are ignored by migration runner.
|
||||
ALTER TABLE qt_configurations
|
||||
ADD CONSTRAINT fk_qt_configurations_warehouse_pricelist_id
|
||||
FOREIGN KEY (warehouse_pricelist_id)
|
||||
REFERENCES qt_pricelists(id)
|
||||
ON DELETE RESTRICT
|
||||
ON UPDATE CASCADE;
|
||||
|
||||
ALTER TABLE qt_configurations
|
||||
ADD CONSTRAINT fk_qt_configurations_competitor_pricelist_id
|
||||
FOREIGN KEY (competitor_pricelist_id)
|
||||
REFERENCES qt_pricelists(id)
|
||||
ON DELETE RESTRICT
|
||||
ON UPDATE CASCADE;
|
||||
25
migrations/017_update_lot_partnumbers_for_placeholders.sql
Normal file
25
migrations/017_update_lot_partnumbers_for_placeholders.sql
Normal file
@@ -0,0 +1,25 @@
|
||||
-- Allow placeholder mappings (partnumber without bound lot) and store import description.
|
||||
ALTER TABLE lot_partnumbers
|
||||
ADD COLUMN IF NOT EXISTS description VARCHAR(10000) NULL AFTER lot_name;
|
||||
|
||||
ALTER TABLE lot_partnumbers
|
||||
MODIFY COLUMN lot_name VARCHAR(255) NOT NULL DEFAULT '';
|
||||
|
||||
-- Drop FK on lot_name if it exists to allow unresolved placeholders.
|
||||
SET @lp_fk_name := (
|
||||
SELECT kcu.CONSTRAINT_NAME
|
||||
FROM information_schema.KEY_COLUMN_USAGE kcu
|
||||
WHERE kcu.TABLE_SCHEMA = DATABASE()
|
||||
AND kcu.TABLE_NAME = 'lot_partnumbers'
|
||||
AND kcu.COLUMN_NAME = 'lot_name'
|
||||
AND kcu.REFERENCED_TABLE_NAME IS NOT NULL
|
||||
LIMIT 1
|
||||
);
|
||||
SET @lp_drop_fk_sql := IF(
|
||||
@lp_fk_name IS NULL,
|
||||
'SELECT 1',
|
||||
CONCAT('ALTER TABLE lot_partnumbers DROP FOREIGN KEY `', @lp_fk_name, '`')
|
||||
);
|
||||
PREPARE lp_stmt FROM @lp_drop_fk_sql;
|
||||
EXECUTE lp_stmt;
|
||||
DEALLOCATE PREPARE lp_stmt;
|
||||
Reference in New Issue
Block a user