Add migration to make sort_order consecutive

This commit is contained in:
Hannes Verschore 2015-10-27 15:08:14 +01:00
Родитель 84db76205a
Коммит a16c32c78a
1 изменённых файлов: 17 добавлений и 0 удалений

17
database/migration-2.php Normal file
Просмотреть файл

@ -0,0 +1,17 @@
<?php
// Demote 'stamp' to a number that will be sequential to base off the sorting.
$migrate = function() {
$query = mysql_query("SELECT distinct(machine) as machine FROM awfy_run") or die(mysql_error());
while($run = mysql_fetch_object($query)) {
mysql_query("SET @pos := 0;")or die (mysql_error());
mysql_query("UPDATE awfy_run
SET sort_order = ( SELECT @pos := @pos + 1 )
WHERE machine = ".$run->machine." ORDER BY sort_order ASC;") or die(mysql_error());
}
};
$rollback = function() {
// Impossible to undo.
};