diff --git a/migra-cli/Cargo.toml b/migra-cli/Cargo.toml index 80682b8..0582083 100644 --- a/migra-cli/Cargo.toml +++ b/migra-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "migra-cli" -version = "0.1.1" +version = "0.1.2" authors = ["Dmitriy Pleshevskiy "] edition = "2018" description = "Simple SQL migration manager for your project" diff --git a/migra-cli/src/database.rs b/migra-cli/src/database.rs index e6ccf1e..74c9564 100644 --- a/migra-cli/src/database.rs +++ b/migra-cli/src/database.rs @@ -9,7 +9,7 @@ pub trait ToSql { impl ToSql for &str { fn to_sql(&self) -> String { - format!(r#""{}""#, self) + format!("'{}'", self) } } diff --git a/migra-cli/src/migration.rs b/migra-cli/src/migration.rs index dd3410e..b4781c7 100644 --- a/migra-cli/src/migration.rs +++ b/migra-cli/src/migration.rs @@ -67,17 +67,6 @@ pub fn is_migrations_table_not_found(error: D) -> bool { } pub trait DatabaseMigrationManager { - const CREATE_MIGRATIONS_STMT: &'static str = r#" - CREATE TABLE IF NOT EXISTS migrations ( - id serial PRIMARY KEY, - name text NOT NULL UNIQUE - ) - "#; - - const INSERT_MIGRATION_STMT: &'static str = "INSERT INTO migrations (name) VALUES ($1)"; - - const DELETE_MIGRATION_STMT: &'static str = "DELETE FROM migrations WHERE name = $1"; - fn apply_sql(&mut self, sql_content: &str) -> StdResult<()>; fn create_migrations_table(&mut self) -> StdResult<()>; @@ -115,15 +104,20 @@ where } fn create_migrations_table(&mut self) -> StdResult<()> { - self.conn.batch_execute(Self::CREATE_MIGRATIONS_STMT) + self.conn.batch_execute( + r#"CREATE TABLE IF NOT EXISTS migrations ( + id serial PRIMARY KEY, + name text NOT NULL UNIQUE + )"# + ) } fn insert_migration_info(&mut self, name: &str) -> StdResult { - self.conn.execute(Self::INSERT_MIGRATION_STMT, &[&name]) + self.conn.execute("INSERT INTO migrations (name) VALUES ($1)", &[&name]) } fn delete_migration_info(&mut self, name: &str) -> StdResult { - self.conn.execute(Self::DELETE_MIGRATION_STMT, &[&name]) + self.conn.execute("DELETE FROM migrations WHERE name = $1", &[&name]) } }