Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New relations in the migration engine #612

Merged
merged 1 commit into from Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .rustfmt.toml
@@ -1 +1,2 @@
edition = "2018"
max_width = 120
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed that because rust-analyzer wasn't respecting the limit in rustfmt.toml (we have two of these, need to figure out why).

Expand Up @@ -44,6 +44,14 @@ impl DestructiveChangeDiagnostics {
pub fn has_warnings(&self) -> bool {
!self.warnings.is_empty()
}

pub fn warn_about_unexecutable_migrations(&mut self) {
for unexecutable in &self.unexecutable_migrations {
self.warnings.push(MigrationWarning {
description: unexecutable.description.clone(),
});
}
}
}

/// A warning emitted by [DestructiveChangesChecker](trait.DestructiveChangesChecker.html). Warnings will
Expand Down
Expand Up @@ -349,6 +349,9 @@ impl SqlDestructiveChangesChecker<'_> {
}
}

// Temporary, for better reporting.
diagnostics.warn_about_unexecutable_migrations();

Ok(diagnostics)
}
}
Expand Down
@@ -1,7 +1,7 @@
use super::common::*;
use crate::{sql_schema_helpers::ColumnRef, SqlFamily};
use sql_schema_describer::*;
use std::fmt::Write as _;
use std::{borrow::Cow, fmt::Write as _};

const VARCHAR_LENGTH_PREFIX: &str = "(191)";

Expand Down Expand Up @@ -58,15 +58,22 @@ impl super::SqlRenderer for MySqlRenderer {
}

impl MySqlRenderer {
fn render_column_type(&self, column: &ColumnRef<'_>) -> anyhow::Result<String> {
fn render_column_type(&self, column: &ColumnRef<'_>) -> anyhow::Result<Cow<'static, str>> {
match &column.column_type().family {
ColumnTypeFamily::Boolean => Ok(format!("boolean")),
ColumnTypeFamily::DateTime => Ok(format!("datetime(3)")),
ColumnTypeFamily::Float => Ok(format!("Decimal(65,30)")),
ColumnTypeFamily::Int => Ok(format!("int")),
ColumnTypeFamily::Boolean => Ok("boolean".into()),
ColumnTypeFamily::DateTime => {
// CURRENT_TIMESTAMP has up to second precision, not more.
if let Some(DefaultValue::NOW) = column.default() {
return Ok("datetime".into());
} else {
Ok("datetime(3)".into())
}
}
ColumnTypeFamily::Float => Ok("Decimal(65,30)".into()),
ColumnTypeFamily::Int => Ok("int".into()),
// we use varchar right now as mediumtext doesn't allow default values
// a bigger length would not allow to use such a column as primary key
ColumnTypeFamily::String => Ok(format!("varchar{}", VARCHAR_LENGTH_PREFIX)),
ColumnTypeFamily::String => Ok(format!("varchar{}", VARCHAR_LENGTH_PREFIX).into()),
ColumnTypeFamily::Enum(enum_name) => {
let r#enum = column
.schema()
Expand All @@ -75,7 +82,7 @@ impl MySqlRenderer {

let variants: String = r#enum.values.iter().map(quoted_string).join(", ");

Ok(format!("ENUM({})", variants))
Ok(format!("ENUM({})", variants).into())
}
x => unimplemented!("{:?} not handled yet", x),
}
Expand Down