X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=assistants%2Fmigrations.inc.php;h=93a720f8fef46d7c3f4fb7944de9a97219892946;hb=ffd3556b1654d0e96d50234306978dbac6b36518;hp=95d3b86dac4c83fa2364110260891cebdcae75d9;hpb=79cc0871640b08bbe5c5e7b132e7bcc934d20823;p=mirrors%2FSokoMan.git diff --git a/assistants/migrations.inc.php b/assistants/migrations.inc.php index 95d3b86..93a720f 100644 --- a/assistants/migrations.inc.php +++ b/assistants/migrations.inc.php @@ -1,6 +1,20 @@ -

populate column item_date_bought

db->safe_query_fetch('SELECT item_id,MIN(item_valid_from) AS item_valid_from FROM item GROUP BY item_id;'); +
+

-- Remove all uncountable items

+SELECT DISTINCT model_countable FROM model; +DELETE item FROM item LEFT JOIN barcode USING(barcode_id) LEFT JOIN model USING(model_id) WHERE model_countable=0; +UPDATE model SET model_countable=1; +

-- populate barcode table

db->safe_query_fetch('SELECT model_id as id, model_barcode as bar FROM model;', false); +//print_r($data); +echo("UPDATE item SET barcode_id=model_id;\n"); +echo("INSERT INTO barcode (barcode_id,model_id,barcode_name) VALUES\n"); +foreach($data as $line) echo("('".$line['id']."','".$line['id']."',".$this->db->quote($line['bar'])."),\n"); +?> +

-- populate columns item_date_bought and item_date_sold

db->safe_query_fetch('SELECT item_id,MIN(item_valid_from) AS min,MAX(item_valid_from) AS max FROM item GROUP BY item_id;', false); //print_r($data); echo("START TRANSACTION;\n"); -foreach($data as $line) echo("UPDATE item SET item_date_bought='".$line['item_valid_from']."' WHERE item_id=".$line['item_id'].";\n"); +foreach($data as $line) echo("UPDATE item SET item_date_bought='".$line['min']."',item_date_sold='".$line['max']."' WHERE item_id=".$line['item_id'].";\n"); echo("COMMIT;\n"); +?> +