mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
Add SQL (without test support)
This commit is contained in:
parent
191926ce68
commit
84e17c448c
12
sql/README.md
Normal file
12
sql/README.md
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# Introduction
|
||||||
|
This code aims to be based on ISO-compliant, therefore database-agnostic.
|
||||||
|
However, Data Definition Language (DDL) usually involves vendor variants.
|
||||||
|
|
||||||
|
# Setup
|
||||||
|
Create database structure: see ./structure/<VARIANT>/create.sql
|
||||||
|
Load test data: see ./test/data/load.sql
|
||||||
|
|
||||||
|
# Execution
|
||||||
|
Execute SQL script: see /code/update_quality.sql
|
||||||
|
TODO: Introduce test framework - vendor specific
|
||||||
|
|
||||||
69
sql/code/update_quality.sql
Normal file
69
sql/code/update_quality.sql
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
UPDATE item
|
||||||
|
SET
|
||||||
|
quality = quality - 1
|
||||||
|
WHERE 1=1
|
||||||
|
AND ( name <> 'Aged Brie' AND name <> 'Backstage passes to a TAFKAL80ETC concert')
|
||||||
|
AND quality > 0
|
||||||
|
AND name <> 'Sulfuras, Hand of Ragnaros'
|
||||||
|
;
|
||||||
|
|
||||||
|
UPDATE item
|
||||||
|
SET
|
||||||
|
quality = quality + 1
|
||||||
|
WHERE 1=1
|
||||||
|
AND NOT ( name <> 'Aged Brie' AND name <> 'Backstage passes to a TAFKAL80ETC concert')
|
||||||
|
AND quality < 50
|
||||||
|
AND name = 'Backstage passes to a TAFKAL80ETC concert'
|
||||||
|
AND sellIn < 11
|
||||||
|
AND quality < 50
|
||||||
|
;
|
||||||
|
|
||||||
|
UPDATE item
|
||||||
|
SET
|
||||||
|
quality = quality + 1
|
||||||
|
WHERE 1=1
|
||||||
|
AND NOT ( name <> 'Aged Brie' AND name <> 'Backstage passes to a TAFKAL80ETC concert')
|
||||||
|
AND quality < 50
|
||||||
|
AND name = 'Backstage passes to a TAFKAL80ETC concert'
|
||||||
|
AND sellIn < 6
|
||||||
|
AND quality < 50
|
||||||
|
;
|
||||||
|
|
||||||
|
UPDATE item
|
||||||
|
SET
|
||||||
|
sellIn = sellIn - 1
|
||||||
|
WHERE 1=1
|
||||||
|
AND name <> 'Sulfuras, Hand of Ragnaros'
|
||||||
|
;
|
||||||
|
|
||||||
|
UPDATE item
|
||||||
|
SET
|
||||||
|
quality = quality - 1
|
||||||
|
WHERE 1=1
|
||||||
|
AND sellIn < 0
|
||||||
|
AND name <> 'Aged Brie'
|
||||||
|
AND name <> 'Backstage passes to a TAFKAL80ETC concert'
|
||||||
|
AND quality > 0
|
||||||
|
AND name <> 'Sulfuras, Hand of Ragnaros'
|
||||||
|
;
|
||||||
|
|
||||||
|
UPDATE item
|
||||||
|
SET
|
||||||
|
quality = quality - quality
|
||||||
|
WHERE 1=1
|
||||||
|
AND sellIn < 0
|
||||||
|
AND name <> 'Aged Brie'
|
||||||
|
AND NOT (name <> 'Backstage passes to a TAFKAL80ETC concert')
|
||||||
|
;
|
||||||
|
|
||||||
|
UPDATE item
|
||||||
|
SET
|
||||||
|
quality = quality + 1
|
||||||
|
WHERE 1=1
|
||||||
|
AND sellIn < 0
|
||||||
|
AND NOT (name <> 'Aged Brie')
|
||||||
|
AND quality < 50
|
||||||
|
AND name <> 'Sulfuras, Hand of Ragnaros'
|
||||||
|
;
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
9
sql/structure/postgreSQL/create.sql
Normal file
9
sql/structure/postgreSQL/create.sql
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
CREATE DATABASE gilded_rose;
|
||||||
|
|
||||||
|
\connect gilded_rose;
|
||||||
|
|
||||||
|
CREATE TABLE item (
|
||||||
|
name CHARACTER VARYING(100) NOT NULL,
|
||||||
|
sellIn INTEGER,
|
||||||
|
quality INTEGER NOT NULL
|
||||||
|
);
|
||||||
15
sql/test/data/load.sql
Normal file
15
sql/test/data/load.sql
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
DELETE FROM item;
|
||||||
|
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('+5 Dexterity Vest', 10, 20);
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Aged Brie', 2, 0);
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Elixir of the Mongoose', 5, 7);
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Sulfuras, Hand of Ragnaros', 0, 80);
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Sulfuras, Hand of Ragnaros', -1, 80);
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 15, 20);
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 10, 49);
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Backstage passes to a TAFKAL80ETC concert', 5, 49);
|
||||||
|
|
||||||
|
-- this conjured item does not work properly yet
|
||||||
|
INSERT INTO item (name, sellIn, quality) VALUES ('Conjured Mana Cake', 3, 6);
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
Loading…
Reference in New Issue
Block a user