@@ -2,37 +2,28 @@ use anyhow::Context;
22
33use crate::db::Conn;
44
5−pub fn set_up_helpers(db: &mut dyn Conn, current_migration: &Option<String>) -> anyhow::Result<()> {
6− let predicate = if let Some(current_migration) = current_migration {
7− format!(
8− "current_setting('search_path') = 'migration_{}' OR setting_bool",
9− current_migration
10− )
11− } else {
12− "setting_bool".to_string()
13− };
14−
5+pub fn set_up_helpers(db: &mut dyn Conn, target_migration: &str) -> anyhow::Result<()> {
156 let query = format!(
167 "
17− CREATE OR REPLACE FUNCTION reshape.is_old_schema()
8+ CREATE OR REPLACE FUNCTION reshape.is_new_schema()
189 RETURNS BOOLEAN AS $$
1910 DECLARE
20− setting TEXT := current_setting('reshape.is_old_schema', TRUE);
11+ setting TEXT := current_setting('reshape.is_new_schema', TRUE);
2112 setting_bool BOOLEAN := setting IS NOT NULL AND setting = 'YES';
2213 BEGIN
23− RETURN {};
14+ RETURN current_setting('search_path') = 'migration_{}' OR setting_bool;
2415 END
2516 $$ language 'plpgsql';
2617 ",
27− predicate
18+ target_migration,
2819 );
2920 db.query(&query)
30− .context("failed creating helper function reshape.is_old_schema()")?;
21+ .context("failed creating helper function reshape.is_new_schema()")?;
3122
3223 Ok(())
3324}
3425
3526pub fn tear_down_helpers(db: &mut dyn Conn) -> anyhow::Result<()> {
36− db.query("DROP FUNCTION IF EXISTS reshape.is_old_schema;")?;
27+ db.query("DROP FUNCTION IF EXISTS reshape.is_new_schema;")?;
3728 Ok(())
3829}