@@ -54,7 +54,36 @@ def export_schema(out, schema, is_main_schema):
54
54
migrations [tbl .name ].append (' {\n ' )
55
55
migrations [tbl .name ].append (' Schema::create(\' %s\' , function (Blueprint $table) {\n ' % (tbl .name ))
56
56
57
+ created_at = False
58
+ created_at_nullable = False
59
+ updated_at = False
60
+ updated_at_nullable = False
61
+ deleted_at = False
62
+ timestamps = False
63
+ timestamps_nullable = False
64
+
65
+ for col in tbl .columns :
66
+ if col .name == 'created_at' :
67
+ created_at = True
68
+ if col .isNotNull != 1 :
69
+ created_at_nullable = True
70
+ elif col .name == 'updated_at' :
71
+ updated_at = True
72
+ if col .isNotNull != 1 :
73
+ updated_at_nullable = True
74
+
75
+ if created_at is True and updated_at is True and created_at_nullable is True and updated_at_nullable is True :
76
+ timestamps_nullable = True
77
+ elif created_at is True and updated_at is True :
78
+ timestamps = True
79
+
57
80
for col in tbl .columns :
81
+ if (col .name == 'created_at' or col .name == 'updated_at' ) and (timestamps is True or timestamps_nullable is True ):
82
+ continue
83
+ if col .name == 'deleted_at' :
84
+ deleted_at = True
85
+ continue
86
+
58
87
if col .simpleType :
59
88
col_type = col .simpleType .name
60
89
col_flags = col .simpleType .flags
@@ -106,6 +135,13 @@ def export_schema(out, schema, is_main_schema):
106
135
migrations [tbl .name ].append (";" )
107
136
migrations [tbl .name ].append ('\n ' )
108
137
138
+ if deleted_at is True :
139
+ migrations [tbl .name ].append (' $table->softDeletes();\n ' )
140
+ if timestamps is True :
141
+ migrations [tbl .name ].append (' $table->timestamps();\n ' )
142
+ elif timestamps_nullable is True :
143
+ migrations [tbl .name ].append (' $table->nullableTimestamps();\n ' )
144
+
109
145
first_foreign_created = 0
110
146
for fkey in tbl .foreignKeys :
111
147
if fkey .name != '' :
0 commit comments