A slightly improved scheme for storing user and document data that is somewhat better normalized.
User:
scheme (eg. http)
host (eg. www.foo.com)
Document:
path (eg. /2015-01-20/my-awesome-post)
We can still give Document a #url attribute that automatically assigns the document instance to the correct user (creating one, if necessary; maybe even updating an existing one, in case the user's scheme has changed.)
This would greatly simplify things like #31 (and related), nicely denormalize the database information, and we'd still be able to build full URLs from the information present. The only potential drawback is that we'll need to create User records for every document URL that ends up in the database, but this probably isn't really a big problem.
It would also solve the HTTP vs. HTTPS problem, as moving a user from a HTTP to a HTTPS host would now just be a matter of changing the User record's URL.
Checklist:
[x] Add User#scheme
[x] Make User#url= automatically set #scheme and #host (do we also want #port?)
[x] Remove Document#host and use an integer foreign key instead
[x] Set up a foreign key constraint that enforces referential integrity
[x] Document#url= should automatically assign the correct User (or create one, if necessary) and just store the #path
[x] Document#url should build the URL from combining the User instance's #scheme and #host with its own #path
A slightly improved scheme for storing user and document data that is somewhat better normalized.
User
:scheme
(eg.http
)host
(eg.www.foo.com
)Document
:path
(eg./2015-01-20/my-awesome-post
)We can still give
Document
a#url
attribute that automatically assigns the document instance to the correct user (creating one, if necessary; maybe even updating an existing one, in case the user's scheme has changed.)This would greatly simplify things like #31 (and related), nicely denormalize the database information, and we'd still be able to build full URLs from the information present. The only potential drawback is that we'll need to create
User
records for every document URL that ends up in the database, but this probably isn't really a big problem.It would also solve the HTTP vs. HTTPS problem, as moving a user from a HTTP to a HTTPS host would now just be a matter of changing the
User
record's URL.Checklist:
User#scheme
User#url=
automatically set#scheme
and#host
(do we also want#port
?)Document#host
and use an integer foreign key insteadDocument#url=
should automatically assign the correctUser
(or create one, if necessary) and just store the#path
Document#url
should build the URL from combining theUser
instance's#scheme
and#host
with its own#path
user_id
andpath
previous_urls
toprevious_paths
DocumentController
accordingly