From 8b6684d034763d1008a2d7bbadf2fa80abab7364 Mon Sep 17 00:00:00 2001 From: Stefano Da Ros Date: Thu, 15 Nov 2018 18:22:46 +0100 Subject: [PATCH] Add script to migrate test data to oracle database --- build/migrate-to-oracle.sh | 15 +++++++ build/oracle/oracle.dmp | 82 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100755 build/migrate-to-oracle.sh create mode 100644 build/oracle/oracle.dmp diff --git a/build/migrate-to-oracle.sh b/build/migrate-to-oracle.sh new file mode 100755 index 0000000..320e751 --- /dev/null +++ b/build/migrate-to-oracle.sh @@ -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}\"" + diff --git a/build/oracle/oracle.dmp b/build/oracle/oracle.dmp new file mode 100644 index 0000000..098b431 --- /dev/null +++ b/build/oracle/oracle.dmp @@ -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'); \ No newline at end of file