I'm trying to make a simple app where Users can make Lists of films/books they'd like to complete. Once a List is created, they could add to a List, or reorder the items in the List.
So currently I have a User table:
CREATE TABLE User (
userid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL,
salt TEXT NOT NULL UNIQUE
);
And a List table:
CREATE TABLE List (
listid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
listname TEXT NOT NULL,
userid INTEGER NOT NULL,
date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
date_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
FOREIGN KEY(userid) REFERENCES User(userid)
);
What I'm trying to figure out now is: how do I store the actual lists? The lists are user-created, and a user should have the ability to add and remove from them, and re-order the items of the list if they'd like. I'd also like to store some metadata with each list item (such as a url to a film's respective Wikipedia page).
At first I thought, I'll just store the list as JSON in a column in the List table. But this seems counter-intuitive in SQL.
A quick cursory search-spree led me to people talking about junction tables. I'm not sure I fully understand junction tables yet; but does this mean that each time a user would create a new List, I'll have to generate a new table for all of the items of the List? (So, as I create a new row in the List
table, I'll also create a new table ListItems_ListID_Username
that links to that row?).
Any insight appreciated. If it's not obvious, I'm a total SQL newbie. :)
EDIT: As an example, if I were to store each list item in a table, I imagine each list item would look like this psuedo schema
(orderInList INTEGER, itemname TEXT, url TEXT (nullable), listid INTEGER (foreign key to List), userid INTEGER (foreignkey to User))