Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F566203
20170918.ref.01.position.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
20170918.ref.01.position.php
View Options
<?php
$table
=
new
PhabricatorRepositoryRefPosition
();
$conn
=
$table
->
establishConnection
(
'w'
);
$key_name
=
'key_position'
;
try
{
queryfx
(
$conn
,
'ALTER TABLE %T DROP KEY %T'
,
$table
->
getTableName
(),
$key_name
);
}
catch
(
AphrontQueryException
$ex
)
{
// This key may or may not exist, depending on exactly when the install
// ran previous migrations and adjustments. We're just dropping it if it
// does exist.
// We're doing this first (outside of the lock) because the MySQL
// documentation says "if you ALTER TABLE a locked table, it may become
// unlocked".
}
queryfx
(
$conn
,
'LOCK TABLES %T WRITE'
,
$table
->
getTableName
());
$seen
=
array
();
foreach
(
new
LiskMigrationIterator
(
$table
)
as
$position
)
{
$cursor_id
=
$position
->
getCursorID
();
$hash
=
$position
->
getCommitIdentifier
();
// If this is the first copy of this row we've seen, mark it as seen and
// move on.
if
(
empty
(
$seen
[
$cursor_id
][
$hash
]))
{
$seen
[
$cursor_id
][
$hash
]
=
true
;
continue
;
}
// Otherwise, get rid of this row as it duplicates a row we saw previously.
$position
->
delete
();
}
queryfx
(
$conn
,
'ALTER TABLE %T ADD UNIQUE KEY %T (cursorID, commitIdentifier)'
,
$table
->
getTableName
(),
$key_name
);
queryfx
(
$conn
,
'UNLOCK TABLES'
);
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Tue, May 13, 10:51 AM (2 d)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
109906
Default Alt Text
20170918.ref.01.position.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment