Skip to content

Commit

Permalink
DAT-19303 DevOps :: TiDB :: Add ability to run custom SQL script that…
Browse files Browse the repository at this point in the history
… creates tables and table data against created db (#975)

* ✨ (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
  • Loading branch information
jandroav authored Jan 21, 2025
1 parent 2d226ac commit 6962d61
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 5 deletions.
31 changes: 26 additions & 5 deletions src/test/resources/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3.3'
version: "3.3"

services:

mysql-5.6:
platform: linux/x86_64
image: library/mysql:5.6
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -311,7 +309,7 @@ services:
db2-luw:
image: taskana/db2:11.5
environment:
LICENSE: 'accept'
LICENSE: "accept"
ports:
- "50000:50000"

Expand Down Expand Up @@ -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
Expand Down
60 changes: 60 additions & 0 deletions src/test/resources/docker/tidb-init.sql
Original file line number Diff line number Diff line change
@@ -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', '[email protected]', '1991-03-04', '2004-05-30 02:08:25'),
(2, 'Tamia', 'Mayert', '[email protected]', '2016-03-27', '2014-03-21 02:52:00'),
(3, 'Cyril', 'Funk', '[email protected]','1988-04-21', '2011-06-24 18:17:48'),
(4, 'Nicolas', 'Buckridge', '[email protected]', '2017-02-03', '2019-04-22 02:04:41'),
(5, 'Jayden', 'Walter', '[email protected]', '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');

0 comments on commit 6962d61

Please sign in to comment.