Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f1b36272
authored
Feb 28, 2026
by
RedwindA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: migrate model_limits column from varchar(1024) to text for existing tables
parent
066de35a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
model/main.go
+52
-0
No files found.
model/main.go
View file @
f1b36272
...
...
@@ -250,6 +250,8 @@ func InitLogDB() (err error) {
func
migrateDB
()
error
{
// Migrate price_amount column from float/double to decimal for existing tables
migrateSubscriptionPlanPriceAmount
()
// Migrate model_limits column from varchar to text for existing tables
migrateTokenModelLimitsToText
()
err
:=
DB
.
AutoMigrate
(
&
Channel
{},
...
...
@@ -445,6 +447,56 @@ PRIMARY KEY (` + "`id`" + `)
return
nil
}
// migrateTokenModelLimitsToText migrates model_limits column from varchar(1024) to text
// This is safe to run multiple times - it checks the column type first
func
migrateTokenModelLimitsToText
()
{
// SQLite uses type affinity, so TEXT and VARCHAR are effectively the same — no migration needed
if
common
.
UsingSQLite
{
return
}
tableName
:=
"tokens"
columnName
:=
"model_limits"
if
!
DB
.
Migrator
()
.
HasTable
(
tableName
)
{
return
}
if
!
DB
.
Migrator
()
.
HasColumn
(
&
Token
{},
columnName
)
{
return
}
var
alterSQL
string
if
common
.
UsingPostgreSQL
{
var
dataType
string
DB
.
Raw
(
`SELECT data_type FROM information_schema.columns
WHERE table_name = ? AND column_name = ?`
,
tableName
,
columnName
)
.
Scan
(
&
dataType
)
if
dataType
==
"text"
{
return
}
alterSQL
=
fmt
.
Sprintf
(
`ALTER TABLE %s ALTER COLUMN %s TYPE text`
,
tableName
,
columnName
)
}
else
if
common
.
UsingMySQL
{
var
columnType
string
DB
.
Raw
(
`SELECT COLUMN_TYPE FROM information_schema.columns
WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ?`
,
tableName
,
columnName
)
.
Scan
(
&
columnType
)
if
strings
.
ToLower
(
columnType
)
==
"text"
{
return
}
alterSQL
=
fmt
.
Sprintf
(
"ALTER TABLE %s MODIFY COLUMN %s text"
,
tableName
,
columnName
)
}
else
{
return
}
if
alterSQL
!=
""
{
if
err
:=
DB
.
Exec
(
alterSQL
)
.
Error
;
err
!=
nil
{
common
.
SysLog
(
fmt
.
Sprintf
(
"Warning: failed to migrate %s.%s to text: %v"
,
tableName
,
columnName
,
err
))
}
else
{
common
.
SysLog
(
fmt
.
Sprintf
(
"Successfully migrated %s.%s to text"
,
tableName
,
columnName
))
}
}
}
// migrateSubscriptionPlanPriceAmount migrates price_amount column from float/double to decimal(10,6)
// This is safe to run multiple times - it checks the column type first
func
migrateSubscriptionPlanPriceAmount
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment