-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Image class and DB #3190
Comments
I never used databases, and I would like to learn. If nobody else takes this up I would be willing to, but it would be my first real experience with databases (and I would be looking forward to it ;-) ) |
I give up. I tried for a week to implement this the correct way, but there are just too many things to consider that I don't know enough about. I was able to create the migration code (it was rather simple since I more-or-less know the basics of databases), but I wasn't able to come up with consistent and clear-enough ways of accessing data via Room. This is the migration code I came up with. It works (tested on an exported database), but does not create indexes. // create new tables: images and stream_image_join
database.execSQL("CREATE TABLE IF NOT EXISTS images " +
"(uid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, url TEXT UNIQUE NOT NULL, " +
"width INTEGER NOT NULL, height INTEGER NOT NULL)");
database.execSQL("CREATE TABLE IF NOT EXISTS stream_image_join " +
"(image_id INTEGER PRIMARY KEY NOT NULL, stream_id INTEGER NOT NULL, " +
"FOREIGN KEY(stream_id) REFERENCES streams(uid) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, " +
"FOREIGN KEY(image_id) REFERENCES images(uid) ON UPDATE CASCADE ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED)");
// move stream thumbnail urls into images and link those with stream_image_join
database.execSQL("INSERT OR IGNORE INTO images (url, width, height) " +
"SELECT thumbnail_url, -1, -1 FROM streams");
database.execSQL("INSERT INTO stream_image_join (stream_id, image_id) " +
"SELECT streams.uid, images.uid " +
"FROM streams INNER JOIN images " +
"ON streams.thumbnail_url == images.thumbnail_url");
// drop column thumbnail_url in table streams
database.execSQL("CREATE TABLE streams_temp " +
"(uid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, service_id INTEGER NOT NULL, " +
"url TEXT, title TEXT, stream_type TEXT, duration INTEGER, uploader TEXT)");
database.execSQL("INSERT INTO streams_temp (uid, service_id, url, title, stream_type, duration, uploader) " +
"SELECT uid, service_id, url, title, stream_type, duration, uploader FROM streams");
database.execSQL("DROP TABLE streams");
database.execSQL("ALTER TABLE streams_temp RENAME TO streams"); |
@TobiGr @mauriciocolli @Stypox: I was working on having NewPipeExtractor return all possible images together with their resolution (if known) in TeamNewPipe/NewPipeExtractor#268. This will (obviously) need some changes in NewPipe. Currently NewPipe just saves the URL of the images in the DB. With that PR, there won't just be one URL, so we'll need a separate table for the images, so we could store multiple images (together with their resolutions) in the DB. As I'm not familiar with Room, I was wondering whether one of you could work on it. I also know that the DB will change a bit in #2309.
The text was updated successfully, but these errors were encountered: