From 6962d612ef607bdab384c406a862cc7fb78deac6 Mon Sep 17 00:00:00 2001 From: Alejandro Alvarez Date: Tue, 21 Jan 2025 13:40:27 +0100 Subject: [PATCH] DAT-19303 DevOps :: TiDB :: Add ability to run custom SQL script that creates tables and table data against created db (#975) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✨ (docker-compose.yml): add TiDB and MySQL client services for enhanced database support 📝 (docker-compose.yml): update quotes for consistency and remove unnecessary blank lines * ✨ (tidb-init.sql): add initial SQL script to create and populate 'test' database with 'authors' and 'posts' tables to facilitate testing and development --- src/test/resources/docker/docker-compose.yml | 31 ++++++++-- src/test/resources/docker/tidb-init.sql | 60 ++++++++++++++++++++ 2 files changed, 86 insertions(+), 5 deletions(-) create mode 100644 src/test/resources/docker/tidb-init.sql diff --git a/src/test/resources/docker/docker-compose.yml b/src/test/resources/docker/docker-compose.yml index c2173defd..ef09276b2 100644 --- a/src/test/resources/docker/docker-compose.yml +++ b/src/test/resources/docker/docker-compose.yml @@ -1,7 +1,6 @@ -version: '3.3' +version: "3.3" services: - mysql-5.6: platform: linux/x86_64 image: library/mysql:5.6 @@ -42,7 +41,7 @@ services: MYSQL_USER: lbuser MYSQL_PASSWORD: LiquibasePass1 volumes: - - "./mysql-init.sql:/docker-entrypoint-initdb.d/mysql-init.sql" + - "./mysql-init.sql:/docker-entrypoint-initdb.d/mysql-init.sql" mysql-8.4: platform: linux/x86_64 @@ -58,7 +57,6 @@ services: volumes: - "./mysql-init.sql:/docker-entrypoint-initdb.d/mysql-init.sql" - percona-xtradb-cluster-5.7: image: percona/percona-xtradb-cluster:5.7 ports: @@ -311,7 +309,7 @@ services: db2-luw: image: taskana/db2:11.5 environment: - LICENSE: 'accept' + LICENSE: "accept" ports: - "50000:50000" @@ -414,6 +412,29 @@ services: volumes: - "./informix-init.sql:/opt/ibm/config/informix-init.sql" + ti-db: + image: pingcap/tidb + container_name: ti-db + ports: + - 4000:4000 + volumes: + - ./storage/tidb:/var/lib/mysql + + ti-db-mysql: + image: mysql:latest + container_name: mysql-client + depends_on: + - ti-db + volumes: + - ./tidb-init.sql:/tidb-init.sql + entrypoint: sh -c " + echo 'Waiting for TiDB to be ready...' && + sleep 5; + echo 'TiDB is ready. Running initialization script...' && + mysql -h ti-db -P 4000 -u root < /tidb-init.sql && + echo 'Initialization complete.' && + tail -f /dev/null" Keeps the container running for interactive use + network_mode: "service:ti-db" # Titan (https://titan-data.io) is managing these images for our CI/CD process. If you want to run them locally you'll have to # populate init script (hsqldb-init.sql) for this platform manually or install titan and pull image pre-populated with data diff --git a/src/test/resources/docker/tidb-init.sql b/src/test/resources/docker/tidb-init.sql new file mode 100644 index 000000000..cfe7a8768 --- /dev/null +++ b/src/test/resources/docker/tidb-init.sql @@ -0,0 +1,60 @@ +-- Create the 'test' database if it doesn't exist +CREATE DATABASE IF NOT EXISTS `test`; + +-- Switch to the 'test' database +USE `test`; + +-- Drop and recreate the 'authors' table +DROP TABLE IF EXISTS `authors`; +CREATE TABLE `authors` ( + `id` INT(11) NOT NULL AUTO_INCREMENT, + `first_name` VARCHAR(50) COLLATE utf8_unicode_ci NOT NULL, + `last_name` VARCHAR(50) COLLATE utf8_unicode_ci NOT NULL, + `email` VARCHAR(100) COLLATE utf8_unicode_ci NOT NULL, + `birthdate` DATE NOT NULL, + `added` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(), + PRIMARY KEY (`id`) +) ENGINE=InnoDB + AUTO_INCREMENT=6 + DEFAULT CHARSET=utf8 + COLLATE=utf8_unicode_ci; + +-- Insert sample data into 'authors' +INSERT INTO `authors` +(`id`, `first_name`, `last_name`, `email`, `birthdate`, `added`) +VALUES + (1, 'Eileen', 'Lubowitz', 'ppaucek@example.org', '1991-03-04', '2004-05-30 02:08:25'), + (2, 'Tamia', 'Mayert', 'shansen@example.org', '2016-03-27', '2014-03-21 02:52:00'), + (3, 'Cyril', 'Funk', 'reynolds.godfrey@example.com','1988-04-21', '2011-06-24 18:17:48'), + (4, 'Nicolas', 'Buckridge', 'xhoeger@example.net', '2017-02-03', '2019-04-22 02:04:41'), + (5, 'Jayden', 'Walter', 'lillian66@example.com', '2010-02-27', '1990-02-04 02:32:00'); + +-- Drop and recreate the 'posts' table +DROP TABLE IF EXISTS `posts`; +CREATE TABLE `posts` ( + `id` INT(11) NOT NULL, + `author_id` INT(11) NOT NULL, + `title` VARCHAR(255) COLLATE utf8_unicode_ci NOT NULL, + `description` VARCHAR(500) COLLATE utf8_unicode_ci NOT NULL, + `content` TEXT COLLATE utf8_unicode_ci NOT NULL, + `inserted_date` DATE +) ENGINE=InnoDB + AUTO_INCREMENT=6 + DEFAULT CHARSET=utf8 + COLLATE=utf8_unicode_ci; + +-- Insert sample data into 'posts' +INSERT INTO `posts` +(`id`, `author_id`, `title`, `description`, `content`, `inserted_date`) +VALUES + (1, 1, 'temporibus', 'voluptatum', + 'Fugit non et doloribus repudiandae.', '2015-11-18'), + (2, 2, 'ea', 'aut', + 'Tempora molestias maiores provident molestiae sint possimus quasi.', '1975-06-08'), + (3, 3, 'illum', 'rerum', + 'Delectus recusandae sit officiis dolor.', '1975-02-25'), + (4, 4, 'itaque', 'deleniti', + 'Magni nam optio id recusandae.', '2010-07-28'), + (5, 5, 'ad', 'similique', + 'Rerum tempore quis ut nesciunt qui excepturi est.', '2006-10-09'); + \ No newline at end of file