From 81fd8d9d44ddb25fd60d92693b8f8d3ff9cd4a8b Mon Sep 17 00:00:00 2001 From: "choi.jh" Date: Tue, 8 Jul 2025 17:47:08 +0900 Subject: [PATCH] dbms_init...1 --- app/Config/Database.php | 22 --------- app/Config/Routes.php | 4 +- .../CLI/DBMigration/DBMigration.php | 24 ++++----- app/Controllers/CLI/DBMigration/PrimeIDC.php | 30 ------------ app/Controllers/CLI/DBMigration/SourceDB.php | 49 +++++++++++++++++++ app/Database/dbms_init_all.sql | 6 +-- app/Models/Customer/ServiceModel.php | 5 +- 7 files changed, 68 insertions(+), 72 deletions(-) delete mode 100644 app/Controllers/CLI/DBMigration/PrimeIDC.php create mode 100644 app/Controllers/CLI/DBMigration/SourceDB.php diff --git a/app/Config/Database.php b/app/Config/Database.php index e603b1c..d939a88 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -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, - ]; } } diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 49d168a..ba8b767 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -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) { diff --git a/app/Controllers/CLI/DBMigration/DBMigration.php b/app/Controllers/CLI/DBMigration/DBMigration.php index 772b276..e1ac9b2 100644 --- a/app/Controllers/CLI/DBMigration/DBMigration.php +++ b/app/Controllers/CLI/DBMigration/DBMigration.php @@ -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"; } } } diff --git a/app/Controllers/CLI/DBMigration/PrimeIDC.php b/app/Controllers/CLI/DBMigration/PrimeIDC.php deleted file mode 100644 index 31d7b0e..0000000 --- a/app/Controllers/CLI/DBMigration/PrimeIDC.php +++ /dev/null @@ -1,30 +0,0 @@ -_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; - } -} diff --git a/app/Controllers/CLI/DBMigration/SourceDB.php b/app/Controllers/CLI/DBMigration/SourceDB.php new file mode 100644 index 0000000..af5760d --- /dev/null +++ b/app/Controllers/CLI/DBMigration/SourceDB.php @@ -0,0 +1,49 @@ +_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(); + } +} diff --git a/app/Database/dbms_init_all.sql b/app/Database/dbms_init_all.sql index 8f5949e..c3f9208 100644 --- a/app/Database/dbms_init_all.sql +++ b/app/Database/dbms_init_all.sql @@ -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 diff --git a/app/Models/Customer/ServiceModel.php b/app/Models/Customer/ServiceModel.php index d7be43d..d224879 100644 --- a/app/Models/Customer/ServiceModel.php +++ b/app/Models/Customer/ServiceModel.php @@ -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()]); } }