From 7fb7c2a402791a6dc998e50b2122d1d1cbd4ab49 Mon Sep 17 00:00:00 2001 From: Roman Parpalak Date: Tue, 30 Apr 2024 01:02:19 +0300 Subject: [PATCH] Added fallback for MySQL 5.6, running tests on old PostgreSQL versions. --- .github/workflows/test_mysql.yml | 1 + .github/workflows/test_postgres.yml | 22 +++++++++++++----- README.md | 10 ++++---- .../Rose/Storage/Database/MysqlRepository.php | 23 ++++++++++++++----- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test_mysql.yml b/.github/workflows/test_mysql.yml index f65b1f8..8679e82 100644 --- a/.github/workflows/test_mysql.yml +++ b/.github/workflows/test_mysql.yml @@ -27,6 +27,7 @@ jobs: - 'mariadb-11.0' - 'mariadb-11.1' - 'mariadb-11.2' + - '5.6' - '5.7' php_versions: - '7.4' diff --git a/.github/workflows/test_postgres.yml b/.github/workflows/test_postgres.yml index c63414c..b7ae65a 100644 --- a/.github/workflows/test_postgres.yml +++ b/.github/workflows/test_postgres.yml @@ -8,6 +8,7 @@ jobs: fail-fast: false matrix: operating_system: ['ubuntu-22.04'] + postgresql-version: [10, 11, 12, 13, 14, 15, 16] php_versions: - '8.2' @@ -15,12 +16,21 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: ikalnytskyi/action-setup-postgres@v4 - with: - username: postgres - password: 12345 - database: s2_rose_test - port: 5432 + + - name: Install PostgreSQL + env: + POSTGRESQL_VERSION: ${{ matrix.postgresql-version }} + run: | + sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - + sudo apt-get update + sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION" + sudo service postgresql start + + - name: Set up PostgreSQL + run: | + sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '12345';" + sudo -u postgres psql -c "CREATE DATABASE s2_rose_test OWNER postgres;" - name: 'Setup PHP' uses: shivammathur/setup-php@v2 diff --git a/README.md b/README.md index 6aca2f1..11662a4 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ It indexes your content and provides a full-text search. 1. PHP 7.4 or later. 2. A relational database in case of significant content size. Supported databases are: -| Database | Tests | -| ------------- | ------------- | -| MySQL 5.7 or later and MariaDB 10.2 or later | [![Tests on MySQL](https://github.com/parpalak/rose/actions/workflows/test_mysql.yml/badge.svg)](https://github.com/parpalak/rose/actions/workflows/test_mysql.yml) | -| PostgreSQL (tested on 14) | [![Tests on PostgreSQL](https://github.com/parpalak/rose/actions/workflows/test_postgres.yml/badge.svg)](https://github.com/parpalak/rose/actions/workflows/test_postgres.yml) | -| SQLite | [![Tests on SQLite](https://github.com/parpalak/rose/actions/workflows/test_sqlite.yml/badge.svg)](https://github.com/parpalak/rose/actions/workflows/test_sqlite.yml) | +| Database | Tests | +|----------------------------------------------| ------------- | +| MySQL 5.6 or later and MariaDB 10.2 or later | [![Tests on MySQL](https://github.com/parpalak/rose/actions/workflows/test_mysql.yml/badge.svg)](https://github.com/parpalak/rose/actions/workflows/test_mysql.yml) | +| PostgreSQL (tested on versions 10...16) | [![Tests on PostgreSQL](https://github.com/parpalak/rose/actions/workflows/test_postgres.yml/badge.svg)](https://github.com/parpalak/rose/actions/workflows/test_postgres.yml) | +| SQLite (tested on 3.37.2) | [![Tests on SQLite](https://github.com/parpalak/rose/actions/workflows/test_sqlite.yml/badge.svg)](https://github.com/parpalak/rose/actions/workflows/test_sqlite.yml) | ## Installation diff --git a/src/S2/Rose/Storage/Database/MysqlRepository.php b/src/S2/Rose/Storage/Database/MysqlRepository.php index b0d95cb..af7be60 100644 --- a/src/S2/Rose/Storage/Database/MysqlRepository.php +++ b/src/S2/Rose/Storage/Database/MysqlRepository.php @@ -321,12 +321,23 @@ private function dropAndCreateTables(string $charset, int $keyLen): void ) ENGINE=InnoDB CHARACTER SET ' . $charset); $this->pdo->exec('DROP TABLE IF EXISTS ' . $this->getTableName(self::METADATA) . ';'); - $this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::METADATA) . ' ( - toc_id INT(11) UNSIGNED NOT NULL, - word_count INT(11) UNSIGNED NOT NULL, - images JSON NOT NULL, - PRIMARY KEY (toc_id) - ) ENGINE=InnoDB CHARACTER SET ' . $charset); + + try { + $this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::METADATA) . ' ( + toc_id INT(11) UNSIGNED NOT NULL, + word_count INT(11) UNSIGNED NOT NULL, + images JSON NOT NULL, + PRIMARY KEY (toc_id) + ) ENGINE=InnoDB CHARACTER SET ' . $charset); + } catch (\PDOException $e) { + // Fallback for old MariaDB < 10.2 with no JSON alias support + $this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::METADATA) . ' ( + toc_id INT(11) UNSIGNED NOT NULL, + word_count INT(11) UNSIGNED NOT NULL, + images LONGTEXT NOT NULL, + PRIMARY KEY (toc_id) + ) ENGINE=InnoDB CHARACTER SET ' . $charset); + } $this->pdo->exec('DROP TABLE IF EXISTS ' . $this->getTableName(self::SNIPPET) . ';'); $this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::SNIPPET) . ' (