{"id":362,"date":"2024-04-17T11:50:19","date_gmt":"2024-04-17T02:50:19","guid":{"rendered":"https:\/\/txn.myds.me\/blog\/?p=362"},"modified":"2024-04-17T11:50:19","modified_gmt":"2024-04-17T02:50:19","slug":"cakephp-%e3%81%ae-migrations-%e3%81%a7%e5%a4%96%e9%83%a8%e3%82%ad%e3%83%bc%e3%82%92%e4%bd%9c%e3%82%8b%e6%99%82%e3%81%af%e3%80%81unsigned-%e3%81%ab%e3%81%99%e3%82%8b%e3%81%a8%e3%81%84%e3%81%84%e3%81%8b","status":"publish","type":"post","link":"https:\/\/blog.txn.red\/?p=362","title":{"rendered":"CakePHP \u306e migrations \u3067\u5916\u90e8\u30ad\u30fc\u3092\u4f5c\u308b\u6642\u306f\u3001unsigned \u306b\u3059\u308b\u3068\u3044\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u8a71"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u3042\u308b\u9577\u5e74\u52d5\u3044\u3066\u3044\u305f CakePHP \uff13 \u30a2\u30d7\u30ea\u3092\u79fb\u884c\u3059\u308b\u305f\u3081\u306b\u3001\u4e00\u65e6 CakePHP5 \u306e tuta \u3092\u3084\u308a\u59cb\u3081\u305f\u3068\u3053\u308d\u3060\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a rel=\"noreferrer noopener\" href=\"https:\/\/book.cakephp.org\/5\/ja\/tutorials-and-examples\/cms\/installation.html\" target=\"_blank\">Cake\u516c\u5f0f\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb<\/a>\u306f\u30d6\u30ed\u30b0\u30a2\u30d7\u30ea\u3092\u3064\u304f\u308b\u3053\u3068\u306b\u306a\u308b\u306e\u3060\u304c\u3001DB \u306e\u4f5c\u6210\u306f\u30d9\u30bf\u3067 SQL\u3092\u53e9\u304f\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u308b\u3002\u305d\u306e\u307e\u307e\u3084\u3063\u3066\u3082\u3082\u3061\u308d\u3093\u3044\u3044\u3057\u6700\u77ed\u6642\u9593\u3067\u76ee\u7684\u306e\u72b6\u614b\u306b\u306a\u308b\u306e\u3060\u304c\u3001\u4eca\u56de\u306f\u79fb\u884c\u6642\u306b\u4f7f\u3046\u3053\u3068\u306b\u306a\u308b\u306e\u3067\u3042\u3048\u3066 migrations \u3092\u4f7f\u3063\u3066\u307f\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u8981\u70b9\u304b\u3089\u3001 migrations \u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u3001id \u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4f5c\u3063\u3066\u304f\u308c\u308b\u306e\u3067\u3059\u304c\u305d\u308c\u304c int(11) \u306b\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002\u4e00\u65b9\u3001migrations \u3067 integer \u3067\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u4f5c\u6210\u3059\u308b\u3068 int(10) \u306b\u306a\u308b\u306e\u304c\u30c7\u30d5\u30a9\u30eb\u30c8\u306e\u3088\u3046\u3067\u3059\u3002<br>\u3068\u306a\u308b\u3068\u7d50\u679c\u3068\u3057\u3066\u5916\u90e8\u30ad\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u6841\u6570\u304c\u5408\u308f\u305a\u306b\u4f5c\u308c\u305a\u30a8\u30e9\u30fc\u306b\u306a\u308b\u3068\u3044\u3046\u4e8b\u8c61\u306b\u906d\u9047\u3057\u305f\u3068\u3044\u3046\u8a71\u3067\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30d6\u30ed\u30b0\u30c1\u30e5\u30fc\u30bf\u3067\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u30d5\u30a1\u30a4\u30eb\u540d\u306e\u5148\u982d\u90e8\u5206\u306f\u65e5\u6642\u3092\u793a\u3057\u307e\u3059\u3002 \u7a7a\u306e\u30d5\u30a1\u30a4\u30eb\u81ea\u8eab\u3082\u3053\u3093\u306a\u3075\u3046\u306b migrations \u3067\u751f\u6210\u3067\u304d\u307e\u3059\u3002<br> <code>.\/app\/bin\/cake migrations create CreateUsers<\/code> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3067\u30e6\u30fc\u30b6\u30fc\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u308c\u3067\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"YYYYMMDDhhmmss_CreateUsers.php\" data-lang=\"PHP\"><code>&lt;?php\ndeclare(strict_types=1);\n\nuse Migrations\\AbstractMigration;\n\nclass CreateUsers extends AbstractMigration\n{\n    \/**\n     * Change Method.\n     *\n     * More information on this method is available here:\n     * https:\/\/book.cakephp.org\/phinx\/0\/en\/migrations.html#the-change-method\n     * @return void\n     *\/\n    public function change(): void\n    {\n        $table = $this-&gt;table(&#39;users&#39;);\n        $table-&gt;addColumn(&#39;email&#39;, &#39;string&#39;, [\n            &#39;default&#39; =&gt; &#39;&#39;,\n            &#39;limit&#39; =&gt; 255,\n            &#39;null&#39; =&gt; false,\n            &#39;comment&#39; =&gt; &#39;&#39;\n        ])\n        -&gt;addIndex([&#39;email&#39;]);\n        $table-&gt;addColumn(&#39;password&#39;, &#39;string&#39;, [\n            &#39;default&#39; =&gt; &#39;&#39;,\n            &#39;limit&#39; =&gt; 255,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;created&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;modified&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;create();\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u30a2\u30fc\u30c6\u30a3\u30af\u30eb\u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">user_id  \u30d5\u30a3\u30fc\u30eb\u30c9\u306e signed \u3092 false \u306b\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"YYYYMMDDDhhmmss_CreateArticles.php\" data-lang=\"PHP\" data-line=\"20\"><code>&lt;?php\ndeclare(strict_types=1);\n\nuse Migrations\\AbstractMigration;\n\nclass CreateArticles extends AbstractMigration\n{\n    \/**\n     * Change Method.\n     *\n     * More information on this method is available here:\n     * https:\/\/book.cakephp.org\/phinx\/0\/en\/migrations.html#the-change-method\n     * @return void\n     *\/\n    public function change(): void\n    {\n        $table = $this-&gt;table(&#39;articles&#39;);\n        $table-&gt;addColumn(&#39;user_id&#39;, &#39;integer&#39;, [\n            &#39;null&#39; =&gt; false,\n            &#39;signed&#39; =&gt; false,\n        ]);\n        \/\/ -&gt;addIndex([&#39;user_id&#39;]);\n        $table-&gt;addColumn(&#39;title&#39;, &#39;string&#39;, [\n            &#39;default&#39; =&gt; &#39;&#39;,\n            &#39;limit&#39; =&gt; 255,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;slug&#39;, &#39;string&#39;, [\n            &#39;default&#39; =&gt; &#39;&#39;,\n            &#39;limit&#39; =&gt; 191,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;body&#39;, &#39;text&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; true,\n        ]);\n        $table-&gt;addColumn(&#39;published&#39;, &#39;boolean&#39;, [\n            &#39;default&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;created&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;modified&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addIndex(&#39;slug&#39;, [\n            &#39;unique&#39; =&gt; true\n        ]);\n        $table-&gt;addForeignKey(&#39;user_id&#39;, &#39;users&#39;, &#39;id&#39;,\n            [\n                &#39;delete&#39; =&gt; &#39;NO_ACTION&#39;, \n                &#39;update&#39; =&gt; &#39;NO_ACTION&#39;\n            ]\n        );\n        \/\/ $table-&gt;changePrimaryKey([&#39;article_id&#39;, &#39;tag_id&#39;]);\n        $table-&gt;create();\n    }\n}<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">tags \u30c6\u30fc\u30d6\u30eb\u306f\u3053\u3046\u306a\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"YYYYMMDDhhmmss_CreateTags.php\" data-lang=\"PHP\"><code>&lt;?php\ndeclare(strict_types=1);\n\nuse Migrations\\AbstractMigration;\n\nclass CreateTags extends AbstractMigration\n{\n    \/**\n     * Change Method.\n     *\n     * More information on this method is available here:\n     * https:\/\/book.cakephp.org\/phinx\/0\/en\/migrations.html#the-change-method\n     * @return void\n     *\/\n    public function change(): void\n    {\n        $table = $this-&gt;table(&#39;tags&#39;);\n        $table-&gt;addColumn(&#39;title&#39;, &#39;string&#39;, [\n            &#39;limit&#39; =&gt; 191,\n        ]);\n        $table-&gt;addColumn(&#39;created&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;modified&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addIndex(&#39;title&#39;, [\n            &#39;unique&#39; =&gt; true\n        ]);\n        $table-&gt;create();\n    }\n}\n<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Articles \u30c6\u30fc\u30d6\u30eb\u3068\u540c\u3058\u3088\u3046\u306b\u5916\u90e8\u30ad\u30fc\u3092\u4fdd\u5b58\u3059\u308b\u30d5\u30a3\u30fc\u30eb\u30c9\u306f\u30a2\u30f3\u30b5\u30a4\u30f3\u30c9\u306b\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-file=\"YYYYMMDDhhmmss_CreateAticlesTags.php\" data-lang=\"PHP\" data-line=\"20,24\"><code>&lt;?php\ndeclare(strict_types=1);\n\nuse Migrations\\AbstractMigration;\n\nclass CreateAticlesTags extends AbstractMigration\n{\n    \/**\n     * Change Method.\n     *\n     * More information on this method is available here:\n     * https:\/\/book.cakephp.org\/phinx\/0\/en\/migrations.html#the-change-method\n     * @return void\n     *\/\n    public function change(): void\n    {\n        $table = $this-&gt;table(&#39;aticles_tags&#39;);\n        $table-&gt;addColumn(&#39;article_id&#39;, &#39;integer&#39;, [\n            &#39;null&#39; =&gt; false,\n            &#39;signed&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;tag_id&#39;, &#39;integer&#39;, [\n            &#39;null&#39; =&gt; false,\n            &#39;signed&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;created&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addColumn(&#39;modified&#39;, &#39;datetime&#39;, [\n            &#39;default&#39; =&gt; null,\n            &#39;null&#39; =&gt; false,\n        ]);\n        $table-&gt;addForeignKey(&#39;tag_id&#39;, &#39;tags&#39;, &#39;id&#39;, [\n            &#39;delete&#39; =&gt; &#39;NO_ACTION&#39;, &#39;update&#39; =&gt; &#39;NO_ACTION&#39;\n        ]);\n        $table-&gt;addForeignKey(&#39;article_id&#39;, &#39;articles&#39;, &#39;id&#39;, [\n            &#39;delete&#39; =&gt; &#39;NO_ACTION&#39;, &#39;update&#39; =&gt; &#39;NO_ACTION&#39;\n        ]);\n        $table-&gt;create();\n    }\n}\n<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">\u3053\u308c\u3067 DB\u306e\u69cb\u7bc9\u306f\u3067\u304d\u305f\u304c\u3001\u5148\u306b\u9032\u3093\u3060\u6240\u3067\u9593\u9055\u3044\u304c\u3042\u308c\u3070\u4fee\u6b63\u3057\u3066\u3044\u304f\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3042\u308b\u9577\u5e74\u52d5\u3044\u3066\u3044\u305f CakePHP \uff13 \u30a2\u30d7\u30ea\u3092\u79fb\u884c\u3059\u308b\u305f\u3081\u306b\u3001\u4e00\u65e6 CakePHP5 \u306e tuta \u3092\u3084\u308a\u59cb\u3081\u305f\u3068\u3053\u308d\u3060\u3002 Cake\u516c\u5f0f\u306e\u30c1\u30e5\u30fc\u30c8\u30ea\u30a2\u30eb\u306f\u30d6\u30ed\u30b0\u30a2\u30d7\u30ea\u3092\u3064\u304f\u308b\u3053\u3068\u306b\u306a\u308b\u306e\u3060\u304c\u3001DB \u306e\u4f5c\u6210\u306f\u30d9\u30bf\u3067 SQ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":9,"footnotes":""},"categories":[9],"tags":[15],"class_list":["post-362","post","type-post","status-publish","format-standard","hentry","category-dev","tag-cakephp"],"_links":{"self":[{"href":"https:\/\/blog.txn.red\/index.php?rest_route=\/wp\/v2\/posts\/362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.txn.red\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.txn.red\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.txn.red\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.txn.red\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=362"}],"version-history":[{"count":0,"href":"https:\/\/blog.txn.red\/index.php?rest_route=\/wp\/v2\/posts\/362\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.txn.red\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.txn.red\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.txn.red\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}