Skip to content

Commit 34fb725

Browse files
committed
Added fallback for MySQL 5.6.
1 parent 36af6d9 commit 34fb725

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

.github/workflows/test_mysql.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
- 'mariadb-11.0'
2828
- 'mariadb-11.1'
2929
- 'mariadb-11.2'
30+
- '5.6'
3031
- '5.7'
3132
php_versions:
3233
- '7.4'

.github/workflows/test_postgres.yml

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,28 @@ jobs:
88
fail-fast: false
99
matrix:
1010
operating_system: ['ubuntu-22.04']
11+
postgresql-version: [10, 11, 12, 13, 14, 15, 16]
1112
php_versions:
1213
- '8.2'
1314

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

1617
steps:
1718
- uses: actions/checkout@v4
18-
- uses: ikalnytskyi/action-setup-postgres@v4
19-
with:
20-
username: postgres
21-
password: 12345
22-
database: s2_rose_test
23-
port: 5432
19+
20+
- name: Install PostgreSQL
21+
env:
22+
POSTGRESQL_VERSION: ${{ matrix.postgresql-version }}
23+
run: |
24+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
25+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
26+
sudo apt-get update
27+
sudo apt-get -y install "postgresql-$POSTGRESQL_VERSION"
28+
29+
- name: Set up PostgreSQL
30+
run: |
31+
sudo -u postgres psql -c "CREATE USER postgres WITH PASSWORD '12345';"
32+
sudo -u postgres psql -c "CREATE DATABASE s2_rose_test OWNER postgres;"
2433
2534
- name: 'Setup PHP'
2635
uses: shivammathur/setup-php@v2

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ It indexes your content and provides a full-text search.
1010
1. PHP 7.4 or later.
1111
2. A relational database in case of significant content size. Supported databases are:
1212

13-
| Database | Tests |
14-
| ------------- | ------------- |
15-
| 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) |
16-
| 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) |
17-
| 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) |
13+
| Database | Tests |
14+
|----------------------------------------------| ------------- |
15+
| 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) |
16+
| 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) |
17+
| 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) |
1818

1919
## Installation
2020

src/S2/Rose/Storage/Database/MysqlRepository.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -321,12 +321,23 @@ private function dropAndCreateTables(string $charset, int $keyLen): void
321321
) ENGINE=InnoDB CHARACTER SET ' . $charset);
322322

323323
$this->pdo->exec('DROP TABLE IF EXISTS ' . $this->getTableName(self::METADATA) . ';');
324-
$this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::METADATA) . ' (
325-
toc_id INT(11) UNSIGNED NOT NULL,
326-
word_count INT(11) UNSIGNED NOT NULL,
327-
images JSON NOT NULL,
328-
PRIMARY KEY (toc_id)
329-
) ENGINE=InnoDB CHARACTER SET ' . $charset);
324+
325+
try {
326+
$this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::METADATA) . ' (
327+
toc_id INT(11) UNSIGNED NOT NULL,
328+
word_count INT(11) UNSIGNED NOT NULL,
329+
images JSON NOT NULL,
330+
PRIMARY KEY (toc_id)
331+
) ENGINE=InnoDB CHARACTER SET ' . $charset);
332+
} catch (\PDOException $e) {
333+
// Fallback for old MariaDB < 10.2 with no JSON alias support
334+
$this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::METADATA) . ' (
335+
toc_id INT(11) UNSIGNED NOT NULL,
336+
word_count INT(11) UNSIGNED NOT NULL,
337+
images LONGTEXT NOT NULL,
338+
PRIMARY KEY (toc_id)
339+
) ENGINE=InnoDB CHARACTER SET ' . $charset);
340+
}
330341

331342
$this->pdo->exec('DROP TABLE IF EXISTS ' . $this->getTableName(self::SNIPPET) . ';');
332343
$this->pdo->exec('CREATE TABLE ' . $this->getTableName(self::SNIPPET) . ' (

0 commit comments

Comments
 (0)