Skip to content

Commit

Permalink
Feature/remeber token (#39)
Browse files Browse the repository at this point in the history
* Updates

- Added testing Model
- Fix for #18
- Fixed issues with 'CURRENT_TIMESTAMP', 'NULL ON UPDATE CURRENT_TIMESTAMP',  'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
- Check for non existing column types
- Fixed index keys, primary key is no longer included
- Added .gitignore

* Updates

- Added testing Model
- Fix for #18
- Fixed issues with 'CURRENT_TIMESTAMP', 'NULL ON UPDATE CURRENT_TIMESTAMP',  'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'
- Check for non existing column types
- Fixed index keys, primary key is no longer included
- Added .gitignore

* Fix for #30

And possible for padding as well as small fixes
  • Loading branch information
VeeeneX authored Feb 20, 2017
1 parent f093bf5 commit d8c0356
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions export-laravel-5-migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
'MEDIUM_INCREMENTS': 'mediumIncrements',
'INCREMENTS': 'increments',
'TINYINT': 'tinyInteger',
'uTINYINT': 'unsignedTinyInteger',
'uTINYINT': 'unsignedTinyInteger',
'SMALLINT': 'smallInteger',
'uSMALLINT': 'unsignedSmallInteger',
'uSMALLINT': 'unsignedSmallInteger',
'MEDIUMINT': 'mediumInteger',
'uMEDIUMINT': 'unsignedMediumInteger',
'uMEDIUMINT': 'unsignedMediumInteger',
'INT': 'integer',
'uINT': 'unsignedInteger',
'uINT': 'unsignedInteger',
'BIGINT': 'bigInteger',
'uBIGINT': 'unsignedBigInteger',
'uBIGINT': 'unsignedBigInteger',
'FLOAT': 'float',
'DOUBLE': 'double',
'DECIMAL': 'decimal',
Expand Down Expand Up @@ -75,25 +75,25 @@
'FLOAT4': '',
'FLOAT8': '',
'INT1': 'tinyInteger',
'uINT1': 'unsignedTinyInteger',
'uINT1': 'unsignedTinyInteger',
'INT2': 'smallInteger',
'uINT2': 'unsignedSmallInteger',
'uINT2': 'unsignedSmallInteger',
'INT3': 'mediumInteger',
'uINT3': 'unsignedMediumInteger',
'uINT3': 'unsignedMediumInteger',
'INT4': 'integer',
'uINT4': 'unsignedInteger',
'uINT4': 'unsignedInteger',
'INT8': 'bigint',
'uINT8': 'unsignedBigInteger',
'uINT8': 'unsignedBigInteger',
'INTEGER': 'integer',
'uINTEGER': 'unsignedInteger',
'uINTEGER': 'unsignedInteger',
'LONGVARBINARY': '',
'LONGVARCHAR': '',
'LONG': '',
'MIDDLEINT': 'mediumInteger',
'NUMERIC': 'decimal',
'DEC': 'decimal',
'CHARACTER': 'char',
'UUID': 'uuid'
'UUID': 'uuid'
}

migrationTemplate = '''<?php
Expand Down Expand Up @@ -158,7 +158,8 @@ def create_tree(table_schema):
table_references = []

for key in tbl.foreignKeys:
if key.name != '' and tbl.name != key.referencedColumns[0].owner.name and hasattr(key, 'referencedColumns'):
if key.name != '' and tbl.name != key.referencedColumns[0].owner.name and hasattr(key,
'referencedColumns'):
table_references.append(key.referencedColumns[0].owner.name)

tree[tbl.name] = table_references
Expand Down Expand Up @@ -248,6 +249,12 @@ def export_schema(table_schema, tree):
]

for col in tbl.columns:
# Name is important attribute so it has to be set
# in order to make this work
# https://github.com/beckenrode/mysql-workbench-export-laravel-5-migrations/issues/18#issuecomment-272152778
if hasattr(col, 'name'):
continue

if (col.name == 'created_at' or col.name == 'updated_at') and (
timestamps is True or timestamps_nullable is True):
continue
Expand All @@ -272,8 +279,7 @@ def export_schema(table_schema, tree):
col_type = "INCREMENTS"

if (col_type == 'BIGINT' or col_type == 'INT' or col_type == 'TINYINT' or col_type == 'MEDIUMINT' or col_type == 'SMALLINT') and 'UNSIGNED' in col.flags:
col_type = "u" + col_type

col_type = "u" + col_type

col_data = '\''

Expand All @@ -298,14 +304,14 @@ def export_schema(table_schema, tree):
else:
col_data = '\''

if col.name == 'remember_token' and typesDict[col_type] == 'string' and str(col.length) == 100:
if col.name == 'remember_token' and typesDict[col_type] == 'string' and str(col.length) == '100':
migrations[ti].append(' $table->rememberToken();\n')
elif typesDict[col_type]:
migrations[ti].append(
' $table->%s(\'%s%s)' % (typesDict[col_type], col.name, col_data))

if typesDict[col_type] == 'integer' and 'UNSIGNED' in col.flags:
migrations[ti].append('->unsigned()')
migrations[ti].append('->unsigned()')

if col.isNotNull != 1:
migrations[ti].append('->nullable()')
Expand Down Expand Up @@ -502,7 +508,7 @@ def go_cancel(self):

def create_ui(self):
button_box = mforms.newBox(True)
button_box.set_padding(8)
button_box.set_padding(20)

button_box.add(self.save_button, False, True)

Expand Down

0 comments on commit d8c0356

Please sign in to comment.