Course table in Moodle

Course table in Moodle

by Darko Miletić -
Number of replies: 5

Can somebody explain to me what is the rationale for not having a unique index on shortname field in course table?

Moodle already checks for duplicates in code, but it is bad design to put this kind of logic in the code. Database should handle integrity of data whenever possible.

Thanks

Average of ratings: -
In reply to Darko Miletić

Re: Course table in Moodle

by Ray Morris -

Maybe for the same reason it does this:

WHERE id LIKE '$id'

instead of this:

WHERE id=$id

Sorry, I just thought it was interesting that after your five years working with Moodle, the lack of a unique index in the DB was what you thought was wonky. 

In reply to Ray Morris

Re: Course table in Moodle

by Dan Poltawski -
Hi Ray,

Please can you be specific about where in the code you are talking about?

Contrary to what you are insinuating, many 'strange behaviours' are usually there for a reason. If not, we'd like to know about them and fix them. With open source code and many eyes on the code, hopefully we can find and fix them with your help.
In reply to Darko Miletić

Re: Course table in Moodle

by Dan Poltawski -

Hi Darko,

Its because of historical problems with empty strings.

See Eloy's explanation in: MDL-14083 - Course Shortname is unique in interface and code but not in database schema.

In reply to Dan Poltawski

Re: Course table in Moodle

by Darko Miletić -

So it will never be fixed?

In reply to Darko Miletić

Re: Course table in Moodle

by Dan Poltawski -
It can be fixed, it just hasn't been yet raised its head against the other [x],000 open issues. From your initial comment, maybe you have a reason to raise the priority of this issue? If so, I recommend creating an issue in the tracker and outlining the problems you are facing.