fix: correct ComputerNmae typo to ComputerName in BIPUsers DAO
- Fix column name typo in BIP_USERS_CONFIG constant - Update SQL queries to use correct ComputerName column - Add migration scripts for database schema fix (JS and SQL) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
142
scripts/fix-computer-name-typo.js
Normal file
142
scripts/fix-computer-name-typo.js
Normal file
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* Fix ComputerNmae Typo in dbo_BIPUsers Table
|
||||
*
|
||||
* This script renames the column from 'ComputerNmae' to 'ComputerName'
|
||||
*/
|
||||
|
||||
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 column name
|
||||
console.log('=== Step 1: Check current column name ===')
|
||||
const [columns] = await connection.execute(`
|
||||
SELECT
|
||||
COLUMN_NAME,
|
||||
COLUMN_TYPE,
|
||||
IS_NULLABLE,
|
||||
CHARACTER_MAXIMUM_LENGTH,
|
||||
COLUMN_KEY,
|
||||
COLUMN_DEFAULT,
|
||||
EXTRA
|
||||
FROM
|
||||
INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE
|
||||
TABLE_NAME = 'dbo_BIPUsers'
|
||||
AND TABLE_SCHEMA = DATABASE()
|
||||
AND (COLUMN_NAME = 'ComputerNmae' OR COLUMN_NAME = 'ComputerName')
|
||||
ORDER BY
|
||||
ORDINAL_POSITION
|
||||
`)
|
||||
|
||||
if (columns.length === 0) {
|
||||
console.log('No ComputerNmae or ComputerName column found!')
|
||||
return
|
||||
}
|
||||
|
||||
console.table(columns)
|
||||
|
||||
const currentColumn = columns.find((col) => col.COLUMN_NAME === 'ComputerNmae')
|
||||
const newColumn = columns.find((col) => col.COLUMN_NAME === 'ComputerName')
|
||||
|
||||
if (newColumn) {
|
||||
console.log('\n=== Column is already named "ComputerName"! No modification needed. ===')
|
||||
return
|
||||
}
|
||||
|
||||
if (!currentColumn) {
|
||||
console.log('\n=== ERROR: ComputerNmae column not found! ===')
|
||||
return
|
||||
}
|
||||
|
||||
// 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_BIPUsers')
|
||||
console.log(`Total records: ${countBefore[0].total}`)
|
||||
|
||||
// Step 3: Show sample data with the column
|
||||
console.log('\n=== Step 3: Sample data (showing ComputerNmae column) ===')
|
||||
const [sample] = await connection.execute(`
|
||||
SELECT ID, UserName, UserType, ComputerNmae, CreateTime
|
||||
FROM dbo_BIPUsers
|
||||
LIMIT 5
|
||||
`)
|
||||
console.table(sample)
|
||||
|
||||
// Step 4: Rename the column
|
||||
console.log('\n=== Step 4: Renaming column ComputerNmae -> ComputerName ===')
|
||||
await connection.execute(`
|
||||
ALTER TABLE dbo_BIPUsers
|
||||
CHANGE COLUMN ComputerNmae ComputerName VARCHAR(255) NULL
|
||||
`)
|
||||
console.log('Column renamed successfully!\n')
|
||||
|
||||
// Step 5: Verify the change
|
||||
console.log('=== Step 5: Verify modification ===')
|
||||
const [columnsAfter] = await connection.execute(`
|
||||
SELECT
|
||||
COLUMN_NAME,
|
||||
COLUMN_TYPE,
|
||||
IS_NULLABLE,
|
||||
CHARACTER_MAXIMUM_LENGTH,
|
||||
COLUMN_KEY,
|
||||
COLUMN_DEFAULT,
|
||||
EXTRA
|
||||
FROM
|
||||
INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE
|
||||
TABLE_NAME = 'dbo_BIPUsers'
|
||||
AND TABLE_SCHEMA = DATABASE()
|
||||
AND COLUMN_NAME = 'ComputerName'
|
||||
`)
|
||||
console.table(columnsAfter)
|
||||
|
||||
// Step 6: Verify data is still intact
|
||||
console.log('\n=== Step 6: Verify data integrity ===')
|
||||
const [countAfter] = await connection.execute('SELECT COUNT(*) AS total FROM dbo_BIPUsers')
|
||||
console.log(`Total records after modification: ${countAfter[0].total}`)
|
||||
|
||||
// Step 7: Show sample data with new column name
|
||||
console.log('\n=== Step 7: Sample data (showing ComputerName column) ===')
|
||||
const [sampleAfter] = await connection.execute(`
|
||||
SELECT ID, UserName, UserType, ComputerName, CreateTime
|
||||
FROM dbo_BIPUsers
|
||||
LIMIT 5
|
||||
`)
|
||||
console.table(sampleAfter)
|
||||
|
||||
if (countBefore[0].total === countAfter[0].total) {
|
||||
console.log(
|
||||
'\n✅ SUCCESS: All data preserved, column renamed from ComputerNmae to ComputerName!'
|
||||
)
|
||||
} 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()
|
||||
13
scripts/fix-computer-name-typo.sql
Normal file
13
scripts/fix-computer-name-typo.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
-- Migration script to fix ComputerNmae typo in dbo_BIPUsers table
|
||||
-- Changes column name from 'ComputerNmae' to 'ComputerName'
|
||||
-- Date: 2026-03-05
|
||||
|
||||
-- Rename the column (MySQL syntax)
|
||||
ALTER TABLE dbo_BIPUsers
|
||||
CHANGE COLUMN ComputerNmae ComputerName VARCHAR(255) NULL;
|
||||
|
||||
-- Verify the change
|
||||
SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE
|
||||
FROM INFORMATION_SCHEMA.COLUMNS
|
||||
WHERE TABLE_NAME = 'dbo_BIPUsers'
|
||||
AND COLUMN_NAME = 'ComputerName';
|
||||
@@ -27,7 +27,7 @@ export const BIP_USERS_CONFIG = {
|
||||
USERNAME: 'UserName',
|
||||
USER_TYPE: 'UserType',
|
||||
PASSWORD: 'Password',
|
||||
COMPUTER_NAME: 'ComputerNmae', // Note: typo in database schema
|
||||
COMPUTER_NAME: 'ComputerName',
|
||||
CREATE_TIME: 'CreateTime'
|
||||
}
|
||||
} as const
|
||||
@@ -173,7 +173,7 @@ export class BIPUsersDAO {
|
||||
const sqlString = `
|
||||
SELECT ID, UserName, UserType
|
||||
FROM ${tableName}
|
||||
WHERE ComputerNmae = @computerName
|
||||
WHERE ComputerName = @computerName
|
||||
`
|
||||
|
||||
const result = await (dbService as SqlServerService).queryWithParams(sqlString, {
|
||||
@@ -193,7 +193,7 @@ export class BIPUsersDAO {
|
||||
const sqlString = `
|
||||
SELECT ID, UserName, UserType
|
||||
FROM ${tableName}
|
||||
WHERE ComputerNmae = ?
|
||||
WHERE ComputerName = ?
|
||||
`
|
||||
|
||||
const result = await (dbService as MySqlService).query(sqlString, [computerName])
|
||||
@@ -277,7 +277,7 @@ export class BIPUsersDAO {
|
||||
if (computerName) {
|
||||
sqlString = `
|
||||
INSERT INTO ${tableName}
|
||||
(UserName, Password, UserType, ComputerNmae)
|
||||
(UserName, Password, UserType, ComputerName)
|
||||
VALUES (@username, @password, @userType, @computerName)
|
||||
`
|
||||
params = {
|
||||
@@ -308,7 +308,7 @@ export class BIPUsersDAO {
|
||||
if (computerName) {
|
||||
sqlString = `
|
||||
INSERT INTO ${tableName}
|
||||
(UserName, Password, UserType, ComputerNmae)
|
||||
(UserName, Password, UserType, ComputerName)
|
||||
VALUES (?, ?, ?, ?)
|
||||
`
|
||||
params = [username, password, userType, computerName]
|
||||
|
||||
Reference in New Issue
Block a user