cms-dev / cms

Contest Management System
http://cms-dev.github.io/
GNU Affero General Public License v3.0
901 stars 362 forks source link

Look and fix some DB model issues #87

Open lw opened 11 years ago

lw commented 11 years ago

I think some DB models (i.e. those classes in cms.db) have some strange fields definitions. For example the User.ip field is nullable but we usually use the '0.0.0.0' string to mean "no IP address assigned". Likewise User.email is almost never used, thus left blank, but it's not nullable. I suspect other such issues are around, even of other kinds. We should take a look at all models and fix the ones we find.

giomasce commented 11 years ago

I'm of course in favor, in general, to such changes and agree that the two cases you indicate are to be fixed.

bblackham commented 11 years ago

Can I suggest for User.ip, that instead of hard-coding '0.0.0.0', we actually just use NULL or a specific IP(v4 or v6) address? (i.e. make NULL the new '0.0.0.0', as '0.0.0.0' is only ever treated as a magic string).

bblackham commented 11 years ago

My proposed fix for the User.ip issue is here: bblackham/cms@a102720

lw commented 11 years ago

Seems good. I suggest to merge it after the release of v1.0, which should happen very soon.

Just a quick note: there's no UpdateDB script... not sure if we want one ;-)

bblackham commented 11 years ago

Yep, post definitely 1.0.

UpdateDB script would be trivial, but probably completely useless. (New contests wouldn't run with old IP locks). I don't think we should worry :)

lw commented 11 years ago

I'm putting this here, even if it's not strictly related: the DB allows Contest.start and .stop to be nullable, and assign to these values a meaning of -infinity and +infinity (respectively). I don't think that all of the code is aware of these cases...

lw commented 11 years ago

The current problems have been fixed in https://github.com/cms-dev/cms/commit/483ee85965f527cbc459ebe7e010c6854661b6eb, https://github.com/cms-dev/cms/commit/e051ee4d2667ba381a24c7b1764a6d9c3d792b45 and https://github.com/cms-dev/cms/commit/d66951d3149a954fb0b81b6015e8e0b060020152. I keep this issue open to remember to look if I can find more...

lw commented 11 years ago

TODO: rename the table name of Testcases from "task_testcases" to "testcases".

lw commented 11 years ago

TODO: check that nobody is using Task.scorer and remove it.

lw commented 11 years ago

TODO: try to use a SmartMappedCollection for Contest.users and Contest.tasks (indexed by username and task name respectively).

lw commented 11 years ago

TODO: move Submission.LANGUAGES and Submission.LANGUAGES_MAP out of the DB classes since it has nothing to do with the DB... for example in cms/__init__.py.

lw commented 11 years ago

TODO: now that UpdateDB has been removed I think we don't need to give names to UniqueConstraints (and other constraints) anymore; we can remove them.

lw commented 11 years ago

TODO: use a proper many-to-many relationship for Task. and User.primary_statements. With the new ContestExporter/Importer it should be a piece of cake.

lw commented 11 years ago

@bblackham I was reading this discussion again and I'm not getting anymore the reason we don't need an UpdateDB script for the User.ip change (which, at this point, would be an UpdateDump script). Wouldn't it be useful to convert the '0.0.0.0' values into null? If we don't do that then reimported dumps won't work, right?

bblackham commented 11 years ago

@lerks Updating them wouldn't hurt, but I can't imagine a scenario where it would be useful. I figured re-imported dumps wouldn't run twice with the same users (nor with the same IP locks).

lw commented 11 years ago

Yes, we usually think of dumps as a way to "archive" contests after they've been run, or to re-run them again. But suppose one uses CMS to manage a long-running online repository of tasks: one could export just to update CMS and then import again. Sure, in both cases this particular change doesn't seem necessary (users will be changed on re-runs, and no IP locks will be in place for online contests) but I'd prefer to do it anyway.

bblackham commented 11 years ago

@lerks Cool, no objections from me.

lw commented 11 years ago

TODO: consider making (Submission|UserTest).get_result(_or_create)? use the active dataset if no one is given as argument.

lw commented 10 years ago