From 16bfb1cf2f78a625b328fc36e8fa29413a67b328 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 18 Jul 2023 01:09:09 +0100 Subject: [PATCH] simplify sql create tables --- databases/mysql/README.md | 10 +++++----- .../sql/{create_database.sql => 0_create_database.sql} | 0 databases/mysql/sql/1_bank_details.sql | 6 ++++++ databases/mysql/sql/2_branch_details.sql | 6 ++++++ databases/mysql/sql/3_customer_details.sql | 6 ++++++ databases/mysql/sql/4_teller_details.sql | 6 ++++++ databases/mysql/sql/bank_details.sql | 7 ------- databases/mysql/sql/branch_details.sql | 7 ------- databases/mysql/sql/customer_details.sql | 7 ------- databases/mysql/sql/teller_details.sql | 7 ------- graphql/juniper-advanced/mysql-schema.sql | 4 ++-- 11 files changed, 31 insertions(+), 35 deletions(-) rename databases/mysql/sql/{create_database.sql => 0_create_database.sql} (100%) create mode 100644 databases/mysql/sql/1_bank_details.sql create mode 100644 databases/mysql/sql/2_branch_details.sql create mode 100644 databases/mysql/sql/3_customer_details.sql create mode 100644 databases/mysql/sql/4_teller_details.sql delete mode 100644 databases/mysql/sql/bank_details.sql delete mode 100644 databases/mysql/sql/branch_details.sql delete mode 100644 databases/mysql/sql/customer_details.sql delete mode 100644 databases/mysql/sql/teller_details.sql diff --git a/databases/mysql/README.md b/databases/mysql/README.md index d99f367..a323690 100644 --- a/databases/mysql/README.md +++ b/databases/mysql/README.md @@ -18,11 +18,11 @@ $ pwd The `sql` directory contains the SQL files used for database setup: ```sh - mysql -u root -p < sql/create_database.sql - mysql -u root -p my_bank < sql/bank_details.sql - mysql -u root -p my_bank < sql/branch_details.sql - mysql -u root -p my_bank < sql/teller_details.sql - mysql -u root -p my_bank < sql/customer_details.sql + mysql -u root -p < sql/0_create_database.sql + mysql -u root -p my_bank < sql/1_bank_details.sql + mysql -u root -p my_bank < sql/2_branch_details.sql + mysql -u root -p my_bank < sql/3_teller_details.sql + mysql -u root -p my_bank < sql/4_customer_details.sql ``` For each step you will be prompted for the root user's password. If there's no password set on the root use, just hit enter again. diff --git a/databases/mysql/sql/create_database.sql b/databases/mysql/sql/0_create_database.sql similarity index 100% rename from databases/mysql/sql/create_database.sql rename to databases/mysql/sql/0_create_database.sql diff --git a/databases/mysql/sql/1_bank_details.sql b/databases/mysql/sql/1_bank_details.sql new file mode 100644 index 0000000..9f84e60 --- /dev/null +++ b/databases/mysql/sql/1_bank_details.sql @@ -0,0 +1,6 @@ +CREATE TABLE `bank_details` ( + `id` BIGINT AUTO_INCREMENT PRIMARY KEY, + `bank_name` VARCHAR(30) NOT NULL, + `country` VARCHAR(30) NOT NULL, + `date_added` DATETIME DEFAULT CURRENT_TIMESTAMP +) CHARSET=utf8mb4; diff --git a/databases/mysql/sql/2_branch_details.sql b/databases/mysql/sql/2_branch_details.sql new file mode 100644 index 0000000..0eb1352 --- /dev/null +++ b/databases/mysql/sql/2_branch_details.sql @@ -0,0 +1,6 @@ +CREATE TABLE `branch_details` ( + `id` BIGINT AUTO_INCREMENT PRIMARY KEY, + `branch_name` VARCHAR(30) NOT NULL, + `location` VARCHAR(30) NOT NULL, + `date_added` DATETIME DEFAULT CURRENT_TIMESTAMP +) CHARSET=utf8mb4; diff --git a/databases/mysql/sql/3_customer_details.sql b/databases/mysql/sql/3_customer_details.sql new file mode 100644 index 0000000..8d19b90 --- /dev/null +++ b/databases/mysql/sql/3_customer_details.sql @@ -0,0 +1,6 @@ +CREATE TABLE `customer_details` ( + `id` BIGINT AUTO_INCREMENT PRIMARY KEY, + `customer_name` VARCHAR(100) NOT NULL, + `branch_name` VARCHAR(30) NOT NULL, + `date_added` DATETIME DEFAULT CURRENT_TIMESTAMP +) CHARSET=utf8mb4; diff --git a/databases/mysql/sql/4_teller_details.sql b/databases/mysql/sql/4_teller_details.sql new file mode 100644 index 0000000..197ffb6 --- /dev/null +++ b/databases/mysql/sql/4_teller_details.sql @@ -0,0 +1,6 @@ +CREATE TABLE `teller_details` ( + `id` BIGINT AUTO_INCREMENT PRIMARY KEY, + `teller_name` VARCHAR(100) NOT NULL, + `branch_name` VARCHAR(30) NOT NULL, + `date_added` DATETIME DEFAULT CURRENT_TIMESTAMP +) CHARSET=utf8mb4; diff --git a/databases/mysql/sql/bank_details.sql b/databases/mysql/sql/bank_details.sql deleted file mode 100644 index b6b52bb..0000000 --- a/databases/mysql/sql/bank_details.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `bank_details` ( - `id` int NOT NULL AUTO_INCREMENT, - `bank_name` VARCHAR(30) DEFAULT '', - `country` VARCHAR(30) DEFAULT '', - `date_added` DATETIME DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; diff --git a/databases/mysql/sql/branch_details.sql b/databases/mysql/sql/branch_details.sql deleted file mode 100644 index 965433d..0000000 --- a/databases/mysql/sql/branch_details.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `branch_details` ( - `id` int NOT NULL AUTO_INCREMENT, - `branch_name` VARCHAR(30) DEFAULT '', - `location` VARCHAR(30) DEFAULT '', - `date_added` DATETIME DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; diff --git a/databases/mysql/sql/customer_details.sql b/databases/mysql/sql/customer_details.sql deleted file mode 100644 index 66702ed..0000000 --- a/databases/mysql/sql/customer_details.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `customer_details` ( - `id` INT NOT NULL AUTO_INCREMENT, - `customer_name` VARCHAR(100) DEFAULT '', - `branch_name` VARCHAR(30) DEFAULT '', - `date_added` DATETIME DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; diff --git a/databases/mysql/sql/teller_details.sql b/databases/mysql/sql/teller_details.sql deleted file mode 100644 index 1234d76..0000000 --- a/databases/mysql/sql/teller_details.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE `teller_details` ( - `id` int NOT NULL AUTO_INCREMENT, - `teller_name` varchar(100) DEFAULT '', - `branch_name` varchar(30) DEFAULT '', - `date_added` datetime DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; diff --git a/graphql/juniper-advanced/mysql-schema.sql b/graphql/juniper-advanced/mysql-schema.sql index 40f5a3a..2fde582 100644 --- a/graphql/juniper-advanced/mysql-schema.sql +++ b/graphql/juniper-advanced/mysql-schema.sql @@ -30,7 +30,7 @@ CREATE TABLE `product` ( PRIMARY KEY (`id`), KEY `product_fk0` (`user_id`), CONSTRAINT `product_fk0` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -55,7 +55,7 @@ CREATE TABLE `user` ( `email` varchar(255) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `email` (`email`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; --