Skip to content

Check column existence in MigrateFrom3to4 and fix incorrect test database dump data (uplift to 1.80.x) #29370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions components/ai_chat/core/browser/ai_chat_database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ bool MigrateFrom2To3(sql::Database* db) {
}

bool MigrateFrom3to4(sql::Database* db) {
// Check if column exists first
static constexpr char kCheckColumnQuery[] =
"PRAGMA table_info(conversation_entry_uploaded_files)";
sql::Statement check_statement(db->GetUniqueStatement(kCheckColumnQuery));

while (check_statement.Step()) {
if (check_statement.ColumnString(1) == "type") {
// Column already exists, no need to migrate
return true;
}
}

static constexpr char kAddTypeColumnQuery[] =
"ALTER TABLE conversation_entry_uploaded_files ADD COLUMN type INTEGER "
"DEFAULT 0";
Expand Down
1 change: 0 additions & 1 deletion test/data/ai_chat/aichat_database_dump_version_1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ INSERT INTO conversation_entry VALUES('f761af26-4491-4787-ad53-82238b42f534','1a
CREATE TABLE conversation_entry_event_completion(conversation_entry_uuid INTEGER NOT NULL,event_order INTEGER NOT NULL,text BLOB NOT NULL,PRIMARY KEY(conversation_entry_uuid, event_order));
INSERT INTO conversation_entry_event_completion VALUES('f761af26-4491-4787-ad53-82238b42f534',0,X'76313080a3088aa5874d731e9b5042cb565dab897e3af6560681aad24ef9c9379de805096188372c73372de010da70dd9231cfd70490087fd074004e3c826852cb400903a589baf91e4b3ad75acfe8b40b2bc6846b9c00edd6a3d32359c98614383d35');
CREATE TABLE conversation_entry_event_search_queries(conversation_entry_uuid INTEGER NOT NULL,event_order INTEGER NOT NULL,queries BLOB NOT NULL,PRIMARY KEY(conversation_entry_uuid, event_order));
CREATE TABLE conversation_entry_uploaded_files(conversation_entry_uuid INTEGER NOT NULL,file_order INTEGER NOT NULL,filename BLOB NOT NULL,filesize INTEGER NOT NULL,data BLOB NOT NULL,PRIMARY KEY(conversation_entry_uuid, file_order));
COMMIT;
1 change: 0 additions & 1 deletion test/data/ai_chat/aichat_database_dump_version_2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ INSERT INTO conversation_entry VALUES('f761af26-4491-4787-ad53-82238b42f534','1a
CREATE TABLE conversation_entry_event_completion(conversation_entry_uuid INTEGER NOT NULL,event_order INTEGER NOT NULL,text BLOB NOT NULL,PRIMARY KEY(conversation_entry_uuid, event_order));
INSERT INTO conversation_entry_event_completion VALUES('f761af26-4491-4787-ad53-82238b42f534',0,X'76313080a3088aa5874d731e9b5042cb565dab897e3af6560681aad24ef9c9379de805096188372c73372de010da70dd9231cfd70490087fd074004e3c826852cb400903a589baf91e4b3ad75acfe8b40b2bc6846b9c00edd6a3d32359c98614383d35');
CREATE TABLE conversation_entry_event_search_queries(conversation_entry_uuid INTEGER NOT NULL,event_order INTEGER NOT NULL,queries BLOB NOT NULL,PRIMARY KEY(conversation_entry_uuid, event_order));
CREATE TABLE conversation_entry_uploaded_files(conversation_entry_uuid INTEGER NOT NULL,file_order INTEGER NOT NULL,filename BLOB NOT NULL,filesize INTEGER NOT NULL,data BLOB NOT NULL,PRIMARY KEY(conversation_entry_uuid, file_order));
COMMIT;
Loading