-
Notifications
You must be signed in to change notification settings - Fork 4
/
2016_09_04_154633_migration_laravel_modules_base.php
82 lines (70 loc) · 2.54 KB
/
2016_09_04_154633_migration_laravel_modules_base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class MigrationLaravelModulesBase extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if ( ! Schema::hasTable('provinces')) {
Schema::create('provinces', function(Blueprint $table) {
$table->increments('id');
$table->string('province', 50);
$table->engine = 'InnoDB';
});
}
if ( ! Schema::hasTable('counties')) {
Schema::create('counties', function(Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('province_id');
$table->foreign('province_id')->references('id')->on('provinces')->onDelete('cascade');
$table->string('county', 75);
$table->engine = 'InnoDB';
});
}
if ( ! Schema::hasTable('districts')) {
Schema::create('districts', function(Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('county_id');
$table->foreign('county_id')->references('id')->on('counties')->onDelete('cascade');
$table->string('district', 75);
$table->engine = 'InnoDB';
});
}
if ( ! Schema::hasTable('neighborhoods')) {
Schema::create('neighborhoods', function(Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('district_id');
$table->foreign('district_id')->references('id')->on('districts')->onDelete('cascade');
$table->string('neighborhood', 150);
$table->engine = 'InnoDB';
});
}
if ( ! Schema::hasTable('postal_codes')) {
Schema::create('postal_codes', function(Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('neighborhood_id');
$table->foreign('neighborhood_id')->references('id')->on('neighborhoods')->onDelete('cascade');
$table->char('postal_code', 6);
$table->engine = 'InnoDB';
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('postal_codes');
Schema::drop('neighborhoods');
Schema::drop('districts');
Schema::drop('counties');
Schema::drop('provinces');
}
}