@@ -54,7 +54,36 @@ def export_schema(out, schema, is_main_schema):
5454 migrations [tbl .name ].append (' {\n ' )
5555 migrations [tbl .name ].append (' Schema::create(\' %s\' , function (Blueprint $table) {\n ' % (tbl .name ))
5656
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+
5780 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+
5887 if col .simpleType :
5988 col_type = col .simpleType .name
6089 col_flags = col .simpleType .flags
@@ -106,6 +135,13 @@ def export_schema(out, schema, is_main_schema):
106135 migrations [tbl .name ].append (";" )
107136 migrations [tbl .name ].append ('\n ' )
108137
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+
109145 first_foreign_created = 0
110146 for fkey in tbl .foreignKeys :
111147 if fkey .name != '' :
0 commit comments