| 1 |
<?php |
| 2 |
|
| 3 |
namespace FormGent\Database; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
use FormGent\WpMVC\Database\Schema\Schema; |
| 8 |
use FormGent\WpMVC\Database\Schema\Blueprint; |
| 9 |
|
| 10 |
class Setup { |
| 11 |
public function execute() { |
| 12 |
$prefix = 'formgent_'; |
| 13 |
|
| 14 |
// -- Table: responses |
| 15 |
Schema::create( |
| 16 |
"{$prefix}responses", function ( Blueprint $table ) { |
| 17 |
$table->big_increments( 'id' ); |
| 18 |
$table->unsigned_big_integer( 'form_id' ); |
| 19 |
$table->enum( 'status', ['publish', 'draft'] )->default( 'publish' ); |
| 20 |
$table->tiny_integer( 'is_read' )->default( 0 )->comment( 'value: 0/1' ); |
| 21 |
$table->tiny_integer( 'is_completed' )->default( 0 )->comment( 'value: 0/1' ); |
| 22 |
$table->timestamp( 'completed_at' )->nullable(); |
| 23 |
$table->tiny_integer( 'is_starred' )->default( 0 )->comment( 'value: 0/1' ); |
| 24 |
$table->string( 'ip', 50 )->nullable(); |
| 25 |
$table->string( 'device', 50 )->nullable(); |
| 26 |
$table->string( 'browser', 50 )->nullable(); |
| 27 |
$table->string( 'browser_version', 50 )->nullable(); |
| 28 |
$table->unsigned_big_integer( 'created_by' )->nullable(); |
| 29 |
$table->timestamps(); |
| 30 |
|
| 31 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 32 |
} |
| 33 |
); |
| 34 |
|
| 35 |
// -- Table: response_meta |
| 36 |
Schema::create( |
| 37 |
"{$prefix}response_meta", function ( Blueprint $table ) use ( $prefix ) { |
| 38 |
$table->big_increments( 'id' ); |
| 39 |
$table->unsigned_big_integer( 'response_id' ); |
| 40 |
$table->string( 'meta_key', 255 ); |
| 41 |
$table->long_text( 'meta_value' )->nullable(); |
| 42 |
|
| 43 |
$table->foreign( 'response_id' )->references( 'id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 44 |
} |
| 45 |
); |
| 46 |
|
| 47 |
// -- Table: answers |
| 48 |
Schema::create( |
| 49 |
"{$prefix}answers", function ( Blueprint $table ) use ( $prefix ) { |
| 50 |
$table->big_increments( 'id' ); |
| 51 |
$table->unsigned_big_integer( 'response_id' ); |
| 52 |
$table->unsigned_big_integer( 'form_id' ); |
| 53 |
$table->unsigned_big_integer( 'parent_id' )->nullable(); |
| 54 |
$table->string( 'field_name', 50 ); |
| 55 |
$table->string( 'field_type', 50 ); |
| 56 |
$table->long_text( 'value' )->nullable(); |
| 57 |
$table->timestamps(); |
| 58 |
|
| 59 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 60 |
$table->foreign( 'response_id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 61 |
$table->foreign( 'parent_id' )->on( "{$prefix}answers" )->on_delete( 'cascade' ); |
| 62 |
} |
| 63 |
); |
| 64 |
|
| 65 |
// -- Table: notes |
| 66 |
Schema::create( |
| 67 |
"{$prefix}notes", function ( Blueprint $table ) use ( $prefix ) { |
| 68 |
$table->big_increments( 'id' ); |
| 69 |
$table->unsigned_big_integer( 'response_id' ); |
| 70 |
$table->long_text( 'note' )->nullable(); |
| 71 |
$table->timestamps(); |
| 72 |
|
| 73 |
$table->foreign( 'response_id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 74 |
} |
| 75 |
); |
| 76 |
|
| 77 |
// -- Table: response_token |
| 78 |
Schema::create( |
| 79 |
"{$prefix}response_token", function ( Blueprint $table ) use ( $prefix ) { |
| 80 |
$table->big_increments( 'id' ); |
| 81 |
$table->unsigned_big_integer( 'form_id' ); |
| 82 |
$table->unsigned_big_integer( 'response_id' ); |
| 83 |
$table->string( 'token' ); |
| 84 |
$table->timestamp( 'created_at' )->use_current(); |
| 85 |
$table->timestamp( 'expired_at' )->nullable(); |
| 86 |
|
| 87 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 88 |
$table->foreign( 'response_id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 89 |
} |
| 90 |
); |
| 91 |
|
| 92 |
// -- Table: email_notifications |
| 93 |
Schema::create( |
| 94 |
"{$prefix}email_notifications", function ( Blueprint $table ) { |
| 95 |
$table->big_increments( 'id' ); |
| 96 |
$table->unsigned_big_integer( 'form_id' ); |
| 97 |
$table->string( 'name' ); |
| 98 |
$table->string( 'send_to' ); |
| 99 |
$table->string( 'subject' ); |
| 100 |
$table->long_text( 'body' )->nullable(); |
| 101 |
$table->string( 'cc' )->nullable(); |
| 102 |
$table->string( 'bcc' )->nullable(); |
| 103 |
$table->string( 'reply_to' )->nullable(); |
| 104 |
$table->string( 'from_name' )->nullable(); |
| 105 |
$table->string( 'from_email' )->nullable(); |
| 106 |
$table->enum( 'status', ['publish', 'draft'] )->default( 'publish' ); |
| 107 |
$table->enum( 'condition_type', ['or', 'and'] )->default( 'or' ); |
| 108 |
$table->tiny_integer( 'condition_status' )->default( 0 )->comment( 'value: 0/1' ); |
| 109 |
$table->long_text( 'conditions' )->nullable(); |
| 110 |
$table->timestamps(); |
| 111 |
|
| 112 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 113 |
} |
| 114 |
); |
| 115 |
|
| 116 |
// -- Table: google_spreadsheets |
| 117 |
Schema::create( |
| 118 |
"{$prefix}google_spreadsheets", function ( Blueprint $table ) { |
| 119 |
$table->big_increments( 'id' ); |
| 120 |
$table->unsigned_big_integer( 'form_id' ); |
| 121 |
$table->string( 'title' )->nullable(); |
| 122 |
$table->string( 'spreadsheet_id' )->nullable(); |
| 123 |
$table->string( 'sheet_title' )->nullable(); |
| 124 |
$table->string( 'sheet_id' )->nullable(); |
| 125 |
$table->enum( 'status', ['publish', 'draft'] )->default( 'draft' ); |
| 126 |
$table->enum( 'field_mapping_type', ['auto', 'manual'] )->default( 'auto' ); |
| 127 |
$table->long_text( 'field_mapping' )->nullable(); |
| 128 |
$table->long_text( 'columns' )->nullable(); |
| 129 |
$table->tiny_integer( 'is_columns_updated' )->default( 1 )->comment( 'value: 0/1' ); |
| 130 |
$table->enum( 'condition_type', ['or', 'and'] )->default( 'or' ); |
| 131 |
$table->tiny_integer( 'condition_status' )->default( 0 )->comment( 'value: 0/1' ); |
| 132 |
$table->long_text( 'conditions' )->nullable(); |
| 133 |
$table->timestamps(); |
| 134 |
|
| 135 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 136 |
} |
| 137 |
); |
| 138 |
|
| 139 |
// -- Table: mailchimp_feeds |
| 140 |
Schema::create( |
| 141 |
"{$prefix}mailchimp_feeds", function ( Blueprint $table ) { |
| 142 |
$table->big_increments( 'id' ); |
| 143 |
$table->unsigned_big_integer( 'form_id' ); |
| 144 |
$table->string( 'title' ); |
| 145 |
$table->string( 'list_id' ); |
| 146 |
$table->string( 'group_id' )->nullable(); |
| 147 |
$table->string( 'group_option_id' )->nullable(); |
| 148 |
$table->long_text( 'field_mapping' )->nullable(); |
| 149 |
$table->long_text( 'tags' )->nullable(); |
| 150 |
$table->tiny_integer( 'double_opt_in' )->default( 0 )->comment( 'value: 0/1' ); |
| 151 |
$table->tiny_integer( 'resubscribe_existing_contact' )->default( 0 )->comment( 'value: 0/1' ); |
| 152 |
$table->tiny_integer( 'update_existing_contact' )->default( 0 )->comment( 'value: 0/1' ); |
| 153 |
$table->tiny_integer( 'mark_as_vip' )->default( 0 )->comment( 'value: 0/1' ); |
| 154 |
$table->tiny_integer( 'condition_status' )->default( 0 )->comment( 'value: 0/1' ); |
| 155 |
$table->enum( 'condition_type', ['or', 'and'] )->default( 'or' ); |
| 156 |
$table->long_text( 'conditions' )->nullable(); |
| 157 |
$table->tiny_integer( 'status' )->default( 0 )->comment( 'value: 0/1' ); |
| 158 |
|
| 159 |
$table->timestamps(); |
| 160 |
|
| 161 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 162 |
} |
| 163 |
); |
| 164 |
|
| 165 |
// -- Table: zapier_zaps |
| 166 |
Schema::create( |
| 167 |
"{$prefix}zapier_zaps", function ( Blueprint $table ) { |
| 168 |
$table->big_increments( 'id' ); |
| 169 |
$table->unsigned_big_integer( 'form_id' ); |
| 170 |
$table->unsigned_big_integer( 'zap_id' ); |
| 171 |
$table->timestamp( 'created_at' )->use_current(); |
| 172 |
|
| 173 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 174 |
} |
| 175 |
); |
| 176 |
|
| 177 |
// -- Table: zapier_processed_responses |
| 178 |
Schema::create( |
| 179 |
"{$prefix}zapier_processed_responses", function ( Blueprint $table ) use ( $prefix ) { |
| 180 |
$table->big_increments( 'id' ); |
| 181 |
$table->unsigned_big_integer( 'zap_id' ); |
| 182 |
$table->unsigned_big_integer( 'response_id' ); |
| 183 |
$table->timestamp( 'created_at' )->use_current(); |
| 184 |
|
| 185 |
$table->foreign( 'response_id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 186 |
} |
| 187 |
); |
| 188 |
|
| 189 |
|
| 190 |
// -- Table: zohocrm_feed |
| 191 |
Schema::create( |
| 192 |
"{$prefix}zohocrm_feed", function ( Blueprint $table ) { |
| 193 |
$table->big_increments( 'id' ); |
| 194 |
$table->unsigned_big_integer( 'form_id' ); |
| 195 |
$table->string( 'module' ); |
| 196 |
$table->long_text( 'fields' ); |
| 197 |
$table->tiny_integer( 'status' )->default( 1 )->comment( 'value: 0/1' ); |
| 198 |
$table->tiny_integer( 'condition_status' )->default( 0 )->comment( 'value: 0/1' ); |
| 199 |
$table->enum( 'condition_type', ['or', 'and'] )->default( 'or' ); |
| 200 |
$table->long_text( 'conditions' )->nullable(); |
| 201 |
$table->timestamps(); |
| 202 |
|
| 203 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 204 |
} |
| 205 |
); |
| 206 |
|
| 207 |
// -- Table: orders |
| 208 |
Schema::create( |
| 209 |
"{$prefix}orders", function ( Blueprint $table ) use ( $prefix ) { |
| 210 |
$table->big_increments( 'id' ); |
| 211 |
$table->unsigned_big_integer( 'response_id' )->nullable(); |
| 212 |
$table->decimal( 'amount', 10, 2 ); |
| 213 |
$table->string( 'currency', 10 ); |
| 214 |
$table->decimal( 'final_amount', 10, 2 )->default( 0.00 ); |
| 215 |
$table->enum( 'status', ['pending','paid','failed','cancelled','expired','refunded','unpaid'] )->default( 'pending' ); |
| 216 |
$table->string( 'hash' )->comment( "Using for public payment link" ); |
| 217 |
$table->timestamps(); |
| 218 |
|
| 219 |
$table->foreign( 'response_id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 220 |
} |
| 221 |
); |
| 222 |
|
| 223 |
// -- Table: order_items |
| 224 |
Schema::create( |
| 225 |
"{$prefix}order_items", function ( Blueprint $table ) use ( $prefix ) { |
| 226 |
$table->big_increments( 'id' ); |
| 227 |
$table->unsigned_big_integer( 'order_id' )->nullable(); |
| 228 |
$table->string( 'title', 255 )->nullable(); |
| 229 |
$table->decimal( 'unit_amount', 10, 2 )->default( 0.00 ); |
| 230 |
$table->integer( 'quantity' ); |
| 231 |
$table->decimal( 'total_amount', 10, 2 )->default( 0.00 ); |
| 232 |
$table->timestamps(); |
| 233 |
|
| 234 |
$table->foreign( 'order_id' )->on( "{$prefix}orders" )->on_delete( 'cascade' ); |
| 235 |
} |
| 236 |
); |
| 237 |
|
| 238 |
// -- Table: payments |
| 239 |
Schema::create( |
| 240 |
"{$prefix}payments", function ( Blueprint $table ) use ( $prefix ) { |
| 241 |
$table->big_increments( 'id' ); |
| 242 |
$table->unsigned_big_integer( 'order_id' ); |
| 243 |
$table->decimal( 'amount', 10, 2 ); |
| 244 |
$table->string( 'currency', 10 ); |
| 245 |
$table->enum( 'status', ['pending','paid','failed','cancelled','refunded','unpaid','expired'] )->default( 'pending' ); |
| 246 |
$table->string( 'transaction_id', 100 )->nullable(); |
| 247 |
$table->string( 'method', 30 )->nullable(); |
| 248 |
$table->string( 'billing_email', 255 )->nullable(); |
| 249 |
$table->string( 'billing_name', 255 )->nullable(); |
| 250 |
$table->string( 'billing_country', 255 )->nullable(); |
| 251 |
$table->timestamps(); |
| 252 |
|
| 253 |
$table->foreign( 'order_id' )->references( 'id' )->on( "{$prefix}orders" )->on_delete( 'cascade' ); |
| 254 |
} |
| 255 |
); |
| 256 |
|
| 257 |
// -- Table: queues |
| 258 |
Schema::create( |
| 259 |
"{$prefix}queues", function( Blueprint $table ) use ( $prefix ) { |
| 260 |
$table->big_increments( 'id' ); |
| 261 |
$table->unsigned_big_integer( 'form_id' ); |
| 262 |
$table->unsigned_big_integer( 'response_id' ); |
| 263 |
$table->string( 'task_type' ); |
| 264 |
$table->string( 'task_id' ); |
| 265 |
$table->enum( 'status', ['in_queue', 'in_progress', 'failed'] )->default( 'in_queue' ); |
| 266 |
$table->timestamps(); |
| 267 |
|
| 268 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 269 |
$table->foreign( 'response_id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 270 |
} |
| 271 |
); |
| 272 |
|
| 273 |
// -- Table: pdfs (PDF template configurations) |
| 274 |
Schema::create( |
| 275 |
"{$prefix}pdfs", function ( Blueprint $table ) { |
| 276 |
$table->big_increments( 'id' ); |
| 277 |
$table->unsigned_big_integer( 'form_id' ); |
| 278 |
$table->string( 'template_name' ); |
| 279 |
$table->string( 'template_type' )->nullable(); |
| 280 |
$table->long_text( 'content' ); |
| 281 |
$table->string( 'paper_size' )->nullable(); |
| 282 |
$table->string( 'orientation' )->nullable(); |
| 283 |
$table->string( 'direction' )->nullable(); |
| 284 |
$table->text( 'password' )->nullable(); |
| 285 |
$table->timestamps(); |
| 286 |
|
| 287 |
$table->foreign( 'form_id' )->references( 'ID' )->on( 'posts' )->on_delete( 'cascade' ); |
| 288 |
} |
| 289 |
); |
| 290 |
|
| 291 |
// -- Table: response_logs |
| 292 |
Schema::create( |
| 293 |
"{$prefix}response_logs", function ( Blueprint $table ) use ( $prefix ) { |
| 294 |
$table->big_increments( 'id' ); |
| 295 |
$table->unsigned_big_integer( 'response_id' ); |
| 296 |
$table->string( 'action', 50 )->default( 'entry_edited' ); |
| 297 |
$table->unsigned_big_integer( 'created_by' )->nullable(); |
| 298 |
$table->long_text( 'meta' )->nullable(); |
| 299 |
$table->timestamp( 'created_at' )->use_current(); |
| 300 |
|
| 301 |
$table->foreign( 'response_id' )->on( "{$prefix}responses" )->on_delete( 'cascade' ); |
| 302 |
} |
| 303 |
); |
| 304 |
} |
| 305 |
} |