@@ -15,20 +15,28 @@ func (v *V7TCPTLSRoutes) Version() int {
1515}
1616
1717func (v * V7TCPTLSRoutes ) Run (sqlDB * db.SqlDB ) error {
18- // Update the instance_id column to allow NULL values
19- err := sqlDB .Client .ExecWithError ("ALTER TABLE tcp_routes MODIFY COLUMN instance_id varchar(255) DEFAULT NULL" )
20- if err != nil {
21- return err
18+ // Update the instance_id column to allow NULL values - syntax differs by database
19+ if sqlDB .Client .Dialect ().Name () == "mysql" {
20+ err := sqlDB .Client .ExecWithError ("ALTER TABLE tcp_routes MODIFY COLUMN instance_id varchar(255) DEFAULT NULL" )
21+ if err != nil {
22+ return err
23+ }
24+ } else {
25+ err := sqlDB .Client .ExecWithError ("ALTER TABLE tcp_routes ALTER COLUMN instance_id SET DEFAULT NULL" )
26+ if err != nil {
27+ return err
28+ }
2229 }
2330
24- // Drop existing index if it exists - using correct MySQL syntax with table name
25- _ = sqlDB . Client . ExecWithError ( "DROP INDEX idx_tcp_route ON tcp_routes" )
31+ // Drop existing index if it exists
32+ dropIndex ( sqlDB , " idx_tcp_route" , " tcp_routes" )
2633
27- // Create unique index using raw SQL with column length specifications
28- err = sqlDB .Client .ExecWithError ("CREATE UNIQUE INDEX idx_tcp_route ON tcp_routes (router_group_guid(191), host_port, host_ip(191), external_port, sni_hostname(191), host_tls_port)" )
29- if err != nil {
30- return err
34+ // Create unique index - MySQL requires length prefixes for text columns
35+ var indexSQL string
36+ if sqlDB .Client .Dialect ().Name () == "mysql" {
37+ indexSQL = "CREATE UNIQUE INDEX idx_tcp_route ON tcp_routes (router_group_guid(191), host_port, host_ip(191), external_port, sni_hostname(191), host_tls_port)"
38+ } else {
39+ indexSQL = "CREATE UNIQUE INDEX idx_tcp_route ON tcp_routes (router_group_guid, host_port, host_ip, external_port, sni_hostname, host_tls_port)"
3140 }
32-
33- return nil
41+ return sqlDB .Client .ExecWithError (indexSQL )
3442}
0 commit comments