Changing an int to be a string in PHP / MySQL Schema

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?

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.

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.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật