Skip to content

Commit

Permalink
Added fallback for MySQL 5.6, running tests on old PostgreSQL versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
parpalak committed Apr 29, 2024
1 parent 36af6d9 commit 7fb7c2a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test_mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- 'mariadb-11.0'
- 'mariadb-11.1'
- 'mariadb-11.2'
- '5.6'
- '5.7'
php_versions:
- '7.4'
Expand Down
22 changes: 16 additions & 6 deletions .github/workflows/test_postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,29 @@ jobs:
fail-fast: false
matrix:
operating_system: ['ubuntu-22.04']
postgresql-version: [10, 11, 12, 13, 14, 15, 16]
php_versions:
- '8.2'

runs-on: '${{ matrix.operating_system }}'

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
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 17 additions & 6 deletions src/S2/Rose/Storage/Database/MysqlRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) . ' (
Expand Down

0 comments on commit 7fb7c2a

Please sign in to comment.