Skip to content

Commit

Permalink
Add script to migrate test data to oracle database
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefano Da Ros committed Nov 15, 2018
1 parent 9e6a051 commit 8b6684d
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 0 deletions.
15 changes: 15 additions & 0 deletions build/migrate-to-oracle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -x

ORACLE_HOST=${ORACLE_HOST:=localhost}
ORACLE_USER=${ORACLE_USER:=system}
ORACLE_DATABASE=${ORACLE_DATABASE:=xe}
ORACLE_DUMP_FILE=${ORACLE_DUMP_FILE:=oracle.dmp}
# Source sensitive environment variables from .env
if [ -f .env ]
then
# shellcheck source=.env
. ./.env
fi
sqlplus ${ORACLE_USER}/${ORACLE_PASSWORD}@${ORACLE_HOST}/${ORACLE_DATABASE} @\""${ORACLE_DUMP_FILE}\""

82 changes: 82 additions & 0 deletions build/oracle/oracle.dmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
CREATE TABLE equipment (
"id" number generated by default as identity,
"name" nvarchar2(256),
"acquisition_cost" number(10,5),
"purchase_date" timestamp(3) with time zone,
primary key ("id")
);
INSERT INTO equipment ("name", "acquisition_cost", "purchase_date")
VALUES ('Bialetti Moka Express 6 cup',25.95,to_timestamp_tz('2017-12-12T12:00:00+00:00', 'YYYY-MM-DD"T"HH24:MI:SSXFF3TZH:TZM'));
INSERT INTO equipment ("name", "acquisition_cost", "purchase_date")
VALUES ('Sanremo Café Racer',8477.85,to_timestamp_tz('2017-12-12T12:00:00+00:00', 'YYYY-MM-DD"T"HH24:MI:SSXFF3TZH:TZM'));
INSERT INTO equipment ("name", "acquisition_cost", "purchase_date")
VALUES ('Buntfink SteelKettle',39.95,to_timestamp_tz('2017-12-12T12:00:00+00:00', 'YYYY-MM-DD"T"HH24:MI:SSXFF3TZH:TZM'));
INSERT INTO equipment ("name", "acquisition_cost", "purchase_date")
VALUES ('Copper Coffee Pot Cezve',49.95,to_timestamp_tz('2017-12-12T12:00:00+00:00', 'YYYY-MM-DD"T"HH24:MI:SSXFF3TZH:TZM'));

CREATE TABLE ingredients (
"id" number generated by default as identity,
"name" nvarchar2(1024),
"description" nvarchar2(1024),
primary key ("id")
);
INSERT INTO ingredients ("name","description")
VALUES ('V60 paper filter', 'The best paper filter on the market');
INSERT INTO ingredients ("name","description")
VALUES ('Caffé Borbone Beans - Miscela Blu', 'Excellent beans for espresso');
INSERT INTO ingredients ("name","description")
VALUES ('Caffé Borbone Beans - Miscela Oro', 'Well balanced beans');
INSERT INTO ingredients ("name","description")
VALUES ('Filtered Water', 'Contains the perfect water hardness for espresso');

CREATE TABLE inventory (
"ingredient_id" number,
"quantity" number,
"unit_of_measure" nvarchar2(256),
foreign key ("ingredient_id") references ingredients("id"),
primary key ("ingredient_id")
);
INSERT INTO inventory ("ingredient_id", "quantity", "unit_of_measure")
VALUES (1, 100, 'Each');
INSERT INTO inventory ("ingredient_id", "quantity", "unit_of_measure")
VALUES (2, 10000, 'Gram');
INSERT INTO inventory ("ingredient_id", "quantity", "unit_of_measure")
VALUES (3, 5000, 'Gram');
INSERT INTO inventory ("ingredient_id", "quantity", "unit_of_measure")
VALUES (4, 100, 'Liter');

CREATE TABLE recipes (
"id" number generated by default as identity,
"equipment_id" number,
"name" nvarchar2(1024),
"instructions" nvarchar2(1024),
foreign key ("equipment_id") references equipment("id"),
primary key ("id")
);
INSERT INTO recipes ("name", "instructions", "equipment_id")
VALUES ('Espresso single shot','do this', 2);
INSERT INTO recipes ("name", "instructions", "equipment_id")
VALUES ('Ibrik (turkish) coffee', 'do that', 4);
INSERT INTO recipes ("name", "instructions", "equipment_id")
VALUES ('Filter coffee', 'do bar', 3);

CREATE TABLE ingredient_recipe (
"id" number generated by default as identity,
"ingredient_id" number unique,
"recipe_id" number unique,
"quantity" number,
"unit_of_measure" nvarchar2(1024),
foreign key ("ingredient_id") references ingredients("id"),
foreign key ("recipe_id") references recipes("id"),
primary key ("ingredient_id", "recipe_id")
);
INSERT INTO ingredient_recipe ("id", "ingredient_id", "recipe_id", "quantity", "unit_of_measure")
VALUES (1, 2, 3, 30, 'Gram');
INSERT INTO ingredient_recipe ("id", "ingredient_id", "recipe_id", "quantity", "unit_of_measure")
VALUES (2, 1, 3, 1, 'Each');
INSERT INTO ingredient_recipe ("id", "ingredient_id", "recipe_id", "quantity", "unit_of_measure")
VALUES (3, 4, 3, 0.5, 'Liter');
INSERT INTO ingredient_recipe ("id", "ingredient_id", "recipe_id", "quantity", "unit_of_measure")
VALUES (4, 3, 2, 20, 'Gram');
INSERT INTO ingredient_recipe ("id", "ingredient_id", "recipe_id", "quantity", "unit_of_measure")
VALUES (5, 4, 2, 0.15, 'Liter');

0 comments on commit 8b6684d

Please sign in to comment.