Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Hugo Hörnquist
Stupan
Commits
a928d4a6
Commit
a928d4a6
authored
Apr 08, 2018
by
Hugo Hörnquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added patch file for database
parent
72cf5d04
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
0 deletions
+51
-0
diff.sql
diff.sql
+51
-0
No files found.
diff.sql
0 → 100644
View file @
a928d4a6
/*
* This file is to patch up an already existing SQLite file
* to use the new product diffing system
*/
CREATE
TABLE
diff_help
(
id
INTEGER
PRIMARY
KEY
NOT
NULL
,
product_id
INTEGER
NOT
NULL
,
amount
INTEGER
,
FOREIGN
KEY
(
product_id
)
REFERENCES
products
(
id
)
);
CREATE
VIEW
diff_view
AS
SELECT
d
.
id
AS
id
,
p
.
id
AS
product_id
,
p
.
sale_status
AS
sale_status
,
-- visible border
p
.
name
AS
name
,
s
.
active
AS
expected
,
d
.
amount
AS
actual
,
d
.
amount
-
s
.
active
AS
diff
FROM
products
p
INNER
JOIN
stock
s
ON
p
.
id
=
s
.
product_id
INNER
JOIN
diff_help
d
ON
p
.
id
=
d
.
product_id
;
CREATE
TRIGGER
after_diff_help_delete_last
AFTER
DELETE
ON
diff_help
FOR
EACH
ROW
WHEN
(
SELECT
count
(
1
)
=
0
FROM
diff_help
)
BEGIN
INSERT
INTO
diff_help
(
product_id
)
SELECT
id
FROM
products
p
;
END
;
CREATE
TRIGGER
diff_view_transfer
INSTEAD
OF
DELETE
ON
diff_view
BEGIN
UPDATE
stock
SET
active
=
OLD
.
actual
WHERE
OLD
.
actual
IS
NOT
NULL
AND
product_id
=
OLD
.
product_id
;
INSERT
INTO
stock_diff
(
product_id
,
expected
,
actual
)
SELECT
OLD
.
product_id
,
OLD
.
expected
,
OLD
.
actual
WHERE
OLD
.
actual
IS
NOT
NULL
;
DELETE
FROM
diff_help
WHERE
id
=
OLD
.
id
;
END
;
INSERT
INTO
diff_help
(
product_id
)
SELECT
id
FROM
products
LIMIT
1
;
DELETE
FROM
diff_help
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment