0

Background

I'm trying to decide the best way to manage a change in requirements. Currently when an admin is assigned to a ticket, the ticket header record is given an owner and the ownerID field is updated with the value of the id which corresponds to the record in the TeamMembers table. The owner (Team member) is notified when a user (Customer) updates the ticket with a comment. I now need to add additional Team Members to the ticket so they are also notified.

Question ?

Do I...

  1. Make ownerID field ownerIDs and store a comma separated list of IDs in a string ?
  2. Add a new field additionalOwnerIDs and store any extra IDs after the main owner as a comma separated string ?
  3. Create a new table that simply links ticketID to assigned owners and have one row per owner ?
  4. Do something else ?

Considerations

I want to deliver the new functionality as quickly as possible, repurposing the existing field might seem like the simplest way forward but it would involve changing the schema type of existing data so will need a migration script to rewrite hundreds of thousands of rows.

Adding a new field then wouldn't need as much migration work as it would be an empty string for all existing records and default to an empty string for new records.

A new link table seems the most programatically correct way (IMHO) but would require the most time to implement and test it and the migrations would be the most complicated in terms of extracting existing ticket owners into the new table. Changing the code for retrieving / updating an owner to query the new table. Then removing the defunct ownerID column from the existing table.

Have a missed anything? Which approach is the best in terms of maintaining the code base in the future?

1

You've definitely thought this problem out well. I agree with you that option three is the best practice; I would choose that option. Creating a new table that links many owner IDs to a single ticket ID makes the most sense to me. It is intuitive and will make the database more maintainable in the future.

Some considerations for option 3:

  • Your going to have to update how an owner is linked to a ticket. My suggestions is to update the GUI to use a control like this one: http://diminishing.org/assets/combo_select.png
  • Your going to have to deprecate the existing creation, update and retrieval of owners and update it to create, update and retrieve from your newly created table. Depending on the info you want to return you may have to join the Owner and Ticket table.
  • There is now more than one owner per ticket. It's very likely that there is existing functionality that depends on having a single owner. Your going to have to scout that functionality and return to your clients with a recommendation on solving those problems.

This may sound like a lot of work initially. However, I believe that it will be the easiest to extend functionality later on. It will also be less of a learning curve for future developers.

Problems with comma separated options:

  1. Your not letting the database do its job. The database is there to perform retrievals, updates and creations; it is optimized to do these things. Storing data as a string means you need to write code to parse it and perform operations that the database should be performing.
  2. It's hard to see connections between tables. Your simulating a relationship in code. It will be hard to see the relationship at first glance if there are a ton of entries in your comma delimited field. This contributes to a steep learning curve for new developers and a headache if you need to debug later.
  3. You will have to debug your database relationships through your code instead of writing queries. You want to be able to run your software and execute a SQL query to see if the relationship was setup properly in tables. However, with comma delimited you will need to debug this relationship through code instead of running a simple SQL query. This is a time waster and a pain.

I'm sure there are more reasons not to use comma delimited fields in a database. That's a few to help understand why it's not a good idea. I'm sure people could come up with advantages for storing comma delimited fields as well. However, it is my opinion that it is bad practice to store comma delimited fields in a database.

1

Go with option #3, creating a new table. Embedding CSV data in columns is just going to be a headache down the road for you because you'll have data that is not easily retrievable. In this case, if you embedded a CSV list of users, it would prevent you from easily searching on tickets that a user is assigned with a single SQL statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.