dbms_init...1
This commit is contained in:
parent
c5a6349a1d
commit
1cbb338acd
@ -39,7 +39,7 @@ abstract class DBMigration extends BaseController
|
|||||||
/**
|
/**
|
||||||
* 공통 마이그레이션 처리 로직
|
* 공통 마이그레이션 처리 로직
|
||||||
*/
|
*/
|
||||||
private function processMigration(MigrationProcessInterface $processor, array $rows, string $functionName): void
|
private function migration(MigrationProcessInterface $processor, array $rows, string $functionName): void
|
||||||
{
|
{
|
||||||
$this->getTargetDB()->transStart();
|
$this->getTargetDB()->transStart();
|
||||||
try {
|
try {
|
||||||
@ -58,37 +58,21 @@ abstract class DBMigration extends BaseController
|
|||||||
|
|
||||||
final public function client(): void
|
final public function client(): void
|
||||||
{
|
{
|
||||||
$this->processMigration(
|
$this->migration(new ClientProcess($this->getTargetDB()), $this->getClient(), __FUNCTION__);
|
||||||
new ClientProcess($this->getTargetDB()),
|
|
||||||
$this->getClient(),
|
|
||||||
__FUNCTION__
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function line(): void
|
final public function line(): void
|
||||||
{
|
{
|
||||||
$this->processMigration(
|
$this->migration(new LineProcess($this->getTargetDB()), $this->getLine(), __FUNCTION__);
|
||||||
new LineProcess($this->getTargetDB()),
|
|
||||||
$this->getLine(),
|
|
||||||
__FUNCTION__
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function servercode(): void
|
final public function servercode(): void
|
||||||
{
|
{
|
||||||
$this->processMigration(
|
$this->migration(new ServerCodeProcess($this->getTargetDB()), $this->getServerCode(), __FUNCTION__);
|
||||||
new ServerCodeProcess($this->getTargetDB()),
|
|
||||||
$this->getServerCode(),
|
|
||||||
__FUNCTION__
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final public function switchcode(): void
|
final public function switchcode(): void
|
||||||
{
|
{
|
||||||
$this->processMigration(
|
$this->migration(new SwitchCodeProcess($this->getTargetDB()), $this->getSwitchCode(), __FUNCTION__);
|
||||||
new SwitchCodeProcess($this->getTargetDB()),
|
|
||||||
$this->getSwitchCode(),
|
|
||||||
__FUNCTION__
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,18 +6,32 @@ use CodeIgniter\Database\BaseConnection;
|
|||||||
use CodeIgniter\HTTP\RequestInterface;
|
use CodeIgniter\HTTP\RequestInterface;
|
||||||
use CodeIgniter\HTTP\ResponseInterface;
|
use CodeIgniter\HTTP\ResponseInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use App\Config\SourceDatabase;
|
||||||
|
|
||||||
class SourceDB extends DBMigration
|
class SourceDB extends DBMigration
|
||||||
{
|
{
|
||||||
private $_sourceDB = null;
|
private $_sourceDB = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SQL 쿼리 상수 정의
|
||||||
|
*/
|
||||||
|
private const SQL_GET_CLIENT = "SELECT * FROM clientdb";
|
||||||
|
private const SQL_GET_LINE = "SELECT Line_code, line_case, Line_ip, line_client_name, line_gateway, line_id, line_pass, line_name, line_haveip, line_phone, line_mainip FROM linedb";
|
||||||
|
private const SQL_GET_SERVER_CODE = "SELECT DISTINCT(server_code) FROM serverdb WHERE server_code NOT LIKE ?";
|
||||||
|
private const SQL_GET_SWITCH_CODE = "SELECT DISTINCT(service_sw) FROM servicedb WHERE service_sw NOT LIKE ?";
|
||||||
|
|
||||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||||
{
|
{
|
||||||
parent::initController($request, $response, $logger);
|
parent::initController($request, $response, $logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 소스 데이터베이스 연결 반환
|
||||||
|
*/
|
||||||
final protected function getSourceDB(): BaseConnection
|
final protected function getSourceDB(): BaseConnection
|
||||||
{
|
{
|
||||||
if ($this->_sourceDB === null) {
|
if ($this->_sourceDB === null) {
|
||||||
$primeidc = [
|
$config = [
|
||||||
'DSN' => '',
|
'DSN' => '',
|
||||||
'hostname' => env('database.source.hostname', 'localhost'),
|
'hostname' => env('database.source.hostname', 'localhost'),
|
||||||
'username' => env('database.source.username', 'root'),
|
'username' => env('database.source.username', 'root'),
|
||||||
@ -38,26 +52,38 @@ class SourceDB extends DBMigration
|
|||||||
'failover' => [],
|
'failover' => [],
|
||||||
'port' => 3306,
|
'port' => 3306,
|
||||||
];
|
];
|
||||||
$this->_sourceDB = \Config\Database::connect($primeidc);
|
$this->_sourceDB = \Config\Database::connect($config);
|
||||||
}
|
}
|
||||||
return $this->_sourceDB;
|
return $this->_sourceDB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 공통 쿼리 실행 메서드
|
||||||
|
*/
|
||||||
|
private function executeQuery(string $sql, array $params = []): array
|
||||||
|
{
|
||||||
|
return $this->getSourceDB()
|
||||||
|
->query($sql, $params)
|
||||||
|
->getResultArray();
|
||||||
|
}
|
||||||
|
|
||||||
protected function getClient(): array
|
protected function getClient(): array
|
||||||
{
|
{
|
||||||
return $this->getSourceDB()->query("SELECT * FROM clientdb")->getResultArray();
|
return $this->executeQuery(self::SQL_GET_CLIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getLine(): array
|
protected function getLine(): array
|
||||||
{
|
{
|
||||||
return $this->getSourceDB()->query("SELECT Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip from linedb;select Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip FROM linedb")->getResultArray();
|
return $this->executeQuery(self::SQL_GET_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getServerCode(): array
|
protected function getServerCode(): array
|
||||||
{
|
{
|
||||||
return $this->getSourceDB()->query("SELECT DISTINCT(server_code) FROM serverdb WHERE server_code NOT LIKE ('%일회성%')")->getResultArray();
|
return $this->executeQuery(self::SQL_GET_SERVER_CODE, ['%일회성%']);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSwitchCode(): array
|
protected function getSwitchCode(): array
|
||||||
{
|
{
|
||||||
return $this->getSourceDB()->query("SELECT DISTINCT(service_sw) FROM servicedb WHERE service_sw NOT LIKE ('%일회성%')")->getResultArray();
|
return $this->executeQuery(self::SQL_GET_SWITCH_CODE, ['%일회성%']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user