File tree 4 files changed +27
-4
lines changed
4 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -151,8 +151,18 @@ pub enum AlterTableOperation {
151
151
} ,
152
152
/// `DROP PRIMARY KEY`
153
153
///
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
155
157
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
+ } ,
156
166
/// `ENABLE ALWAYS RULE rewrite_rule_name`
157
167
///
158
168
/// Note: this is a PostgreSQL-specific operation.
@@ -530,6 +540,7 @@ impl fmt::Display for AlterTableOperation {
530
540
)
531
541
}
532
542
AlterTableOperation :: DropPrimaryKey => write ! ( f, "DROP PRIMARY KEY" ) ,
543
+ AlterTableOperation :: DropForeignKey { name } => write ! ( f, "DROP FOREIGN KEY {name}" ) ,
533
544
AlterTableOperation :: DropColumn {
534
545
column_name,
535
546
if_exists,
Original file line number Diff line number Diff line change @@ -998,6 +998,7 @@ impl Spanned for AlterTableOperation {
998
998
. span ( )
999
999
. union_opt ( & with_name. as_ref ( ) . map ( |n| n. span ) ) ,
1000
1000
AlterTableOperation :: DropPrimaryKey => Span :: empty ( ) ,
1001
+ AlterTableOperation :: DropForeignKey { name } => name. span ,
1001
1002
AlterTableOperation :: EnableAlwaysRule { name } => name. span ,
1002
1003
AlterTableOperation :: EnableAlwaysTrigger { name } => name. span ,
1003
1004
AlterTableOperation :: EnableReplicaRule { name } => name. span ,
Original file line number Diff line number Diff line change @@ -8008,10 +8008,11 @@ impl<'a> Parser<'a> {
8008
8008
name,
8009
8009
drop_behavior,
8010
8010
}
8011
- } else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY])
8012
- && dialect_of!(self is MySqlDialect | GenericDialect)
8013
- {
8011
+ } else if self.parse_keywords(&[Keyword::PRIMARY, Keyword::KEY]) {
8014
8012
AlterTableOperation::DropPrimaryKey
8013
+ } else if self.parse_keywords(&[Keyword::FOREIGN, Keyword::KEY]) {
8014
+ let name = self.parse_identifier()?;
8015
+ AlterTableOperation::DropForeignKey { name }
8015
8016
} else if self.parse_keyword(Keyword::PROJECTION)
8016
8017
&& dialect_of!(self is ClickHouseDialect|GenericDialect)
8017
8018
{
Original file line number Diff line number Diff line change @@ -2273,6 +2273,16 @@ fn parse_alter_table_drop_primary_key() {
2273
2273
) ;
2274
2274
}
2275
2275
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
+
2276
2286
#[ test]
2277
2287
fn parse_alter_table_change_column ( ) {
2278
2288
let expected_name = ObjectName :: from ( vec ! [ Ident :: new( "orders" ) ] ) ;
You can’t perform that action at this time.
0 commit comments