Added MySql option

This commit is contained in:
Thomas Ziegler 2017-05-28 21:33:05 +02:00
parent 10b77321bc
commit 04858d609d
6 changed files with 36 additions and 5 deletions

View File

@ -9,7 +9,8 @@ RUN set -xe && \
apk update && apk upgrade && \ apk update && apk upgrade && \
apk add --no-cache --virtual=run-deps \ apk add --no-cache --virtual=run-deps \
nginx git ca-certificates curl \ nginx git ca-certificates curl \
php5 php5-fpm php5-curl php5-dom php5-gd php5-json php5-mcrypt php5-pcntl php5-pdo php5-pdo_pgsql php5-pgsql php5-posix php5 php5-fpm php5-curl php5-dom php5-gd php5-json php5-mcrypt php5-pcntl \
php5-pdo php5-pdo_pgsql php5-pgsql php5-pdo_mysql php5-mysql php5-mysqli php5-posix
# Add user www-data for php-fpm # Add user www-data for php-fpm
# 82 is the standard uid/gid for "www-data" in Alpine # 82 is the standard uid/gid for "www-data" in Alpine

View File

@ -126,6 +126,12 @@ default configuration, which can be changed by passing the following additional
-e DB_PASS=ttrss -e DB_PASS=ttrss
``` ```
#### Run on MySql
```bash
-e DB_TYPE=mysql
```
### Database user ### Database user
When you run TT-RSS it will check your database setup. If it can not connect using the above When you run TT-RSS it will check your database setup. If it can not connect using the above

View File

@ -10,6 +10,11 @@ $conffile = $confpath . 'config.php';
$ename = 'DB'; $ename = 'DB';
$eport = 5432; $eport = 5432;
$db_type = env('DB_TYPE','pgsql');
if ($db_type == 'mysql'){
$eport = 3306;
}
echo 'Configuring database for: ' . $conffile . PHP_EOL; echo 'Configuring database for: ' . $conffile . PHP_EOL;
// check DB_NAME, which will be set automatically for a linked "db" container // check DB_NAME, which will be set automatically for a linked "db" container
@ -18,7 +23,7 @@ if (!env($ename . '_PORT', '')) {
} }
$config = array(); $config = array();
$config['DB_TYPE'] = 'pgsql'; $config['DB_TYPE'] = $db_type;
$config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR'); $config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR');
$config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT'); $config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT');

View File

@ -5,6 +5,11 @@ include '/srv/ttrss-utils.php';
$ename = 'DB'; $ename = 'DB';
$eport = 5432; $eport = 5432;
$db_type = env('DB_TYPE','pgsql');
if ($db_type == 'mysql'){
$eport = 3306;
}
$confpath = '/var/www/ttrss/config.php'; $confpath = '/var/www/ttrss/config.php';
// check DB_NAME, which will be set automatically for a linked "db" container // check DB_NAME, which will be set automatically for a linked "db" container
@ -13,7 +18,7 @@ if (!env($ename . '_PORT', '')) {
} }
$config = array(); $config = array();
$config['DB_TYPE'] = 'pgsql'; $config['DB_TYPE'] = $db_type;
$config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR'); $config['DB_HOST'] = env($ename . '_PORT_' . $eport . '_TCP_ADDR');
$config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT'); $config['DB_PORT'] = env($ename . '_PORT_' . $eport . '_TCP_PORT');
@ -32,7 +37,7 @@ try {
} }
catch (PDOException $e) { catch (PDOException $e) {
echo 'Database table for mobilize plugin not found, applying schema... ' . PHP_EOL; echo 'Database table for mobilize plugin not found, applying schema... ' . PHP_EOL;
$schema = file_get_contents('/srv/ttrss-plugin-mobilize.pgsql'); $schema = file_get_contents('/srv/ttrss-plugin-mobilize.'.$db_type);
$schema = preg_replace('/--(.*?);/', '', $schema); $schema = preg_replace('/--(.*?);/', '', $schema);
$schema = preg_replace('/[\r\n]/', ' ', $schema); $schema = preg_replace('/[\r\n]/', ' ', $schema);
$schema = trim($schema, ' ;'); $schema = trim($schema, ' ;');

View File

@ -0,0 +1,9 @@
CREATE TABLE plugin_mobilize_feeds ( id int NOT NULL, owner_uid int NOT NULL, mobilizer_id int NOT NULL, PRIMARY KEY (id,owner_uid) );
CREATE TABLE plugin_mobilize_mobilizers ( id int NOT NULL, description varchar(255) NOT NULL, url varchar(1000) NOT NULL, PRIMARY KEY (id) ) ;
INSERT INTO plugin_mobilize_mobilizers ( id, description, url) VALUES
(0, 'Readability', 'http://www.readability.com/m?url=%s'),
(1, 'Instapaper', 'http://www.instapaper.com/m?u=%s'),
(2, 'Google Mobilizer', 'http://www.google.com/gwt/x?u=%s'),
(3, 'Original Stripped', 'http://strip=%s'),
(4, 'Original', '%s');

View File

@ -26,7 +26,12 @@ function dbconnect($config)
$dsn .= $d . '=' . $config['DB_' . $h] . ';'; $dsn .= $d . '=' . $config['DB_' . $h] . ';';
} }
} }
echo($dsn);
if ($config['DB_TYPE'] == 'pgsql'){
$pdo = new \PDO($dsn); $pdo = new \PDO($dsn);
} else {
$pdo = new \PDO($dsn, $config['DB_USER'], $config['DB_PASS']);
}
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $pdo; return $pdo;
} }