Skip to content

Commit 7510815

Browse files
committed
Added timestamps, nullabletimestamps, and soft deletes
1 parent 834c310 commit 7510815

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A MySQL Workbench plugin that allows for exporting a model to Laravel 5 migratio
44
saved in it's own, properly named, migration file.
55

66
### Version
7-
0.1.1
7+
0.1.2
88

99
### Tech
1010

@@ -31,8 +31,6 @@ Want to contribute? Great!
3131
### Todos
3232

3333
- indexes
34-
- timestamps
35-
- softDeletes
3634
- types that are unsupported by Laravel
3735

3836
License

export-laravel-5-migrations.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)