Skip to content

Commit

Permalink
fixed modify change on mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
josephmancuso committed Feb 5, 2021
1 parent c70129f commit da71d48
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/masoniteorm/schema/platforms/MySQLPlatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,12 @@ def compile_alter_sql(self, table):
)

if table.changed_columns:

sql.append(
self.alter_format().format(
table=self.wrap_table(table.name),
columns="MODIFY "
+ ", ".join(self.columnize(table.changed_columns)),
columns=", ".join(
f"MODIFY {x}" for x in self.columnize(table.changed_columns)
),
)
)

Expand Down
5 changes: 3 additions & 2 deletions tests/mysql/schema/test_mysql_schema_builder_alter.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,19 @@ def test_alter_drop_unique_constraint_shortcut(self):
def test_change(self):
with self.schema.table("users") as blueprint:
blueprint.integer("age").change()
blueprint.integer("gender").nullable().change()
blueprint.string("name")

self.assertEqual(len(blueprint.table.added_columns), 1)
self.assertEqual(len(blueprint.table.changed_columns), 1)
self.assertEqual(len(blueprint.table.changed_columns), 2)
table = Table("users")
table.add_column("age", "string")

blueprint.table.from_table = table

sql = [
"ALTER TABLE `users` ADD `name` VARCHAR(255) NOT NULL",
"ALTER TABLE `users` MODIFY `age` INT(11) NOT NULL",
"ALTER TABLE `users` MODIFY `age` INT(11) NOT NULL, MODIFY `gender` INT(11) NULL",
]

self.assertEqual(blueprint.to_sql(), sql)
Expand Down

0 comments on commit da71d48

Please sign in to comment.