Copying user settings

If you can get triggers to work at all, you can probably get it to work.  I'd be interested to hear about any successes and/or failures in your tests.

If I get it working, I will incorporate it into my current tool here https://forums.plex.tv/topic/120292-moviefans-database-tool-for-plex/.

Pass or fail, I will post an update here.

If you do end up getting it to work and incorporating it into your tool, I'd like to request the ability to mark which accounts are bound with which accounts ;)  (It would require a bindings table.)

Good luck!

What about those of us that are running Plex on a NAS? 

Is there a solution for that?

Ok.  I was able to get this to work, but it is only a 1 way sync and just like my copy user settings script it does not check if the user the status is being copied to has access to the file or not.  I see this only being useful if you use a managed user account to watch and the status is linked back to the admin account.

BTW, SQLITE allows you to perform the action on the triggering table so I do not need a second table.  I also would not need a binding table as I could handle that in my script.

Could you post the SQL/trigger here?  I'm curious,

Here it is for anyone also interested.  Basically it looks for changes to the table for a particular user and copies the entry to the main account.  This should also change the status back to unwatched, although I do not think that is desirable.  That can be stopped by adding another criteria to the update trigger to look for offset not 0 and view_count not 0.

CREATE TRIGGER copyafterinsert AFTER INSERT ON metadata_item_settings
WHEN NEW.account_id = [copy from id]
BEGIN
DELETE FROM metadata_item_settings WHERE account_id = [copy to id] AND guid = NEW.guid;
INSERT INTO metadata_item_settings(account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at) VALUES([copy to id], NEW.guid, NEW.rating, NEW.view_offset, NEW.view_count, NEW.last_viewed_at, NEW.created_at, NEW.updated_at, NEW.skip_count, NEW.last_skipped_at);
END;
 
CREATE TRIGGER copyafterupdate AFTER UPDATE ON metadata_item_settings
WHEN NEW.account_id = [copy from id]
BEGIN
DELETE FROM metadata_item_settings WHERE account_id = [copy to id] AND guid = NEW.guid;
INSERT INTO metadata_item_settings(account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at) VALUES([copy to id], NEW.guid, NEW.rating, NEW.view_offset, NEW.view_count, NEW.last_viewed_at, NEW.created_at, NEW.updated_at, NEW.skip_count, NEW.last_skipped_at);
END;
 

REVISED (Needed because of change to database schema):


SELECT id, name FROM accounts;

Create a temporary blank copy of the table. I call it temp.

CREATE TABLE “temp” (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “account_id” integer, “guid” varchar(255), “rating” float, “view_offset” integer, “view_count” integer, “last_viewed_at” datetime, “created_at” datetime, “updated_at” datetime, ‘skip_count’ integer DEFAULT 0, ‘last_skipped_at’ datetime DEFAULT NULL, ‘changed_at’ integer(8) default ‘0’);

Copy over the info for the source user. I used the admin.

INSERT INTO temp SELECT * FROM metadata_item_settings WHERE account_id = 1;

Change the id to the new user.

UPDATE temp SET account_id = 101010;

Copy this new info back to the original table.

INSERT INTO metadata_item_settings (account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at, changed_at) SELECT account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at, changed_at FROM temp;

Delete the temp table.

DROP TABLE temp;

Done.


Details: The “changed_at” field was added to the database.

I just used this successfully (on version 0.9.16.6) in order to isolate the Admin level to a locked account.

NOTE: make similar changes to the triggers in the post above.

I have used the sql code to copy my watched status from my admin account to a new one. Except, now for that user, all the watched files are showing a - value on the webui, but when looking at the seson folder, they are all marked watched. And in my roku plex app it shows all the folders for seasons like they are unwatched, but the folders are empty when browsing unwatched. Any suggestions from anyone? Thanks

Screenshots please. I’m not clear what you are saying.

Look a the Game of Thrones poster.

This happened to me too, i fix it manually changing the status to unwatched and then to watched again.

Just an update it looks like plex added another column to this table “metadata_item_settings” so the above command didn’t work

INSERT INTO temp SELECT * FROM metadata_item_settings WHERE account_id = 1;
it said I was trying to insert 12 columns of data and their was only 11 in the temp table.

So I altered the statement to only copy the data in we are putting in the temp table
INSERT INTO temp (account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at) SELECT account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at FROM metadata_item_settings WHERE account_id = 1;

The better way to do it would be to adjust the script to account for the additional column, but I wanted to get this done fast so this one change it works, just not copying whatever that new field is.
I logged in and my history was all there :slight_smile:

@oriolis said:
Look a the Game of Thrones poster.

This happened to me too, i fix it manually changing the status to unwatched and then to watched again.

Ah, a negative value. I get it now. I have seen this before but can’t remember what the cause or the fix was. Let me see if I can find it and I’ll get back to you.

Sorry but this does not work for me :frowning:
After punch all the commands in the sqlite3.exe in the Databasefolder (Library\Application Support\Plex Media Server\Plug-in Support\Databases) and restarting Plex in Synology, the new user does not appear

There is a new column in one of the tables. These are updated scripts

SELECT id, name FROM accounts;

CREATE TABLE "temp" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "account_id" integer, "guid" varchar(255), "rating" float, "view_offset" integer, "view_count" integer, "last_viewed_at" datetime, "created_at" datetime, "updated_at" datetime, 'skip_count' integer DEFAULT 0, 'last_skipped_at' datetime DEFAULT NULL, 'changed_at' integer(8));

INSERT INTO temp SELECT * FROM metadata_item_settings WHERE account_id = 1;

UPDATE temp SET account_id = 1111111111;

INSERT INTO metadata_item_settings (account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at,changed_at) SELECT account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at,changed_at FROM temp;

DROP TABLE temp;

CREATE TABLE temp (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “account_id” integer, “guid” varchar(255), “rating” float, “view_offset” integer, “view_count” integer, “last_viewed_at” datetime, “created_at” datetime, “updated_at” datetime, “skip_count” integer DEFAULT 0, “last_skipped_at” datetime DEFAULT NULL, “changed_at” integer(8) DEFAULT 0, ‘extra_data’ varchar(255));

INSERT INTO temp SELECT * FROM metadata_item_settings WHERE account_id = 1;

UPDATE temp SET account_id = 1111111111;

INSERT INTO metadata_item_settings (account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at,changed_at, extra_data) SELECT account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at,changed_at, extra_data FROM temp;

DROP TABLE temp;

Yet another column

@“MovieFan.Plex” said:
First identify the id numbers for the accounts involved.

SELECT id, name FROM accounts;

Create a temporary blank copy of the table.  I call it temp.

CREATE TABLE “temp” (“id” INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, “account_id” integer, “guid” varchar(255), “rating” float, “view_offset” integer, “view_count” integer, “last_viewed_at” datetime, “created_at” datetime, “updated_at” datetime, ‘skip_count’ integer DEFAULT 0, ‘last_skipped_at’ datetime DEFAULT NULL);

Copy over the info for the source user.  I used the admin.

INSERT INTO temp SELECT * FROM metadata_item_settings WHERE account_id = 1;

Change the id to the new user.

UPDATE temp SET account_id = 101010;

Copy this new info back to the original table.

INSERT INTO metadata_item_settings (account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at) SELECT account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at FROM temp;

Delete the temp table.

DROP TABLE temp;

Done.

I think you guys added more columns to the table metadata_item_settings. I received the following error:

sqlite> INSERT INTO temp SELECT * FROM metadata_item_settings WHERE account_id = 1;
Error: table temp has 11 columns but 13 values were supplied

Can you please update your solution please?

Many thanks…

I’m having the same issue, can anyone help with this please?

Any news on this, anyone?

It looks like I can still update this although the post was locked. Added ‘last_rated_at’ 2023

For Ubuntu:

Cd into the plex database directory

cd /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Plug-in\ Support/Databases/

Open the database with sqlite3


sudo sqlite3 com.plexapp.plugins.library.db

List account_ids and their names


SELECT id, name FROM accounts;

Create a table called temp to store all of the user data from the user you want to clone


CREATE TABLE "temp" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "account_id" integer, "guid" varchar(255), "rating" float, "view_offset" integer, "view_count" integer, "last_viewed_at" datetime, "created_at" datetime, "updated_at" datetime, 'skip_count' integer DEFAULT 0, 'last_skipped_at' datetime DEFAULT NULL, 'changed_at' integer(8), extra_data varchar(255), 'last_rated_at' dt_integer(8));

Insert the user data into this temp table. Make sure to change account_id to the OG account


INSERT INTO temp SELECT * FROM metadata_item_settings WHERE account_id = 13132064;

Update the account_id in the temp table to the account_id of the new user


UPDATE temp SET account_id = 1;

Insert this info back into metadata_item_settings from your temp table


INSERT INTO metadata_item_settings (account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at, changed_at, extra_data) SELECT account_id, guid, rating, view_offset, view_count, last_viewed_at, created_at, updated_at, skip_count, last_skipped_at, changed_at, extra_data, last_rated_at FROM temp;

Get rid of the temp table


Drop table Temp;