Commit 2f52459
authored
Auto-generate foreign key constraint names when not provided (#1041)
* Auto-generate foreign key constraint names when not provided
When a foreign key is added without an explicit name, the MysqlAdapter
and SqliteAdapter now generate a name following the pattern
'tablename_columnname' (e.g., 'articles_user_id' for a FK on the
user_id column in the articles table).
This matches the behavior of PostgresAdapter and SqlserverAdapter,
which already auto-generate FK names. This ensures constraint names
are always strings and prevents issues with constraint lookup methods
that expect string names.
* Update test comparison files for new FK naming convention
Update the expected FK names in comparison files and schema dumps
to match the new auto-generated naming pattern (tablename_columnname).
* Update test comparison files with index rename operations
The FK constraint name change from auto-generated (ibfk_N) to
explicit (table_column) also affects the implicit index MySQL
creates for FKs. Update comparison files to reflect the index
rename from user_id to articles_user_id.
* Remove unnecessary index operations from comparison file
With the FK naming changes, both the lock file and database have
the index named articles_user_id, so no diff is needed for this
index. Remove the index rename operations that were incorrectly
added.
* Add conflict resolution for auto-generated FK constraint names (#1042)
* Add conflict resolution for auto-generated FK constraint names
When auto-generating FK constraint names, check if the name already
exists and append a counter suffix (_2, _3, etc.) if needed.
This prevents duplicate constraint name errors when multiple FKs
are created on the same columns with different references.
* Remove unused variable
* Truncate FK constraint names to max 128 characters
Limit auto-generated foreign key constraint names to 125 characters
to ensure the final name (including potential _XX counter suffix)
stays within 128 characters. This prevents identifier length errors
on databases with strict limits (MySQL: 64, PostgreSQL: 63).
* Use database-specific identifier length limits
- MySQL: 61 chars (64 limit - 3 for _XX suffix)
- PostgreSQL: 60 chars (63 limit - 3 for _XX suffix)
- SQL Server: 125 chars (128 limit - 3 for _XX suffix)
- SQLite: No limit needed
* Use IDENTIFIER_MAX_LENGTH class constant for clarity
Each adapter now defines its database-specific identifier length limit
as a class constant, making the code more self-documenting.File tree
7 files changed
+145
-23
lines changed- src/Db/Adapter
- tests/comparisons/Diff
- default
- simple
7 files changed
+145
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
32 | 37 | | |
33 | 38 | | |
34 | 39 | | |
| |||
977 | 982 | | |
978 | 983 | | |
979 | 984 | | |
980 | | - | |
| 985 | + | |
981 | 986 | | |
982 | 987 | | |
983 | 988 | | |
| |||
1192 | 1197 | | |
1193 | 1198 | | |
1194 | 1199 | | |
| 1200 | + | |
1195 | 1201 | | |
1196 | 1202 | | |
1197 | | - | |
| 1203 | + | |
1198 | 1204 | | |
1199 | | - | |
1200 | | - | |
1201 | | - | |
1202 | | - | |
| 1205 | + | |
| 1206 | + | |
1203 | 1207 | | |
1204 | 1208 | | |
1205 | 1209 | | |
| |||
1222 | 1226 | | |
1223 | 1227 | | |
1224 | 1228 | | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
1225 | 1258 | | |
1226 | 1259 | | |
1227 | 1260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
30 | 35 | | |
31 | 36 | | |
32 | 37 | | |
| |||
949 | 954 | | |
950 | 955 | | |
951 | 956 | | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
| 957 | + | |
957 | 958 | | |
958 | 959 | | |
959 | 960 | | |
| |||
972 | 973 | | |
973 | 974 | | |
974 | 975 | | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
975 | 1006 | | |
976 | 1007 | | |
977 | 1008 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1425 | 1425 | | |
1426 | 1426 | | |
1427 | 1427 | | |
1428 | | - | |
| 1428 | + | |
1429 | 1429 | | |
1430 | 1430 | | |
1431 | 1431 | | |
| |||
1670 | 1670 | | |
1671 | 1671 | | |
1672 | 1672 | | |
| 1673 | + | |
1673 | 1674 | | |
1674 | 1675 | | |
1675 | | - | |
| 1676 | + | |
1676 | 1677 | | |
1677 | | - | |
1678 | | - | |
1679 | | - | |
1680 | | - | |
| 1678 | + | |
| 1679 | + | |
1681 | 1680 | | |
1682 | 1681 | | |
1683 | 1682 | | |
| |||
1698 | 1697 | | |
1699 | 1698 | | |
1700 | 1699 | | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
1701 | 1725 | | |
1702 | 1726 | | |
1703 | 1727 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
31 | 36 | | |
32 | 37 | | |
33 | 38 | | |
| |||
864 | 869 | | |
865 | 870 | | |
866 | 871 | | |
867 | | - | |
| 872 | + | |
868 | 873 | | |
869 | 874 | | |
870 | 875 | | |
| |||
881 | 886 | | |
882 | 887 | | |
883 | 888 | | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
884 | 918 | | |
885 | 919 | | |
886 | 920 | | |
| |||
Binary file not shown.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
| 237 | + | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
0 commit comments