Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database (MySQL): Missing constraints/foreign keys #10014

Closed
fgusinde opened this issue Jul 29, 2014 · 7 comments
Closed

Database (MySQL): Missing constraints/foreign keys #10014

fgusinde opened this issue Jul 29, 2014 · 7 comments

Comments

@fgusinde
Copy link

I just looked at the data model and tables and I wondered why there are foreign keys missing, e.g.

CREATE TABLE oc_group_user (
gid varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',
uid varchar(64) COLLATE utf8_bin NOT NULL DEFAULT '',
PRIMARY KEY (gid,uid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin

I think there MUST be two foreign keys, one to oc_groups and one to oc_users.

But I see that there is NO foreign key in whole data model.
I want to tell you to change this.

@fgusinde
Copy link
Author

Sample:
MariaDB [owncloud]> ALTER TABLE oc_group_user ADD FOREIGN KEY (gid) REFERENCES oc_groups(gid);
Query OK, 1 row affected (1.12 sec)
Records: 1 Duplicates: 0 Warnings: 0

MariaDB [owncloud]> ALTER TABLE oc_group_user ADD FOREIGN KEY (uid) REFERENCES oc_users(uid);
Query OK, 1 row affected (0.64 sec)
Records: 1 Duplicates: 0 Warnings: 0

@fgusinde
Copy link
Author

Another one:
MariaDB [owncloud]> ALTER TABLE oc_group_admin ADD FOREIGN KEY(gid) REFERENCES oc_groups(gid);
Query OK, 0 rows affected (0.69 sec)
Records: 0 Duplicates: 0 Warnings: 0

MariaDB [owncloud]> ALTER TABLE oc_group_admin ADD FOREIGN KEY(uid) REFERENCES oc_users(uid);
Query OK, 0 rows affected (0.80 sec)
Records: 0 Duplicates: 0 Warnings: 0

@fgusinde
Copy link
Author

It looks like these columns are candidats for foreign keys, is it possible to use always the same column-name?

+-------------------+------------------+-------------+
| TABLE_NAME | COLUMN_NAME | COLUMN_TYPE |
+-------------------+------------------+-------------+
| oc_activity | affecteduser | varchar(64) |
| oc_activity | user | varchar(64) |
| oc_activity_mq | amq_affecteduser | varchar(64) |
| oc_files_trash | user | varchar(64) |
| oc_locks | userid | varchar(64) |
| oc_preferences | userid | varchar(64) |
| oc_privatedata | user | varchar(64) |
| oc_properties | userid | varchar(64) |
| oc_share_external | user | varchar(64) |
+-------------------+------------------+-------------+

I think they all belong (reference) to oc_users::uid, right?

@DeepDiver1975
Copy link
Member

Thanks a lot for looking into this.

ownCloud's database migration mechanism does not support foreign keys at the moment.
This has been widely discussed in other issues

@fgusinde
Copy link
Author

Can you please gibt me the corresponding issue-numbers?

@VicDeo
Copy link
Member

VicDeo commented Jul 29, 2014

@fgusinde #5756 (comment)

@wshadow
Copy link

wshadow commented Aug 19, 2014

For now this can only be closed as 'Won't fix'.
Personally I don't think that is the right decision, but that's how it is for now.

@karlitschek please reconsider this. Foreign keys are important for DB integrity. Vic already linked to the other issue where we discussed this in more detail. If you want me to write a paper on 'why foreign keys are important', just tell me.

@wshadow wshadow closed this as completed Aug 19, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Aug 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants