-
Notifications
You must be signed in to change notification settings - Fork 230
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
Bug 1897319 - Stores icons for light/dark theme for Yelp suggestion #6248
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ use sql_support::open_database::{self, ConnectionInitializer}; | |
/// [`SuggestConnectionInitializer::upgrade_from`]. | ||
/// a. If suggestions should be re-ingested after the migration, call `clear_database()` inside | ||
/// the migration. | ||
pub const VERSION: u32 = 19; | ||
pub const VERSION: u32 = 20; | ||
|
||
/// The current Suggest database schema. | ||
pub const SQL: &str = " | ||
|
@@ -113,9 +113,11 @@ CREATE TABLE yelp_location_signs( | |
) WITHOUT ROWID; | ||
|
||
CREATE TABLE yelp_custom_details( | ||
icon_id TEXT PRIMARY KEY, | ||
icon_light_theme_id TEXT NOT NULL, | ||
icon_dark_theme_id TEXT NOT NULL, | ||
Comment on lines
+116
to
+117
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Storing both light and dark icons in the same row is OK with me, and also I just wanted to mention another way to do it would be to have one icon per row plus an "icon type" column. If we need to support any more types of icons in the future -- and I don't know why we would! -- I think we should switch to that approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, if we do not know how many icons we should handle, then yeah, should introduce the mechanism. |
||
score REAL NOT NULL, | ||
record_id TEXT NOT NULL | ||
record_id TEXT NOT NULL, | ||
PRIMARY KEY (icon_light_theme_id, icon_dark_theme_id) | ||
) WITHOUT ROWID; | ||
|
||
CREATE TABLE mdn_custom_details( | ||
|
@@ -193,6 +195,34 @@ CREATE TABLE IF NOT EXISTS dismissed_suggestions ( | |
)?; | ||
Ok(()) | ||
} | ||
19 => { | ||
let result = tx.query_row_and_then( | ||
"SELECT icon_id FROM yelp_custom_details LIMIT 1", | ||
(), | ||
|row| row.get::<_, String>(0), | ||
); | ||
|
||
if let Ok(_) = result { | ||
// As still old table, we chnage to new. | ||
tx.execute_batch( | ||
" | ||
ALTER TABLE yelp_custom_details RENAME TO old_yelp_custom_details; | ||
CREATE TABLE yelp_custom_details( | ||
icon_light_theme_id TEXT NOT NULL, | ||
icon_dark_theme_id TEXT NOT NULL, | ||
score REAL NOT NULL, | ||
record_id TEXT NOT NULL, | ||
PRIMARY KEY (icon_light_theme_id, icon_dark_theme_id) | ||
) WITHOUT ROWID; | ||
INSERT INTO yelp_custom_details (icon_light_theme_id, icon_dark_theme_id, score, record_id) | ||
SELECT icon_id, icon_id, score, record_id FROM old_yelp_custom_details; | ||
DROP TABLE old_yelp_custom_details; | ||
", | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
_ => Err(open_database::Error::IncompatibleVersion(version)), | ||
} | ||
} | ||
|
@@ -320,6 +350,8 @@ CREATE TABLE yelp_custom_details( | |
record_id TEXT NOT NULL | ||
) WITHOUT ROWID; | ||
|
||
INSERT INTO yelp_custom_details(icon_id, score, record_id) VALUES ('yelp-icon', 0.5, 'yelp-record'); | ||
|
||
CREATE TABLE mdn_custom_details( | ||
suggestion_id INTEGER PRIMARY KEY, | ||
description TEXT NOT NULL, | ||
|
@@ -338,5 +370,27 @@ PRAGMA user_version=16; | |
let db_file = MigratedDatabaseFile::new(SuggestConnectionInitializer, V16_SCHEMA); | ||
db_file.run_all_upgrades(); | ||
db_file.assert_schema_matches_new_database(); | ||
|
||
// Test wether yelp_custom_details data inherits to new table. | ||
let connection = db_file.open(); | ||
let result: Result<(String, String, f64, String), crate::error::Error> = connection.query_row_and_then( | ||
"SELECT icon_light_theme_id, icon_dark_theme_id, score, record_id FROM yelp_custom_details LIMIT 1", | ||
(), | ||
|row| Ok(( | ||
row.get::<_, String>(0)?, | ||
row.get::<_, String>(1)?, | ||
row.get::<_, f64>(2)?, | ||
row.get::<_, String>(3)? | ||
)) | ||
); | ||
|
||
if let Ok((icon_light_theme_id, icon_dark_theme_id, score, record_id)) = result { | ||
assert_eq!(icon_light_theme_id, "yelp-icon"); | ||
assert_eq!(icon_dark_theme_id, "yelp-icon"); | ||
assert_eq!(score, 0.5); | ||
assert_eq!(record_id, "yelp-record"); | ||
} else { | ||
assert!(false); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll need to bump the schema
VERSION
const and add a migration step toupgrade_from()
. See the comment aboveVERSION
.