From 36357b9c72bb306e097230005f900d65069ac4d6 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 9 Dec 2019 01:00:23 +0100 Subject: [PATCH] MySQL requires auto columns to be the primary key Adding an auto column to an existing table wasn't possible, because the primary key would be added in a secondary step. However, MySQL does not permit this to be split into two steps, requiring us to define the key when adding the column. --- com.woltlab.wcf/files_pre.tar | Bin 193536 -> 195584 bytes .../DatabaseTableChangeProcessor.class.php | 17 +++++++++++++++-- .../AbstractDatabaseTableColumn.class.php | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/com.woltlab.wcf/files_pre.tar b/com.woltlab.wcf/files_pre.tar index acdf4ad3076ba7277abbd516956246a4be13808c..513c0bc6454d9b9f0c41a3a53b01e3a54fdfc84c 100644 GIT binary patch delta 11857 zcmcIK32>8VcB>aI*$CVCl=1P~mMzPtWa9&jFKjTE!3Hl!zyaC%Z7axQ=H^3#CE~i+FwcVHl_e#X$exRJb1ZR6iDD6^h$+it z5%>QJ3i0vw6R-;(txrNtWY_0&Qh8BJ$m{P{%{3KO^tI9wdGO6nT6-VlBS16$G0?=f zD%0f2b=5tB`vT4S0U`TVVD!!retAWWy-uoIcSOe_U($xhT49r_VKx`g&*sU}w+bxm1|9G#-5=nZe z33pozA?qEp!^4Ys^T6E2bBJRZ*{iDrc%OGbDYkhc7k-mcuQWC`DlP}|jsQwR zx7%^0y%*`VcWqqV*}8F?oylUp$u~*iwRf74!lrl2Nx;U5d*98(iAUZo!S`3+ZN&Ha z@8zNa;0cyU<$FtG*VoY6_Z-a=KyaZhGvfSrkXgj~ej+Z6Dd1$$3N=x5rZOU-`}-jS{x@fdj2IS&;gO7i(jZX-VK2&8`>t9pN}sf6wH;SaM5h?VrO zOL`jXjJ*D#b1tqS#~HDFRF5|2`qE?<&fl5Lk3$RnXR+w(KQ6jSzT%$T$U`5KK>zLIe0+c7W1GqH zlgr9%rZ@6;R~BiW!F{>Gz+0Yp@iOguiGwwCTiXI&LOXSf#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zcTg7dqe5T(8u#!8geAVqi}W2egLP+*Jl~g5F?`s%1uBm+FS3Y59~h02hwHbZyWF>x zX7hVnY1$7Sn#$q#AtC%#xO8p9FtB+iCKH3}pz!GO7>cVY)5pX{ys@txG{E>*$1 zXdeG;v1SUyZ;R+^(AHoWv3nOyRAbIx?!uVq-*$oR7S)^ zO?p2hn?ByTn-XLjjeqWWpPc--hdwyMyJWwyn^tq)9^m(rTliHk?8os&{HoN3HV#Er z%_CCOA^f-j$U1uitqi7v?pcSLa9rO*H2^@Uys>Y&7o{jG5SXcd0L5g-UKGxMz#q?z zRrPa_wvVsuMfX|t0C=iR+aI75&uyhiT&y>V$~8XRzeioW!{l^fh&6uv)YVp_hDKig zBg(+}Pw%DVWPPrs8%l2;^*-2O&^vw<^PN+W=|BAu&1BnyR3yv$;W{di?_rfx=DFP` z90GjRG-PNH!V4dwYULJd2@>Mjhp0jeIC>DG8TU~xLO@!6FRFakKFUzTRy@JWqcc8A z@2FQFzp_tRO*<$@18mwy*^0Gd(7B(ivcb_`!}K0<_q+Rzm8|lHER{H22{)*FvF!lO z;rkDuyNExGta|nUvi0`|@X2%#iMaV7QtP3El%d~$Mjr)P#e<#ky!8kLnmwZY@cC2R zN0%{9HLDp24;;dT4o5rmQ~5A*lRQ=F*|neI(x>Woq?yjGa{TJ{nv!H#XKz8o#Epf% Py6@$$nV%g08(R0jz-X`( diff --git a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php index b0897945ce..261de6ae47 100644 --- a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php @@ -582,9 +582,15 @@ class DatabaseTableChangeProcessor { * @param DatabaseTable $table */ protected function createTable(DatabaseTable $table) { - $columnData = array_map(function(IDatabaseTableColumn $column) { + $hasPrimaryKey = false; + $columnData = array_map(function(IDatabaseTableColumn $column) use (&$hasPrimaryKey) { + $data = $column->getData(); + if (isset($data['key']) && $data['key'] === 'PRIMARY') { + $hasPrimaryKey = true; + } + return [ - 'data' => $column->getData(), + 'data' => $data, 'name' => $column->getName() ]; }, $table->getColumns()); @@ -595,6 +601,13 @@ class DatabaseTableChangeProcessor { ]; }, $table->getIndices()); + // Auto columns are implicitly defined as the primary key by MySQL. + if ($hasPrimaryKey) { + $indexData = array_filter($indexData, function($key) { + return $key !== 'PRIMARY'; + }, ARRAY_FILTER_USE_KEY); + } + $this->dbEditor->createTable($table->getName(), $columnData, $indexData); foreach ($table->getForeignKeys() as $foreignKey) { diff --git a/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php b/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php index 3ca213c3cf..3c84ac5e7f 100644 --- a/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php +++ b/wcfsetup/install/files/lib/system/database/table/column/AbstractDatabaseTableColumn.class.php @@ -61,6 +61,12 @@ abstract class AbstractDatabaseTableColumn implements IDatabaseTableColumn { if ($this instanceof IAutoIncrementDatabaseTableColumn) { $data['autoIncrement'] = $this->isAutoIncremented() ? 1 : 0; + + // MySQL requires that there is only a single auto column per table *AND* + // that this column is defined as the primary key. + if ($data['autoIncrement'] === 1) { + $data['key'] = 'PRIMARY'; + } } if ($this instanceof IDecimalsDatabaseTableColumn && $this->getDecimals() !== null) { -- 2.20.1