Skip to content

Commit

Permalink
Support all db providers from madeline
Browse files Browse the repository at this point in the history
  • Loading branch information
xtrime-ru committed Oct 2, 2020
1 parent 296df55 commit 3be5e22
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 32 deletions.
16 changes: 8 additions & 8 deletions .env.docker.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ TELEGRAM_PROXY_PASSWORD=
# Change this type to convert session:
DB_TYPE=mysql
# MYSQL Settings. Required, when DB_TYPE=mysql
MYSQL_HOST=mysql
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=
MYSQL_DATABASE=MadelineProto
MYSQL_MAX_CONNECTIONS=10
MYSQL_IDLE_TIMEOUT=60
DB_HOST=mysql
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_DATABASE=MadelineProto
DB_MAX_CONNECTIONS=10
DB_IDLE_TIMEOUT=60
# Recent data will be stored in memory this amount of time:
MYSQL_CACHE_TTL="+5 minutes"
DB_CACHE_TTL="+5 minutes"
16 changes: 8 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ TELEGRAM_PROXY_PASSWORD=
# Change this type to convert session:
DB_TYPE=memory
# MYSQL Settings. Required, when DB_TYPE=mysql
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=
MYSQL_DATABASE=MadelineProto
MYSQL_MAX_CONNECTIONS=10
MYSQL_IDLE_TIMEOUT=60
DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=root
DB_PASSWORD=
DB_DATABASE=MadelineProto
DB_MAX_CONNECTIONS=10
DB_IDLE_TIMEOUT=60
# Recent data will be stored in memory this amount of time:
MYSQL_CACHE_TTL="+5 minutes"
DB_CACHE_TTL="+5 minutes"
3 changes: 3 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use TelegramApiServer\Logger;
use TelegramApiServer\Migrations\EnvUpgrade;

$root = __DIR__;
const ENV_VERSION='1';
Expand All @@ -23,6 +24,8 @@
//Config init
{
if (!getenv('SERVER_ADDRESS')) {
EnvUpgrade::mysqlToDbPrefix();

$envFile = $options['env'];
if (empty($envFile)) {
throw new InvalidArgumentException('Env file not defined');
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"amphp/websocket-server": "dev-master",
"amphp/websocket-client": "dev-master",
"vlucas/phpdotenv": "^4",
"danog/madelineproto":"dev-banned_session_handler_fix",
"danog/madelineproto":"dev-master",
"danog/tgseclib": "^3",
"amphp/http-server-form-parser": "^1.1"
},
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
],
'db' => [
'type' => getenv('DB_TYPE'),
'mysql' => [
'host' => getenv('MYSQL_HOST'),
'port' => (int) getenv('MYSQL_PORT'),
'user' => getenv('MYSQL_USER'),
'password' => getenv('MYSQL_PASSWORD'),
'database' => getenv('MYSQL_DATABASE'),
'max_connections' => (int) getenv('MYSQL_MAX_CONNECTIONS'),
'idle_timeout' => (int) getenv('MYSQL_IDLE_TIMEOUT'),
'cache_ttl' => getenv('MYSQL_CACHE_TTL'),
getenv('DB_TYPE') => [
'host' => getenv('DB_HOST'),
'port' => (int) getenv('DB_PORT'),
'user' => getenv('DB_USER'),
'password' => getenv('DB_PASSWORD'),
'database' => getenv('DB_DATABASE'),
'max_connections' => (int) getenv('DB_MAX_CONNECTIONS'),
'idle_timeout' => (int) getenv('DB_IDLE_TIMEOUT'),
'cache_ttl' => getenv('DB_CACHE_TTL'),
]
],
'download'=>[
Expand Down
16 changes: 16 additions & 0 deletions src/Migrations/EnvUpgrade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace TelegramApiServer\Migrations;

class EnvUpgrade
{
public static function mysqlToDbPrefix() {
foreach (glob(ROOT_DIR . '/.env*') as $envFile) {
$text = file_get_contents($envFile);
$text = preg_replace('/^MYSQL_/m', 'DB_', $text);
file_put_contents($envFile, $text);
}

}

}

0 comments on commit 3be5e22

Please sign in to comment.