From cfadbcaac7490c199e3977d53778bcadb0688c1d Mon Sep 17 00:00:00 2001 From: ryuring Date: Tue, 28 Mar 2023 13:11:01 +0900 Subject: [PATCH] =?UTF-8?q?PostgreSQL=E3=81=A8SQLite=E3=81=AE=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C=20fix=20#2086?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + db/.gitkeep | 0 docker/docker-compose.yml.default | 2 +- .../20230328000000_AlterIdToBaserCoreAll.php | 104 ++++++++++++++++++ .../src/Service/BcDatabaseService.php | 12 +- .../20230328000000_AlterIdToBcBlogAll.php | 56 ++++++++++ ...230328000000_AlterIdToBcContentLinkAll.php | 26 +++++ ...0328000000_AlterIdToBcCustomContentAll.php | 56 ++++++++++ ...328000000_AlterIdToBcEditorTemplateAll.php | 26 +++++ .../20230328000000_AlterIdToBcFavoriteAll.php | 26 +++++ .../Admin/InstallationsController.php | 5 +- .../src/Service/InstallationsService.php | 18 ++- .../20230328000000_AlterIdToBcMailAll.php | 56 ++++++++++ ...230328000000_AlterIdToBcSearchIndexAll.php | 26 +++++ ...230328000000_AlterIdToBcThemeConfigAll.php | 26 +++++ .../20230328000000_AlterIdToBcUplaoderAll.php | 38 +++++++ ...0230328000000_AlterIdToBcWidgetAreaAll.php | 26 +++++ 17 files changed, 492 insertions(+), 14 deletions(-) create mode 100755 db/.gitkeep create mode 100755 plugins/baser-core/config/Migrations/20230328000000_AlterIdToBaserCoreAll.php create mode 100755 plugins/bc-blog/config/Migrations/20230328000000_AlterIdToBcBlogAll.php create mode 100755 plugins/bc-content-link/config/Migrations/20230328000000_AlterIdToBcContentLinkAll.php create mode 100755 plugins/bc-custom-content/config/Migrations/20230328000000_AlterIdToBcCustomContentAll.php create mode 100755 plugins/bc-editor-template/config/Migrations/20230328000000_AlterIdToBcEditorTemplateAll.php create mode 100755 plugins/bc-favorite/config/Migrations/20230328000000_AlterIdToBcFavoriteAll.php create mode 100755 plugins/bc-mail/config/Migrations/20230328000000_AlterIdToBcMailAll.php create mode 100755 plugins/bc-search-index/config/Migrations/20230328000000_AlterIdToBcSearchIndexAll.php create mode 100755 plugins/bc-theme-config/config/Migrations/20230328000000_AlterIdToBcThemeConfigAll.php create mode 100755 plugins/bc-uploader/config/Migrations/20230328000000_AlterIdToBcUplaoderAll.php create mode 100755 plugins/bc-widget-area/config/Migrations/20230328000000_AlterIdToBcWidgetAreaAll.php diff --git a/.gitignore b/.gitignore index 454927c16e..b308e6de09 100644 --- a/.gitignore +++ b/.gitignore @@ -112,6 +112,9 @@ node_modules !/composer/.gitkeep # vendor !/vendor/.gitkeep +# db +/db/* +!/db/.gitkeep # etc LOCAL_TODO.md LOCAL_Q&A.md diff --git a/db/.gitkeep b/db/.gitkeep new file mode 100755 index 0000000000..e69de29bb2 diff --git a/docker/docker-compose.yml.default b/docker/docker-compose.yml.default index 8feab0f77c..4a46b3b921 100644 --- a/docker/docker-compose.yml.default +++ b/docker/docker-compose.yml.default @@ -62,7 +62,7 @@ services: - ./phpmyadmin/sessions:/sessions bc5-pg: - image: postgres:10.5 + image: postgres:15.2 container_name: bc5-pg ports: - 5432:5432 diff --git a/plugins/baser-core/config/Migrations/20230328000000_AlterIdToBaserCoreAll.php b/plugins/baser-core/config/Migrations/20230328000000_AlterIdToBaserCoreAll.php new file mode 100755 index 0000000000..951ac6f652 --- /dev/null +++ b/plugins/baser-core/config/Migrations/20230328000000_AlterIdToBaserCoreAll.php @@ -0,0 +1,104 @@ +table('pages') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('password_requests') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('content_folders') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('plugins') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('user_groups') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('users') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('users_user_groups') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('login_stores') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('site_configs') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('dblogs') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('permissions') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('sites') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('contents') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('permission_groups') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/baser-core/src/Service/BcDatabaseService.php b/plugins/baser-core/src/Service/BcDatabaseService.php index 77749ebc76..7414103ede 100644 --- a/plugins/baser-core/src/Service/BcDatabaseService.php +++ b/plugins/baser-core/src/Service/BcDatabaseService.php @@ -1261,7 +1261,7 @@ public function deleteTables($dbConfigKeyName = 'default', $dbConfig = null) $sql = "SELECT sequence_name FROM INFORMATION_SCHEMA.sequences WHERE sequence_schema = '{$dbConfig['schema']}';"; $sequences = []; try { - $sequences = $db->query($sql); + $sequences = $db->execute($sql)->fetchAll('assoc'); } catch (BcException $e) { } if ($sequences) { @@ -1278,7 +1278,9 @@ public function deleteTables($dbConfigKeyName = 'default', $dbConfig = null) break; case 'sqlite': - @unlink($dbConfig['database']); + if(file_exists($dbConfig['database'])) { + unlink($dbConfig['database']); + } break; } return true; @@ -1427,11 +1429,11 @@ public function constructionTable(string $plugin, string $dbConfigKeyName = 'def $db = $this->getDataSource($dbConfigKeyName, $dbConfig); if (!$dbConfig) $dbConfig = ConnectionManager::getConfig($dbConfigKeyName); $datasource = strtolower(str_replace('Cake\\Database\\Driver\\', '', $dbConfig['driver'])); - if (!$db->isConnected()) { - return false; - } elseif ($datasource == 'sqlite') { + if ($datasource == 'sqlite') { $db->connect(); chmod($dbConfig['database'], 0666); + } elseif (!$db->isConnected()) { + return false; } return $this->migrate($plugin, $dbConfigKeyName); } diff --git a/plugins/bc-blog/config/Migrations/20230328000000_AlterIdToBcBlogAll.php b/plugins/bc-blog/config/Migrations/20230328000000_AlterIdToBcBlogAll.php new file mode 100755 index 0000000000..2dfa0c24b3 --- /dev/null +++ b/plugins/bc-blog/config/Migrations/20230328000000_AlterIdToBcBlogAll.php @@ -0,0 +1,56 @@ +table('blog_contents') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('blog_categories') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('blog_posts') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('blog_comments') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('blog_posts_blog_tags') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('blog_tags') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-content-link/config/Migrations/20230328000000_AlterIdToBcContentLinkAll.php b/plugins/bc-content-link/config/Migrations/20230328000000_AlterIdToBcContentLinkAll.php new file mode 100755 index 0000000000..06576ddd9a --- /dev/null +++ b/plugins/bc-content-link/config/Migrations/20230328000000_AlterIdToBcContentLinkAll.php @@ -0,0 +1,26 @@ +table('content_links') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-custom-content/config/Migrations/20230328000000_AlterIdToBcCustomContentAll.php b/plugins/bc-custom-content/config/Migrations/20230328000000_AlterIdToBcCustomContentAll.php new file mode 100755 index 0000000000..1d641fe2c0 --- /dev/null +++ b/plugins/bc-custom-content/config/Migrations/20230328000000_AlterIdToBcCustomContentAll.php @@ -0,0 +1,56 @@ +table('custom_contents') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('custom_tables') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('custom_entry_1_recruit') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('custom_entry_2_occupations') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('custom_links') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('custom_fields') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-editor-template/config/Migrations/20230328000000_AlterIdToBcEditorTemplateAll.php b/plugins/bc-editor-template/config/Migrations/20230328000000_AlterIdToBcEditorTemplateAll.php new file mode 100755 index 0000000000..31897a7fc3 --- /dev/null +++ b/plugins/bc-editor-template/config/Migrations/20230328000000_AlterIdToBcEditorTemplateAll.php @@ -0,0 +1,26 @@ +table('editor_teplates') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-favorite/config/Migrations/20230328000000_AlterIdToBcFavoriteAll.php b/plugins/bc-favorite/config/Migrations/20230328000000_AlterIdToBcFavoriteAll.php new file mode 100755 index 0000000000..8a57bcecd2 --- /dev/null +++ b/plugins/bc-favorite/config/Migrations/20230328000000_AlterIdToBcFavoriteAll.php @@ -0,0 +1,26 @@ +table('favorites') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-installer/src/Controller/Admin/InstallationsController.php b/plugins/bc-installer/src/Controller/Admin/InstallationsController.php index 2685b7464f..6a4f94b0ba 100644 --- a/plugins/bc-installer/src/Controller/Admin/InstallationsController.php +++ b/plugins/bc-installer/src/Controller/Admin/InstallationsController.php @@ -21,6 +21,7 @@ use Cake\Core\Configure; use Cake\Event\EventInterface; use Cake\Http\Cookie\Cookie; +use Cake\Http\Response; use Cake\ORM\Exception\PersistenceFailedException; use Cake\Utility\Hash; use BaserCore\Annotation\UnitTest; @@ -85,7 +86,7 @@ public function step2(InstallationsAdminServiceInterface $service) /** * Step 3: データベースの接続設定 * - * @return void + * @return void|Response * @noTodo * @checked */ @@ -122,7 +123,7 @@ public function step3(InstallationsAdminServiceInterface $service) ); $this->BcMessage->setInfo(__d('baser_core', 'データベースの構築に成功しました。')); return $this->redirect(['action' => 'step4']); - } catch (BcException $e) { + } catch (\Throwable $e) { $errorMessage = __d('baser_core', 'データベースの構築中にエラーが発生しました。') . "\n" . $e->getMessage(); $this->BcMessage->setError($errorMessage); } diff --git a/plugins/bc-installer/src/Service/InstallationsService.php b/plugins/bc-installer/src/Service/InstallationsService.php index 68dcd4d5ad..68acdcf9d8 100644 --- a/plugins/bc-installer/src/Service/InstallationsService.php +++ b/plugins/bc-installer/src/Service/InstallationsService.php @@ -31,13 +31,16 @@ use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Database\Connection; +use Cake\Database\Driver\Sqlite; use Cake\Filesystem\Folder; use Cake\I18n\FrozenTime; use Cake\Log\LogTrait; use Cake\Mailer\MailerAwareTrait; use Cake\ORM\Exception\PersistenceFailedException; use Cake\ORM\TableRegistry; +use PDO; use PDOException; +use SQLite3; /** * InstallationsService @@ -210,7 +213,7 @@ public function getRealDbName(string $type, string $name) } if (!empty($type) && !empty($name)) { if ($type == 'sqlite') { - return APP . 'db' . DS . 'sqlite' . DS . $name . '.db'; + return ROOT . DS . 'db' . DS . 'sqlite' . DS . $name . '.db'; } } return $name; @@ -514,7 +517,13 @@ public function createInstallFile(array $dbConfig, string $securitySalt): bool $installCoreData[] = ' ],'; $installCoreData[] = ' \'Datasources.test\' => ['; foreach($dbConfig as $key => $value) { - if($key === 'database') $value = 'test_' . $value; + if($key === 'database') { + if(str_replace('\\\\', '\\', $dbConfig['driver']) === Sqlite::class) { + $value = dirname($value) . DS . 'test_' . basename($value); + } else { + $value = 'test_' . $value; + } + } if($key === 'datasource' || $key === 'dataPattern') continue; $installCoreData[] = ' \'' . $key . '\' => \'' . $value . '\','; } @@ -609,9 +618,6 @@ public function deployEditorTemplateImage(): bool */ protected function _getDbSource(): array { - // TODO uctmiz 未実装 - return ['mysql' => 'MySQL']; - /* DBソース取得 */ $dbsource = []; $folder = new Folder(); @@ -626,7 +632,7 @@ protected function _getDbSource(): array } /* SQLite利用可否チェック */ if (in_array('sqlite', $pdoDrivers) && extension_loaded('sqlite3') && class_exists('SQLite3')) { - $dbFolderPath = APP . 'db' . DS . 'sqlite'; + $dbFolderPath = ROOT . DS . 'db' . DS . 'sqlite'; if (is_writable(dirname($dbFolderPath)) && $folder->create($dbFolderPath, 0777)) { $info = SQLite3::version(); if (version_compare($info['versionString'], Configure::read('BcRequire.winSQLiteVersion'), '>')) { diff --git a/plugins/bc-mail/config/Migrations/20230328000000_AlterIdToBcMailAll.php b/plugins/bc-mail/config/Migrations/20230328000000_AlterIdToBcMailAll.php new file mode 100755 index 0000000000..d997f7e8a3 --- /dev/null +++ b/plugins/bc-mail/config/Migrations/20230328000000_AlterIdToBcMailAll.php @@ -0,0 +1,56 @@ +table('mail_configs') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('mail_contents') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('mail_fields') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('mail_messages') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('mail_message_1') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('mail_message_2') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-search-index/config/Migrations/20230328000000_AlterIdToBcSearchIndexAll.php b/plugins/bc-search-index/config/Migrations/20230328000000_AlterIdToBcSearchIndexAll.php new file mode 100755 index 0000000000..0926089839 --- /dev/null +++ b/plugins/bc-search-index/config/Migrations/20230328000000_AlterIdToBcSearchIndexAll.php @@ -0,0 +1,26 @@ +table('search_indexes') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-theme-config/config/Migrations/20230328000000_AlterIdToBcThemeConfigAll.php b/plugins/bc-theme-config/config/Migrations/20230328000000_AlterIdToBcThemeConfigAll.php new file mode 100755 index 0000000000..0c3a8b6063 --- /dev/null +++ b/plugins/bc-theme-config/config/Migrations/20230328000000_AlterIdToBcThemeConfigAll.php @@ -0,0 +1,26 @@ +table('theme_configs') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-uploader/config/Migrations/20230328000000_AlterIdToBcUplaoderAll.php b/plugins/bc-uploader/config/Migrations/20230328000000_AlterIdToBcUplaoderAll.php new file mode 100755 index 0000000000..82cdc55799 --- /dev/null +++ b/plugins/bc-uploader/config/Migrations/20230328000000_AlterIdToBcUplaoderAll.php @@ -0,0 +1,38 @@ +table('uploader_files') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('uploader_categories') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + $this->table('uploader_configs') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +} diff --git a/plugins/bc-widget-area/config/Migrations/20230328000000_AlterIdToBcWidgetAreaAll.php b/plugins/bc-widget-area/config/Migrations/20230328000000_AlterIdToBcWidgetAreaAll.php new file mode 100755 index 0000000000..7d4bee234b --- /dev/null +++ b/plugins/bc-widget-area/config/Migrations/20230328000000_AlterIdToBcWidgetAreaAll.php @@ -0,0 +1,26 @@ +table('widget_areas') + ->changeColumn('id', 'integer', [ + 'identity' => true, + 'generated' => PostgresAdapter::GENERATED_BY_DEFAULT + ]) + ->update(); + } + +}