Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
aisbf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
aisbf
Commits
b6e675c1
Commit
b6e675c1
authored
Apr 21, 2026
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration to clean up duplicate cache settings caused by NULL UNIQUE constraint issue
parent
6a14af79
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
58 additions
and
0 deletions
+58
-0
database.py
aisbf/database.py
+58
-0
No files found.
aisbf/database.py
View file @
b6e675c1
...
...
@@ -4038,6 +4038,64 @@ def DatabaseManager__run_config_migrations(self, cursor, auto_increment, timesta
except
Exception
as
e
:
logger
.
warning
(
f
"Migration check for user_cache_settings table: {e}"
)
# Migration: Clean up duplicate cache settings (NULL values bypass UNIQUE constraint in MySQL)
try
:
logger
.
info
(
"Checking for duplicate cache settings..."
)
# Get all users with duplicate global settings
if
self
.
db_type
==
'sqlite'
:
cursor
.
execute
(
'''
SELECT user_id, COUNT(*) as cnt
FROM user_cache_settings
WHERE provider_id IS NULL AND model_name IS NULL
GROUP BY user_id
HAVING cnt > 1
'''
)
else
:
cursor
.
execute
(
'''
SELECT user_id, COUNT(*) as cnt
FROM user_cache_settings
WHERE provider_id IS NULL AND model_name IS NULL
GROUP BY user_id
HAVING cnt > 1
'''
)
duplicate_users
=
cursor
.
fetchall
()
if
duplicate_users
:
logger
.
info
(
f
"Found {len(duplicate_users)} users with duplicate global cache settings"
)
for
user_row
in
duplicate_users
:
user_id
=
user_row
[
0
]
# Get all global settings for this user, ordered by updated_at DESC
cursor
.
execute
(
f
'''
SELECT id FROM user_cache_settings
WHERE user_id = {placeholder} AND provider_id IS NULL AND model_name IS NULL
ORDER BY updated_at DESC
'''
,
(
user_id
,))
all_ids
=
[
row
[
0
]
for
row
in
cursor
.
fetchall
()]
if
len
(
all_ids
)
>
1
:
# Keep the first (most recent), delete the rest
keep_id
=
all_ids
[
0
]
delete_ids
=
all_ids
[
1
:]
placeholders
=
','
.
join
([
placeholder
]
*
len
(
delete_ids
))
cursor
.
execute
(
f
'''
DELETE FROM user_cache_settings
WHERE id IN ({placeholders})
'''
,
tuple
(
delete_ids
))
logger
.
info
(
f
"✅ Cleaned up {len(delete_ids)} duplicate cache settings for user {user_id}, kept id={keep_id}"
)
conn
.
commit
()
else
:
logger
.
info
(
"No duplicate cache settings found"
)
except
Exception
as
e
:
logger
.
warning
(
f
"Migration check for duplicate cache settings: {e}"
)
# Migration: Create account_tiers table if missing
try
:
if
self
.
db_type
==
'sqlite'
:
...
...
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