mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Auto-compact stock entries (closes #1343)
This commit is contained in:
18
migrations/0143.sql
Normal file
18
migrations/0143.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE VIEW stock_splits
|
||||
AS
|
||||
|
||||
/*
|
||||
Helper view which shows splitted stock rows which could be compacted
|
||||
*/
|
||||
|
||||
SELECT
|
||||
product_id,
|
||||
SUM(amount) AS total_amount,
|
||||
MIN(stock_id) AS stock_id_to_keep,
|
||||
MIN(id) AS id_to_keep,
|
||||
GROUP_CONCAT(id) AS id_group,
|
||||
GROUP_CONCAT(stock_id) AS stock_id_group,
|
||||
id -- Dummy
|
||||
FROM stock
|
||||
GROUP BY product_id, best_before_date, purchased_date, price, open, opened_date, location_id, shopping_location_id
|
||||
HAVING COUNT(*) > 1;
|
7
migrations/0144.php
Normal file
7
migrations/0144.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
// This is executed inside DatabaseMigrationService class/context
|
||||
|
||||
use Grocy\Services\StockService;
|
||||
|
||||
$this->getStockService()->CompactStockEntries();
|
Reference in New Issue
Block a user