Skip to content

Commit

Permalink
remove postgres enum support (for now)
Browse files Browse the repository at this point in the history
if you're reading this and you need this plz open an issue (and tag me)
  • Loading branch information
m1guelpf committed Sep 2, 2023
1 parent 877f0ef commit 2d7c9a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
11 changes: 4 additions & 7 deletions ensemble/src/migrations/schema/column.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use ensemble_derive::Column;
#[cfg(feature = "mysql")]
use itertools::Itertools;
use rbs::Value;
use std::{fmt::Display, sync::mpsc};
Expand All @@ -15,6 +16,7 @@ pub enum Type {
Timestamp,
BigInteger,
String(u32),
#[cfg(feature = "mysql")]
Enum(Vec<String>),
}

Expand All @@ -31,6 +33,7 @@ impl Display for Type {
let value = format!("varchar({size})");
f.write_str(&value)
}
#[cfg(feature = "mysql")]
Self::Enum(values) => {
let value = format!(
"enum({})",
Expand Down Expand Up @@ -102,6 +105,7 @@ impl Column {
rbs::to_value!(default)
};

#[cfg(feature = "mysql")]
if let Type::Enum(values) = &self.r#type {
assert!(
values.contains(&value.as_str().unwrap_or_default().to_string()),
Expand Down Expand Up @@ -146,13 +150,6 @@ impl Column {
}

if let Some(default) = &self.default {
if let Type::Enum(values) = &self.r#type {
assert!(
values.contains(&default.to_string()),
"default value must be one of the enum values"
);
}

sql.push_str(&format!(" DEFAULT {default}"));
}

Expand Down
1 change: 1 addition & 0 deletions ensemble/src/migrations/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl Table {
ForeignIndex::new(column.to_string(), self.name.clone(), self.sender.clone())
}

#[cfg(feature = "mysql")]
/// Create a new enum column on the table.
pub fn r#enum(&mut self, name: &str, values: &[&str]) -> Column {
Column::new(
Expand Down

0 comments on commit 2d7c9a5

Please sign in to comment.