mmatuson / SchemaSync

A MySQL Schema Versioning and Migration Utility
http://mmatuson.github.io/SchemaSync/
Other
338 stars 108 forks source link

Drop index incorrect syntax #49

Closed isgroup-srl closed 6 years ago

isgroup-srl commented 7 years ago

There should not be an ON statement after DROP INDEX inside an ALTER TABLE query (http://dev.mysql.com/doc/refman/5.7/en/alter-table.html). This behavior is legit if the DROP INDEX is used as a standalone query (http://dev.mysql.com/doc/refman/5.7/en/drop-index.html).

ALTER TABLE `foo` ADD COLUMN `x` bigint(20) unsigned NOT NULL AFTER `id`, DROP INDEX `y` ON `foo` [..]

Should be:

ALTER TABLE `foo` ADD COLUMN `x` bigint(20) unsigned NOT NULL AFTER `id`, DROP INDEX `y` [..]
cpd1992 commented 7 years ago

Can anybody repair this issue? Thanks a lot

jacoryjin commented 7 years ago

schemaobject->index.py->class IndexSchema(object)->drop,

if self.name == 'PRIMARY': return "DROP PRIMARY KEY" else: return "DROP INDEX %s ON %s" % (self.name, self.parent.name)

changed to:

if self.name == 'PRIMARY': return "DROP PRIMARY KEY" else: return "DROP INDEX `%s``" % (self.name)

mmatuson commented 7 years ago

@jacoryjin if you can submit a PR, I'll merge it

stephenreay commented 7 years ago

This should be fixed in mmatuson/SchemaObject#13

stephenreay commented 6 years ago

@mmatuson any chance of getting the referenced PR above merged in (as it should fix this issue)?