@@ -0,0 +1,51 @@
1+use super::{Action, MigrationContext};
2+use crate::{
3+ db::{Conn, Transaction},
4+ schema::Schema,
5+};
6+use anyhow::Context;
7+use serde::{Deserialize, Serialize};
8+
9+#[derive(Serialize, Deserialize, Debug)]
10+pub struct RemoveEnum {
11+ #[serde(rename = "enum")]
12+ pub enum_name: String,
13+}
14+
15+#[typetag::serde(name = "remove_enum")]
16+impl Action for RemoveEnum {
17+ fn describe(&self) -> String {
18+ format!("Removing enum \"{}\"", self.enum_name)
19+ }
20+
21+ fn run(
22+ &self,
23+ _ctx: &MigrationContext,
24+ _db: &mut dyn Conn,
25+ _schema: &Schema,
26+ ) -> anyhow::Result<()> {
27+ Ok(())
28+ }
29+
30+ fn complete<'a>(
31+ &self,
32+ _ctx: &MigrationContext,
33+ db: &'a mut dyn Conn,
34+ ) -> anyhow::Result<Option<Transaction<'a>>> {
35+ db.run(&format!(
36+ r#"
37+ DROP TYPE IF EXISTS {name}
38+ "#,
39+ name = self.enum_name,
40+ ))
41+ .context("failed to drop enum")?;
42+
43+ Ok(None)
44+ }
45+
46+ fn update_schema(&self, _ctx: &MigrationContext, _schema: &mut Schema) {}
47+
48+ fn abort(&self, _ctx: &MigrationContext, _db: &mut dyn Conn) -> anyhow::Result<()> {
49+ Ok(())
50+ }
51+}