I am currently integrating open source chat (AJAX Chat) into another project. Now, by default, chat gets its actual users and actual channels from a file, but obviously this is not ideal when you have a database with constantly changing users.
So, I want to make the chat load user and channel information directly from the database. I thought the design should be as follows (if you feel different, please let me know):
- We have several chat channels (public, marketing, etc.).
- Then we have groups assigned to the channels (for example, PR 1 team, IT specialists, etc.).
- Then we have users who are part of groups, and in some cases directly linked to channels.
I was thinking about implementing the above tables:
Channel table:
|----|Channel_Name||Channel_ID||Groups_Assigned||Users_Assigned|----| |----|---Public---||-----0----||---1,2,3,4,5---||-----3,4------|----| . . .etc...
Note. The assigned groups table contains the group identifier for the groups assigned to the channel, while the assigned users contain the identifier of users who are not part of the assigned groups.
Group table:
|----|Group_Name||Group_ID||Users_Assigned|----| |----|---Team1--||----0---||------5,10----|----| . . .etc...
Sorry for the badly crossed out tables.
Now, when the above implementation, when the user logs in, the program will get the user ID (from the user table), then search the group table for all groups containing the user ID, and finally search the channel table for all channels that contain either groups (which are part of the user), or channels that have the user directly assigned to them.
My idea is possible, but it seems to be a little inefficient. Since I would need to store the assigned identifiers (both groups and users) in the format 1,2,3....
, I would have to use either PHP explode()
or some other PostgreSQL function that can search for strings . Most likely, I will store an array of groups, and then cyclically move them one line at a time, this seems to me very slow.
Or I may have a logical column for each user, but this will result in too many columns, and I don't want to create a new column every time the user is created.
So how do you guys do this? And if for some crazy reason you agree with my original idea, then could you help me figure out how to actually write the code to actually do it.
Thanks for your time, had a good day.