Open J0s3f opened 13 years ago
Hey J0s3f, What would you say about using enums instead of magic numbers?
Can you change ENUMs in MySQL to add more options later without a huge database reorganization (slow)? If this is possible, I think this would be the best option.
edit: From what I found it should work good if only new ENUM options are added at the end. We don't want to have to go through all data on adding a new logable event...
Yes, ENUM column sets can be added-to easily. It think it is even possible to rename an element of the set (add new element, update all rows, remove old element). Also, quick stupid question from me: what good do FKs do if they are all on serial ids which shouldn't change?
A lot of the features I see (FK restraints etc) are not easily compatible with other database systems (Postgres, H2), and older versions of MySQL. If there are other changes, please let me know.
Well, there are at this time intentionally no other changes so it still works with older Versions. Adding ENUMs like Benja suggested would be a good option IMO. PostgreSQL and H2 support FKs and views, the syntax is just a little different. For older MySQL versions the DB could be created without this options. (This is why I didn't suggest ENUMs in the first place.)
MySQL supports enums since version 3 or so. I will try to implement it, but make it optional, depending on the DBMS or configuration settings. Edit: However, I will test how long it takes to update all "data" rows with a large DB. Edit2: will now use your temporary repo :)
The update is instant if only new values are added at the end. ENUMs are stored as integers internally, and if one of them changes all rows have to be updated. I just added a new value at the end and it was instant on a ~1000000row table.
Ok, i just tried ALTER TABLE table CHANGE COLUMN column column ENUM('A','B','C','D') where column was previously an INT, and it seems like the rows are set to the Nth enum element, where N is the previous INT value, so looking good.
Please add the option for those of us who want to use a real DB (as opposed to MyISAM) to use InnoDB with a proper DB schema (using foreign keys). Here is the DB I use atm. The only thing that has to be changed in BigBrother is the creation of the database and BB has to add new actions into the bbactions db. (This is not really strictly necessary, but I like to have all usefull information inside the database, not some "magic numbers" you have to lookup somewhere else. Also it makes my big-brother view pretty) The actions which are in the Wiki are in the SQLdump here too: