File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -133,9 +133,20 @@ private function initTableVersionTable(): void
133133 * schema.
134134 */
135135 $ update = [
136- 'ALTER TABLE ' . $ this ->prefix . '_tableVersion DROP INDEX IF EXISTS SELECT CONSTRAINT_NAME ' .
137- 'FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE TABLE_NAME= ' . $ this ->prefix . '_tableVersion ' ,
138- 'ALTER TABLE ' . $ this ->prefix . '_tableVersion ADD CONSTRAINT _name PRIMARY KEY CLUSTERED (_name) ' ,
136+ // Use dynamic SQL to drop the existing unique constraint
137+ 'DECLARE @constraintName NVARCHAR(128); ' .
138+ 'SELECT @constraintName = CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS ' .
139+ 'WHERE TABLE_NAME = \'' . $ this ->prefix . '_tableVersion \' AND CONSTRAINT_TYPE = \'UNIQUE \'; ' .
140+ 'IF @constraintName IS NOT NULL ' .
141+ 'BEGIN ' .
142+ 'EXEC( \'ALTER TABLE ' . $ this ->prefix . '_tableVersion ' .
143+ ' DROP CONSTRAINT \' + @constraintName); ' .
144+ 'END; ' ,
145+
146+ // Add the new primary key constraint
147+ 'ALTER TABLE ' . $ this ->prefix . '_tableVersion ' .
148+ ' ADD CONSTRAINT PK_ ' . $ this ->prefix . '_tableVersion ' .
149+ ' PRIMARY KEY CLUSTERED (_name); ' ,
139150 ];
140151 break ;
141152 case 'sqlite ' :
You can’t perform that action at this time.
0 commit comments