File tree Expand file tree Collapse file tree 4 files changed +27
-4
lines changed
Expand file tree Collapse file tree 4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -151,8 +151,18 @@ pub enum AlterTableOperation {
151151 } ,
152152 /// `DROP PRIMARY KEY`
153153 ///
154- /// Note: this is a MySQL-specific operation.
154+ /// Note: this is a [MySQL]-specific operation.
155+ ///
156+ /// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
155157 DropPrimaryKey ,
158+ /// `DROP FOREIGN KEY <fk_symbol>`
159+ ///
160+ /// Note: this is a [MySQL]-specific operation.
161+ ///
162+ /// [MySQL]: https://dev.mysql.com/doc/refman/8.4/en/alter-table.html
163+ DropForeignKey {
164+ name : Ident ,
165+ } ,
156166 /// `ENABLE ALWAYS RULE rewrite_rule_name`
157167 ///
158168 /// Note: this is a PostgreSQL-specific operation.
@@ -530,6 +540,7 @@ impl fmt::Display for AlterTableOperation {
530540 )
531541 }
532542 AlterTableOperation :: DropPrimaryKey => write ! ( f, "DROP PRIMARY KEY" ) ,
543+ AlterTableOperation :: DropForeignKey { name } => write ! ( f, "DROP FOREIGN KEY {name}" ) ,
533544 AlterTableOperation :: DropColumn {
534545 column_name,
535546 if_exists,
Original file line number Diff line number Diff line change @@ -998,6 +998,7 @@ impl Spanned for AlterTableOperation {
998998 . span ( )
999999 . union_opt ( & with_name. as_ref ( ) . map ( |n| n. span ) ) ,
10001000 AlterTableOperation :: DropPrimaryKey => Span :: empty ( ) ,
1001+ AlterTableOperation :: DropForeignKey { name } => name. span ,
10011002 AlterTableOperation :: EnableAlwaysRule { name } => name. span ,
10021003 AlterTableOperation :: EnableAlwaysTrigger { name } => name. span ,
10031004 AlterTableOperation :: EnableReplicaRule { name } => name. span ,
Original file line number Diff line number Diff line change @@ -7998,10 +7998,11 @@ impl<'a> Parser<'a> {
79987998 name,
79997999 drop_behavior,
80008000 }
8001- } else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY])
8002- && dialect_of!(self is MySqlDialect | GenericDialect)
8003- {
8001+ } else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY]) {
80048002 AlterTableOperation::DropPrimaryKey
8003+ } else if self.parse_keywords(&[Keyword::FOREIGN, Keyword::KEY]) {
8004+ let name = self.parse_identifier()?;
8005+ AlterTableOperation::DropForeignKey { name }
80058006 } else if self.parse_keyword(Keyword::PROJECTION)
80068007 && dialect_of!(self is ClickHouseDialect|GenericDialect)
80078008 {
Original file line number Diff line number Diff line change @@ -2273,6 +2273,16 @@ fn parse_alter_table_drop_primary_key() {
22732273 ) ;
22742274}
22752275
2276+ #[ test]
2277+ fn parse_alter_table_drop_foreign_key ( ) {
2278+ assert_matches ! (
2279+ alter_table_op(
2280+ mysql_and_generic( ) . verified_stmt( "ALTER TABLE tab DROP FOREIGN KEY foo_ibfk_1" )
2281+ ) ,
2282+ AlterTableOperation :: DropForeignKey { name } if name. value == "foo_ibfk_1"
2283+ ) ;
2284+ }
2285+
22762286#[ test]
22772287fn parse_alter_table_change_column ( ) {
22782288 let expected_name = ObjectName :: from ( vec ! [ Ident :: new( "orders" ) ] ) ;
You can’t perform that action at this time.
0 commit comments