質問編集履歴

1

でrf

2018/03/11 15:12

投稿

earnest_gay
earnest_gay

スコア615

test CHANGED
File without changes
test CHANGED
@@ -47,3 +47,85 @@
47
47
  目的として、色々手順を増やしたくないです。
48
48
 
49
49
  他の現場はどうしてるんだろう。。。
50
+
51
+
52
+
53
+ 下記のようにmigrationsフォルダにあるファイルは実行されることに便乗して単純にinsert走らせるだけでも問題ないですかね。。。
54
+
55
+
56
+
57
+
58
+
59
+ ```
60
+
61
+ <?php
62
+
63
+
64
+
65
+ namespace Fuel\Migrations;
66
+
67
+
68
+
69
+ class Create_posts
70
+
71
+ {
72
+
73
+ public function up()
74
+
75
+ {
76
+
77
+ \DBUtil::create_table('posts', array(
78
+
79
+ 'id' => array('constraint' => 11, 'type' => 'int'),
80
+
81
+ 'title' => array('constraint' => 50, 'type' => 'varchar'),
82
+
83
+ 'body' => array('type' => 'text'),
84
+
85
+ 'tuika' => array('constraint' => 11, 'type' => 'int'),
86
+
87
+ 'created_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),
88
+
89
+ 'updated_at' => array('constraint' => 11, 'type' => 'int', 'null' => true),
90
+
91
+
92
+
93
+ ), array('id'));
94
+
95
+
96
+
97
+ //追加
98
+
99
+ $connection = Database_Connection::instance(static::$_write_connection);
100
+
101
+
102
+
103
+ $sql = '
104
+
105
+ insert マスタデータ1
106
+
107
+ insert マスタデータ2
108
+
109
+ ';
110
+
111
+
112
+
113
+ $query = DB::query($sql);
114
+
115
+ $query->execute($connection);
116
+
117
+ }
118
+
119
+
120
+
121
+ public function down()
122
+
123
+ {
124
+
125
+ \DBUtil::drop_table('posts');
126
+
127
+ }
128
+
129
+ }
130
+
131
+ ```