-- Fix for reg_ip column truncation issue
-- Problem: IPv6 addresses are 39-45 characters, but reg_ip column is too small
-- Solution: Increase reg_ip column size to VARCHAR(45)

USE [SRO_VT_ACCOUNT];
GO

-- Check current column definition
SELECT
    COLUMN_NAME,
    DATA_TYPE,
    CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'dbo'
  AND TABLE_NAME = 'TB_User'
  AND COLUMN_NAME = 'reg_ip';
GO

-- Alter the column to support IPv6 addresses
ALTER TABLE [dbo].[TB_User]
ALTER COLUMN [reg_ip] VARCHAR(45) NULL;
GO

-- Verify the change
SELECT
    COLUMN_NAME,
    DATA_TYPE,
    CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'dbo'
  AND TABLE_NAME = 'TB_User'
  AND COLUMN_NAME = 'reg_ip';
GO

PRINT 'Column reg_ip has been updated successfully to support IPv6 addresses!';
