mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 04:12:59 +00:00
Reorganize project part 3
This commit is contained in:
13
migrations/0001.sql
Normal file
13
migrations/0001.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE products (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
location_id INTEGER NOT NULL,
|
||||
qu_id_purchase INTEGER NOT NULL,
|
||||
qu_id_stock INTEGER NOT NULL,
|
||||
qu_factor_purchase_to_stock REAL NOT NULL,
|
||||
barcode TEXT,
|
||||
min_stock_amount INTEGER NOT NULL DEFAULT 0,
|
||||
default_best_before_days INTEGER NOT NULL DEFAULT 0,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
6
migrations/0002.sql
Normal file
6
migrations/0002.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE locations (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
6
migrations/0003.sql
Normal file
6
migrations/0003.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE quantity_units (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
9
migrations/0004.sql
Normal file
9
migrations/0004.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE stock (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
product_id INTEGER NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
best_before_date DATE,
|
||||
purchased_date DATE DEFAULT (datetime('now', 'localtime')),
|
||||
stock_id TEXT NOT NULL,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
12
migrations/0005.sql
Normal file
12
migrations/0005.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE stock_log (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
product_id INTEGER NOT NULL,
|
||||
amount INTEGER NOT NULL,
|
||||
best_before_date DATE,
|
||||
purchased_date DATE,
|
||||
used_date DATE,
|
||||
spoiled INTEGER NOT NULL DEFAULT 0,
|
||||
stock_id TEXT NOT NULL,
|
||||
transaction_type TEXT NOT NULL,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
19
migrations/0006.sql
Normal file
19
migrations/0006.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
INSERT INTO locations
|
||||
(name, description)
|
||||
VALUES
|
||||
('DefaultLocation', 'This is the first default location, edit or delete it');
|
||||
|
||||
INSERT INTO quantity_units
|
||||
(name, description)
|
||||
VALUES
|
||||
('DefaultQuantityUnit', 'This is the first default quantity unit, edit or delete it');
|
||||
|
||||
INSERT INTO products
|
||||
(name, description, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock)
|
||||
VALUES
|
||||
('DefaultProduct1', 'This is the first default product, edit or delete it', 1, 1, 1, 1);
|
||||
|
||||
INSERT INTO products
|
||||
(name, description, location_id, qu_id_purchase, qu_id_stock, qu_factor_purchase_to_stock)
|
||||
VALUES
|
||||
('DefaultProduct2', 'This is the second default product, edit or delete it', 1, 1, 1, 1);
|
9
migrations/0007.sql
Normal file
9
migrations/0007.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE VIEW stock_missing_products
|
||||
AS
|
||||
SELECT p.id, MAX(p.name) AS name, p.min_stock_amount - IFNULL(SUM(s.amount), 0) AS amount_missing
|
||||
FROM products p
|
||||
LEFT JOIN stock s
|
||||
ON p.id = s.product_id
|
||||
WHERE p.min_stock_amount != 0
|
||||
GROUP BY p.id
|
||||
HAVING IFNULL(SUM(s.amount), 0) < p.min_stock_amount
|
6
migrations/0008.sql
Normal file
6
migrations/0008.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE VIEW stock_current
|
||||
AS
|
||||
SELECT product_id, SUM(amount) AS amount, MIN(best_before_date) AS best_before_date
|
||||
FROM stock
|
||||
GROUP BY product_id
|
||||
ORDER BY MIN(best_before_date) ASC
|
7
migrations/0009.sql
Normal file
7
migrations/0009.sql
Normal file
@@ -0,0 +1,7 @@
|
||||
CREATE TABLE shopping_list (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
product_id INTEGER NOT NULL UNIQUE,
|
||||
amount INTEGER NOT NULL DEFAULT 0,
|
||||
amount_autoadded INTEGER NOT NULL DEFAULT 0,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
8
migrations/0010.sql
Normal file
8
migrations/0010.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE habits (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
period_type TEXT NOT NULL,
|
||||
period_days INTEGER,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
6
migrations/0011.sql
Normal file
6
migrations/0011.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE habits_log (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
habit_id INTEGER NOT NULL,
|
||||
tracked_time DATETIME,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
6
migrations/0012.sql
Normal file
6
migrations/0012.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE VIEW habits_current
|
||||
AS
|
||||
SELECT habit_id, MAX(tracked_time) AS last_tracked_time
|
||||
FROM habits_log
|
||||
GROUP BY habit_id
|
||||
ORDER BY MAX(tracked_time) DESC
|
8
migrations/0013.sql
Normal file
8
migrations/0013.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE batteries (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
description TEXT,
|
||||
used_in TEXT,
|
||||
charge_interval_days INTEGER NOT NULL DEFAULT 0,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
6
migrations/0014.sql
Normal file
6
migrations/0014.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE TABLE battery_charge_cycles (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
battery_id TEXT NOT NULL,
|
||||
tracked_time DATETIME,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
6
migrations/0015.sql
Normal file
6
migrations/0015.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE VIEW batteries_current
|
||||
AS
|
||||
SELECT battery_id, MAX(tracked_time) AS last_tracked_time
|
||||
FROM battery_charge_cycles
|
||||
GROUP BY battery_id
|
||||
ORDER BY MAX(tracked_time) DESC
|
1
migrations/0016.sql
Normal file
1
migrations/0016.sql
Normal file
@@ -0,0 +1 @@
|
||||
ALTER TABLE shopping_list RENAME TO shopping_list_old
|
8
migrations/0017.sql
Normal file
8
migrations/0017.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
CREATE TABLE shopping_list (
|
||||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
|
||||
product_id INTEGER,
|
||||
note TEXT,
|
||||
amount INTEGER NOT NULL DEFAULT 0,
|
||||
amount_autoadded INTEGER NOT NULL DEFAULT 0,
|
||||
row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime'))
|
||||
)
|
4
migrations/0018.sql
Normal file
4
migrations/0018.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
INSERT INTO shopping_list
|
||||
(product_id, amount, amount_autoadded, row_created_timestamp)
|
||||
SELECT product_id, amount, amount_autoadded, row_created_timestamp
|
||||
FROM shopping_list_old
|
1
migrations/0019.sql
Normal file
1
migrations/0019.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE shopping_list_old
|
Reference in New Issue
Block a user