emode database for the DS53 class

main
Shad Amethyst 2 years ago
parent 2389a72430
commit 91a754d7a2

1
.gitignore vendored

@ -0,0 +1 @@
emode/*.csv

@ -1,6 +1,6 @@
# ds52-db
Database dumps from the DS52 class, in MySQL and Docker form.
Database dumps from the DS52 and DS53 class, in MySQL and Docker form.
The DS52 class uses shady Windows Server VMs, which contain an equivalently shady installation of Oracle SQL.
The VM is 14GB in size, and has incredibly poor accessibility.
@ -14,6 +14,7 @@ The currently-available images are:
- [`ds52-cafe`](https://hub.docker.com/r/shadamethyst/ds52-cafe)
- *ds52-gescom* (TODO)
- *ds52-course* (TODO)
- [`ds53-emode`](https://hub.docker.com/r/shadamethyst/ds52-cafe)
## TODO

@ -0,0 +1,6 @@
FROM mariadb:latest
ADD ds53-emode.sql /docker-entrypoint-initdb.d/ds53-emode.sql
ENV MARIADB_PASSWORD="emode"
ENV MARIADB_USER="emode"
ENV MARIADB_ROOT_PASSWORD="ds53-emode-root"
ENV MARIADB_DATABASE="emode"

@ -0,0 +1,127 @@
DROP TABLE IF EXISTS article_color_lookup;
CREATE TABLE article_color_lookup (
article_code INT NOT NULL,
color_code INT NOT NULL,
article_label VARCHAR(45),
color_label VARCHAR(30),
category VARCHAR(25),
sale_price DECIMAL(8,2),
family_name VARCHAR(20),
family_code VARCHAR(3),
PRIMARY KEY (article_code, color_code)
);
LOAD DATA LOCAL INFILE './emode/article_color_lookup.csv' INTO TABLE article_color_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(
article_code,
color_code,
article_label,
color_label,
category,
sale_price,
family_name,
family_code
);
DROP TABLE IF EXISTS article_lookup;
CREATE TABLE article_lookup (
article_code INT NOT NULL,
article_label VARCHAR(45),
category VARCHAR(25),
sale_price DECIMAL(8,2),
family_name VARCHAR(20),
family_code VARCHAR(3),
PRIMARY KEY (article_code)
);
LOAD DATA LOCAL INFILE './emode/article_lookup.csv' INTO TABLE article_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (
article_code,
article_label,
category,
sale_price,
family_name,
family_code
);
DROP TABLE IF EXISTS calendar_year_lookup;
CREATE TABLE calendar_year_lookup (
week_key INT NOT NULL,
week_in_year INT NOT NULL,
year INT NOT NULL,
fiscal_period VARCHAR(4),
year_week VARCHAR(7) NOT NULL,
quarter INT NOT NULL,
month_name VARCHAR(10) NOT NULL,
month INT NOT NULL,
holiday_flag VARCHAR(1),
PRIMARY KEY (week_key)
);
LOAD DATA LOCAL INFILE './emode/calendar_year_lookup.csv' INTO TABLE calendar_year_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(
week_key,
week_in_year,
year,
fiscal_period,
year_week,
quarter,
month_name,
month,
holiday_flag
);
DROP TABLE IF EXISTS outlet_lookup;
CREATE TABLE outlet_lookup (
shop_name VARCHAR(30),
address_1 VARCHAR(20),
manager VARCHAR(10),
date_open DATE NOT NULL,
open VARCHAR(1),
owned_outright VARCHAR(1),
floor_space INT,
zip_code VARCHAR(6),
city VARCHAR(20),
state VARCHAR(20),
shop_code INT NOT NULL,
PRIMARY KEY (shop_code)
);
LOAD DATA LOCAL INFILE './emode/outlet_lookup.csv' INTO TABLE outlet_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(
shop_name,
address_1,
manager,
@date_open,
open,
owned_outright,
floor_space,
zip_code,
city,
state,
shop_code
)
SET date_open = STR_TO_DATE(@date_open, "%d-%b-%y");
DROP TABLE IF EXISTS shop_facts;
CREATE TABLE shop_facts (
id INT NOT NULL AUTO_INCREMENT,
article_code INT NOT NULL,
color_code INT NOT NULL,
week_key INT NOT NULL,
shop_code INT NOT NULL,
margin DECIMAL(13,2) NOT NULL,
amount_sold DECIMAL(13,2) NOT NULL,
quantity_sold DECIMAL(13,2) NOT NULL,
PRIMARY KEY (id)
);
LOAD DATA LOCAL INFILE './emode/shop_facts.csv' INTO TABLE shop_facts FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (
id,
article_code,
color_code,
week_key,
shop_code,
margin,
amount_sold,
quantity_sold
);

@ -0,0 +1,191 @@
# DB DS53
## AGG_YR_QT_RN_ST_LN_CA_SR
```sql
ID INT
YEAR INT
QUARTER VARCHAR(2)
STATE VARCHAR(20)
LINE VARCHAR(20)
CATEGORY VARCHAR(25)
SALES_REVENUE INT
```
## AGG_YR_THRU_SN_SR_QT_MA
```sql
ID INT
YEAR INT
QUARTER VARCHAR(2)
MONTH INT
MONTH_NAME VARCHAR(10)
WEEK INT
CITY VARCHAR(20)
STORE_NAME VARCHAR(30)
SALES_REVENUE INT
QUANTITY_SOLD INT
MARGIN INT
```
## ARTICLE_COLOR_LOOKUP
```sql
article_code INT NOT NULL,
color_code INT NOT NULL,
article_label VARCHAR(45),
color_label VARCHAR(30),
category VARCHAR(25),
sale_price DECIMAL(8,2),
family_name VARCHAR(20),
family_code VARCHAR(3),
PRIMARY KEY (article_code, color_code)
```
```
LOAD DATA LOCAL INFILE './emode/article_color_lookup.csv' INTO TABLE article_color_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(
article_code,
color_code,
article_label,
color_label,
category,
sale_price,
family_name,
family_code
);
```
## ARTICLE_LOOKUP
```sql
article_code INT NOT NULL,
article_label VARCHAR(45),
category VARCHAR(25),
sale_price DECIMAL(8,2),
family_name VARCHAR(20),
family_code VARCHAR(3),
PRIMARY KEY (article_code)
```
```
LOAD DATA LOCAL INFILE './emode/article_lookup.csv' INTO TABLE article_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (article_code, article_label, category, sale_price, family_name, family_code);
```
## ARTICLE_LOOKUP_CRITERIA
```sql
ID INT
ARTICLE_CODE INT
CRITERIA_TYPE VARCHAR(2)
CRITERIA VARCHAR(2)
CRITERIA_TYPE_LABEL VARCHAR(20)
CRITERIA_LABEL VARCHAR(40)
```
## CALENDAR_YEAR_LOOKUP
```sql
week_key INT NOT NULL,
week_in_year INT NOT NULL,
year INT NOT NULL,
fiscal_period VARCHAR(4),
year_week VARCHAR(7) NOT NULL,
quarter INT NOT NULL,
month_name VARCHAR(10) NOT NULL,
month INT NOT NULL,
holiday_flag VARCHAR(1),
PRIMARY KEY (week_key)
```
```
LOAD DATA LOCAL INFILE './emode/calendar_year_lookup.csv' INTO TABLE calendar_year_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(
week_key,
week_in_year,
year,
fiscal_period,
year_week,
quarter,
month_name,
month,
holiday_flag
);
```
## OUTLET_LOOKUP
```sql
shop_name VARCHAR(30),
address_1 VARCHAR(20),
manager VARCHAR(10),
date_open DATE NOT NULL,
open VARCHAR(1),
owned_outright VARCHAR(1),
floor_space INT,
zip_code VARCHAR(6),
city VARCHAR(20),
state VARCHAR(20),
shop_code INT NOT NULL,
PRIMARY KEY (shop_code)
```
Warning: addresses contain commas, which the dump did not escape
```
LOAD DATA LOCAL INFILE './emode/outlet_lookup.csv' INTO TABLE outlet_lookup FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
(
shop_name,
address_1,
manager,
@date_open,
open,
owned_outright,
floor_space,
zip_code,
city,
state,
shop_code
)
SET date_open = STR_TO_DATE(@date_open, "%d-%b-%y");
```
## PRODUCT_PROMOTION_FACTS
```sql
id INT
article_code INT
week_key INT
duration INT
promotion_key INT
promotion_cost INT
```
## PROMOTION_LOOKUP
```sql
promotion_key INT
promotion VARCHAR(1)
print_flag VARCHAR(1)
radio_flag VARCHAR(1)
television_flag VARCHAR(1)
direct_mail_flag VARCHAR(1)
```
## SHOP_FACTS
```sql
id INT NOT NULL AUTO_INCREMENT,
article_code INT NOT NULL,
color_code INT NOT NULL,
week_key INT NOT NULL,
shop_code INT NOT NULL,
margin DECIMAL(13,2) NOT NULL,
amount_sold DECIMAL(13,2) NOT NULL,
quantity_sold DECIMAL(13,2) NOT NULL,
PRIMARY KEY (id)
```
```
LOAD DATA LOCAL INFILE './emode/shop_facts.csv' INTO TABLE shop_facts FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' (id, article_code, color_code, week_key, shop_code, margin, amount_sold, quantity_sold);
```

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -0,0 +1,36 @@
const fs = require("fs");
const path = require("path");
const raw = fs.readFileSync(path.join(__dirname, "./emode.dump"), 'utf8').replace(/\r\n/g, '\n');
const escapes = [
"32, Tolbooth Street",
"303, 33rd Street",
"33, Magnolia Street",
"44, 5th Avenue",
"32, Sundance Place",
"8260, Ocean Lane",
"5, Newbury Avenue",
"Belts,bags,wallets",
"Hats,gloves,scarves",
"Belts, bags, wallets",
"Hats, gloves, scarves",
];
const split = raw.split("SQL>");
for (const db of split) {
let [firstLine, ...rest] = db.split("\n");
const data = /^\s*select \* from ([A-Z_]+);$/.exec(firstLine);
rest = rest.filter((line) => !!line.trim() && !line.match(/^\d+ rows selected\.$/));
rest = rest.map((line) => {
for (const escape of escapes) {
line = line.replace(new RegExp(escape + "\\s*", "g"), `"${escape}"`);
}
return line.replace(/\s*(?=,|$)/g, '');
});
if (data) {
fs.writeFileSync(path.join(__dirname, `${data[1].toLowerCase()}.csv`), rest.join('\n'));
}
}
Loading…
Cancel
Save