dbms_init...1
This commit is contained in:
parent
8a98a607f1
commit
81fd8d9d44
@ -171,27 +171,5 @@ class Database extends Config
|
||||
if (ENVIRONMENT === 'testing') {
|
||||
$this->defaultGroup = 'tests';
|
||||
}
|
||||
|
||||
$this->primeidc = [
|
||||
'DSN' => '',
|
||||
'hostname' => env('database.primeidc.hostname', 'localhost'),
|
||||
'username' => env('database.primeidc.username', 'root'),
|
||||
'password' => env('database.primeidc.password', ''),
|
||||
'database' => env('database.primeidc.database', 'primeidc'),
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'cacheOn' => false,
|
||||
'cacheDir' => '',
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,8 +13,8 @@ $routes->addPlaceholder('uuid', '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}
|
||||
//2. Config/Filters.php -> $aliases = ['authFilter' => AuthFilter::class]
|
||||
$routes->group('cli', ['namespace' => 'App\Controllers\CLI'], function ($routes) {
|
||||
$routes->cli('billing', 'Payment::billing');
|
||||
$routes->group('primeidc', ['namespace' => 'App\Controllers\CLI\DBMigration'], function ($routes) {
|
||||
$routes->cli('client', 'PrimeIDC::client');
|
||||
$routes->group('migration', ['namespace' => 'App\Controllers\CLI\DBMigration'], function ($routes) {
|
||||
$routes->cli('client', 'SourceDB::client');
|
||||
});
|
||||
});
|
||||
$routes->group('', ['namespace' => 'App\Controllers'], function ($routes) {
|
||||
|
||||
@ -25,8 +25,7 @@ abstract class DBMigration extends BaseController
|
||||
return $this->_targetDB;
|
||||
}
|
||||
|
||||
|
||||
private function convertClient(array $row): array
|
||||
protected function client_process(mixed $row): array
|
||||
{
|
||||
$temps = [];
|
||||
$temps['code'] = $row['Client_Code'];
|
||||
@ -50,26 +49,27 @@ abstract class DBMigration extends BaseController
|
||||
}
|
||||
return $temps;
|
||||
}
|
||||
private function setClient(mixed $rows): void
|
||||
{
|
||||
foreach ($rows as $row) {
|
||||
$datas = $this->convertClient($row);
|
||||
$this->getTargetDB()->table('clientinfo')->insert($datas);
|
||||
}
|
||||
}
|
||||
|
||||
final public function client(): void
|
||||
{
|
||||
//Transaction Start
|
||||
$this->getTargetDB()->transStart();
|
||||
try {
|
||||
$this->setClient($this->getClient());
|
||||
echo " 작업을 완료하였습니다.";
|
||||
$cnt = 1;
|
||||
foreach ($this->getClient() as $row) {
|
||||
$datas = $this->client_process($row);
|
||||
if (!$this->getTargetDB()->table('clientinfo')->insert($datas)) {
|
||||
throw new \Exception($this->getTargetDB()->error()['message']);
|
||||
}
|
||||
echo "{$cnt} -> {$datas['name']} 고객완료.\n";
|
||||
$cnt++;
|
||||
}
|
||||
echo __FUNCTION__ . " 작업을 완료하였습니다.";
|
||||
$this->getTargetDB()->transCommit();
|
||||
} catch (\Exception $e) {
|
||||
//Transaction Rollback
|
||||
$this->getTargetDB()->transRollback();
|
||||
echo " 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n";
|
||||
echo __FUNCTION__ . " 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\DBMigration;
|
||||
|
||||
use CodeIgniter\Database\BaseConnection;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class PrimeIDC extends DBMigration
|
||||
{
|
||||
private $_sourceDB = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
final protected function getSourceDB(): BaseConnection
|
||||
{
|
||||
if ($this->_sourceDB === null) {
|
||||
$this->_sourceDB = \Config\Database::connect('primeidc');
|
||||
}
|
||||
return $this->_sourceDB;
|
||||
}
|
||||
protected function getClient(): array
|
||||
{
|
||||
$rows = $this->getSourceDB()->query('SELECT * FROM clientdb')->getResultArray();
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
49
app/Controllers/CLI/DBMigration/SourceDB.php
Normal file
49
app/Controllers/CLI/DBMigration/SourceDB.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\CLI\DBMigration;
|
||||
|
||||
use CodeIgniter\Database\BaseConnection;
|
||||
use CodeIgniter\HTTP\RequestInterface;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class SourceDB extends DBMigration
|
||||
{
|
||||
private $_sourceDB = null;
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
parent::initController($request, $response, $logger);
|
||||
}
|
||||
final protected function getSourceDB(): BaseConnection
|
||||
{
|
||||
if ($this->_sourceDB === null) {
|
||||
$primeidc = [
|
||||
'DSN' => '',
|
||||
'hostname' => env('database.source.hostname', 'localhost'),
|
||||
'username' => env('database.source.username', 'root'),
|
||||
'password' => env('database.source.password', ''),
|
||||
'database' => env('database.source.database', 'primeidc'),
|
||||
'DBDriver' => 'MySQLi',
|
||||
'DBPrefix' => '',
|
||||
'pConnect' => false,
|
||||
'DBDebug' => (ENVIRONMENT !== 'production'),
|
||||
'cacheOn' => false,
|
||||
'cacheDir' => '',
|
||||
'charset' => 'utf8mb4',
|
||||
'DBCollat' => 'utf8mb4_general_ci',
|
||||
'swapPre' => '',
|
||||
'encrypt' => false,
|
||||
'compress' => false,
|
||||
'strictOn' => false,
|
||||
'failover' => [],
|
||||
'port' => 3306,
|
||||
];
|
||||
$this->_sourceDB = \Config\Database::connect($primeidc);
|
||||
}
|
||||
return $this->_sourceDB;
|
||||
}
|
||||
protected function getClient(): array
|
||||
{
|
||||
return $this->getSourceDB()->query('SELECT * FROM clientdb')->getResultArray();
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ CREATE TABLE `clientinfo` (
|
||||
PRIMARY KEY (`uid`),
|
||||
UNIQUE KEY `UQ_name` (`name`),
|
||||
UNIQUE KEY `UQ_code` (`code`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=610 DEFAULT CHARSET=utf8 COMMENT='고객정보';
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=1194 DEFAULT CHARSET=utf8 COMMENT='고객정보';
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
@ -81,7 +81,7 @@ CREATE TABLE `clientinfo` (
|
||||
|
||||
LOCK TABLES `clientinfo` WRITE;
|
||||
/*!40000 ALTER TABLE `clientinfo` DISABLE KEYS */;
|
||||
INSERT INTO `clientinfo` VALUES (1,'Test001','user','Test111','1111','test111@co.kr',50000,0,0,'default','2025-05-29 06:09:07','2025-05-29 06:07:37',NULL),(2,'Test002','user,vip','Test222','222','test222@co.kr',0,50,0,'default','2025-05-29 06:10:10','2025-05-29 06:07:54',NULL),(3,'Test003','user,vip,reseller','Test333','3333','test333@co.kr',100000,0,50000,'default','2025-06-17 02:11:41','2025-05-29 06:08:07',NULL),(4,'Test004','user','Test444','4444','test444@co.kr',0,1223,0,'default','2025-06-20 00:28:39','2025-05-29 06:08:17',NULL),(5,'Test005','user,vip','Test5555','234-234','test555@test.co.kr',2147483647,0,0,'default','2025-06-20 00:49:23','2025-06-20 00:41:10',NULL),(6,'Test006','user,reseller','Test666','234234','test666@test.co.kr',9930000,0,0,'default','2025-06-20 01:21:03','2025-06-20 00:51:01',NULL),(7,'Test007','user,vip','Test777','234-234-342','test777@test.co.kr',0,0,0,'default',NULL,'2025-06-23 07:42:00',NULL),(8,'Test008','user,vip,reseller','Test8888','00000-23423-3434','test8888@co.kr',0,0,0,'default',NULL,'2025-06-25 09:40:18',NULL),(592,'IDCJP','user','IDCJP','','idc@idcjp.jp',0,0,0,'default','2025-07-08 00:03:59','2025-07-07 09:55:24',NULL);
|
||||
INSERT INTO `clientinfo` VALUES (1,'Test001','user','Test111','1111','test111@co.kr',50000,0,0,'default','2025-05-29 06:09:07','2025-05-29 06:07:37',NULL),(2,'Test002','user,vip','Test222','222','test222@co.kr',0,50,0,'default','2025-05-29 06:10:10','2025-05-29 06:07:54',NULL),(3,'Test003','user,vip,reseller','Test333','3333','test333@co.kr',100000,0,50000,'default','2025-06-17 02:11:41','2025-05-29 06:08:07',NULL),(4,'Test004','user','Test444','4444','test444@co.kr',0,1223,0,'default','2025-06-20 00:28:39','2025-05-29 06:08:17',NULL),(5,'Test005','user,vip','Test5555','234-234','test555@test.co.kr',2147483647,0,0,'default','2025-06-20 00:49:23','2025-06-20 00:41:10',NULL),(6,'Test006','user,reseller','Test666','234234','test666@test.co.kr',9930000,0,0,'default','2025-06-20 01:21:03','2025-06-20 00:51:01',NULL),(7,'Test007','user,vip','Test777','234-234-342','test777@test.co.kr',0,0,0,'default',NULL,'2025-06-23 07:42:00',NULL),(8,'Test008','user,vip,reseller','Test8888','00000-23423-3434','test8888@co.kr',0,0,0,'default',NULL,'2025-06-25 09:40:18',NULL);
|
||||
/*!40000 ALTER TABLE `clientinfo` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
|
||||
@ -840,4 +840,4 @@ UNLOCK TABLES;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
|
||||
-- Dump completed on 2025-07-08 16:33:41
|
||||
-- Dump completed on 2025-07-08 17:03:39
|
||||
|
||||
@ -69,8 +69,7 @@ class ServiceModel extends CustomerModel
|
||||
protected function create_process(array $formDatas): ServiceEntity
|
||||
{
|
||||
$entity = parent::create_process($formDatas);
|
||||
//고객코드 Code 자동 생성 후 수정
|
||||
$code = 'S' . str_pad($entity->getPK(), 8, '0', STR_PAD_LEFT);
|
||||
return $this->modify($entity, ['code' => $code]);
|
||||
//고객코드 Code 자동 생성 후(timestamp값) 수정
|
||||
return $this->modify($entity, ['code' => 'S' . time()]);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user