feat: add material type management feature

- Add MaterialTypeManagementDialog component for managing material type keywords
- Add MaterialsTypeToBeDeletedDAO for database operations
- Add material-type-handler IPC handlers
- Update CleanerPage with type management button
- Add database fix scripts for AUTO_INCREMENT
- Update documentation for settings partial save and validation flow

Co-Authored-By: Claude (glm-5) <noreply@anthropic.com>
This commit is contained in:
Misaka
2026-03-03 22:51:11 +08:00
parent 7aa1abbc22
commit e23cf71f78
23 changed files with 1764 additions and 213 deletions

View File

@@ -0,0 +1,117 @@
/**
* Fix MaterialsTypeToBeDeleted Table - Add AUTO_INCREMENT to ID
*
* This script modifies the ID column to be AUTO_INCREMENT while preserving data
*/
const mysql = require('mysql2/promise');
async function main() {
const config = {
host: '192.168.31.83',
port: 3306,
user: 'remote_user',
password: '3.1415926Beeke',
database: 'BLD_DB'
};
let connection;
try {
console.log('Connecting to MySQL...');
connection = await mysql.createConnection(config);
console.log('Connected successfully!\n');
// Step 1: Check current table structure
console.log('=== Step 1: Current table structure ===');
const [columns] = await connection.execute(`
SELECT
COLUMN_NAME,
COLUMN_TYPE,
IS_NULLABLE,
COLUMN_KEY,
COLUMN_DEFAULT,
EXTRA
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'dbo_MaterialsTypeToBeDeleted'
AND TABLE_SCHEMA = DATABASE()
ORDER BY
ORDINAL_POSITION
`);
console.table(columns);
// Step 2: Count records before modification
console.log('\n=== Step 2: Record count before modification ===');
const [countBefore] = await connection.execute(
'SELECT COUNT(*) AS total FROM dbo_MaterialsTypeToBeDeleted'
);
console.log(`Total records: ${countBefore[0].total}`);
// Step 3: Show sample data
console.log('\n=== Step 3: Sample data ===');
const [sample] = await connection.execute(
'SELECT * FROM dbo_MaterialsTypeToBeDeleted LIMIT 5'
);
console.table(sample);
// Step 4: Check if ID is already AUTO_INCREMENT
const idColumn = columns.find((col) => col.COLUMN_NAME === 'ID');
if (idColumn && idColumn.EXTRA.includes('auto_increment')) {
console.log('\n=== ID is already AUTO_INCREMENT! No modification needed. ===');
return;
}
// Step 5: Modify the ID column
console.log('\n=== Step 4: Modifying ID column to AUTO_INCREMENT ===');
await connection.execute(`
ALTER TABLE dbo_MaterialsTypeToBeDeleted
MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT
`);
console.log('Modification completed successfully!\n');
// Step 6: Verify the change
console.log('=== Step 5: Verify modification ===');
const [columnsAfter] = await connection.execute(`
SELECT
COLUMN_NAME,
COLUMN_TYPE,
IS_NULLABLE,
COLUMN_KEY,
EXTRA
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'dbo_MaterialsTypeToBeDeleted'
AND TABLE_SCHEMA = DATABASE()
AND COLUMN_NAME = 'ID'
`);
console.table(columnsAfter);
// Step 7: Verify data is still intact
console.log('\n=== Step 6: Verify data integrity ===');
const [countAfter] = await connection.execute(
'SELECT COUNT(*) AS total FROM dbo_MaterialsTypeToBeDeleted'
);
console.log(`Total records after modification: ${countAfter[0].total}`);
if (countBefore[0].total === countAfter[0].total) {
console.log('\n✅ SUCCESS: All data preserved, AUTO_INCREMENT added to ID column!');
} else {
console.log('\n⚠ WARNING: Record count changed! Please check data.');
}
} catch (error) {
console.error('\n❌ Error:', error.message);
if (error.code) {
console.error('Error code:', error.code);
}
} finally {
if (connection) {
await connection.end();
console.log('\nConnection closed.');
}
}
}
main();

View File

@@ -0,0 +1,82 @@
-- ============================================================================
-- Script: Fix MaterialsTypeToBeDeleted Table - Add AUTO_INCREMENT to ID
-- Description: Modify the ID column to be AUTO_INCREMENT while preserving data
-- Database: MySQL
-- ============================================================================
-- Step 1: Check current table structure
SELECT
COLUMN_NAME,
COLUMN_TYPE,
IS_NULLABLE,
COLUMN_KEY,
COLUMN_DEFAULT,
EXTRA
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'dbo_MaterialsTypeToBeDeleted'
AND TABLE_SCHEMA = DATABASE()
ORDER BY
ORDINAL_POSITION;
-- Step 2: View current data before modification
SELECT COUNT(*) AS total_records FROM dbo_MaterialsTypeToBeDeleted;
SELECT * FROM dbo_MaterialsTypeToBeDeleted LIMIT 10;
-- Step 3: Check if ID is already AUTO_INCREMENT
SELECT
COLUMN_NAME,
EXTRA
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'dbo_MaterialsTypeToBeDeleted'
AND TABLE_SCHEMA = DATABASE()
AND COLUMN_NAME = 'ID';
-- ============================================================================
-- Step 4: Modify the ID column to AUTO_INCREMENT
-- Note: This assumes ID is already the PRIMARY KEY
-- If not, you may need to add PRIMARY KEY constraint first
-- ============================================================================
-- Option A: If ID is already PRIMARY KEY (most likely case)
ALTER TABLE dbo_MaterialsTypeToBeDeleted
MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT;
-- Option B: If ID is NOT PRIMARY KEY (uncomment if needed)
-- First check if there's an existing primary key
-- SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
-- WHERE TABLE_NAME = 'dbo_MaterialsTypeToBeDeleted'
-- AND TABLE_SCHEMA = DATABASE() AND COLUMN_KEY = 'PRI';
--
-- If no primary key exists:
-- ALTER TABLE dbo_MaterialsTypeToBeDeleted
-- MODIFY COLUMN ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
-- Step 5: Verify the change
SELECT
COLUMN_NAME,
COLUMN_TYPE,
IS_NULLABLE,
COLUMN_KEY,
EXTRA
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'dbo_MaterialsTypeToBeDeleted'
AND TABLE_SCHEMA = DATABASE()
AND COLUMN_NAME = 'ID';
-- Step 6: Verify data is still intact
SELECT COUNT(*) AS total_records_after FROM dbo_MaterialsTypeToBeDeleted;
-- ============================================================================
-- Expected Results:
-- After running this script, the ID column should show:
-- EXTRA: 'auto_increment'
--
-- This will allow INSERT statements to omit the ID field, and MySQL will
-- automatically generate the next sequential ID value.
-- ============================================================================