mirror of
https://github.com/ilyakooo0/reshape.git
synced 2024-11-22 01:09:15 +03:00
88fca45c06
This action enables migrations to run custom SQL and is meant to be used when no other actions fit. It doesn't provide any guarantees for zero-downtime.
129 lines
3.0 KiB
Rust
129 lines
3.0 KiB
Rust
mod common;
|
|
use common::Test;
|
|
|
|
#[test]
|
|
fn custom_enable_extension() {
|
|
let mut test = Test::new("Custom migration");
|
|
|
|
test.clear(|db| {
|
|
db.simple_query(
|
|
"
|
|
DROP EXTENSION IF EXISTS bloom;
|
|
DROP EXTENSION IF EXISTS btree_gin;
|
|
DROP EXTENSION IF EXISTS btree_gist;
|
|
",
|
|
)
|
|
.unwrap();
|
|
});
|
|
|
|
test.first_migration(
|
|
r#"
|
|
name = "empty_migration"
|
|
|
|
[[actions]]
|
|
type = "custom"
|
|
"#,
|
|
);
|
|
|
|
test.second_migration(
|
|
r#"
|
|
name = "enable_extensions"
|
|
|
|
[[actions]]
|
|
type = "custom"
|
|
|
|
start = """
|
|
CREATE EXTENSION IF NOT EXISTS bloom;
|
|
CREATE EXTENSION IF NOT EXISTS btree_gin;
|
|
"""
|
|
|
|
complete = "CREATE EXTENSION IF NOT EXISTS btree_gist"
|
|
|
|
abort = """
|
|
DROP EXTENSION IF EXISTS bloom;
|
|
DROP EXTENSION IF EXISTS btree_gin;
|
|
"""
|
|
"#,
|
|
);
|
|
|
|
test.intermediate(|db, _| {
|
|
let bloom_activated = !db
|
|
.query("SELECT * FROM pg_extension WHERE extname = 'bloom'", &[])
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(bloom_activated);
|
|
|
|
let btree_gin_activated = !db
|
|
.query(
|
|
"SELECT * FROM pg_extension WHERE extname = 'btree_gin'",
|
|
&[],
|
|
)
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(btree_gin_activated);
|
|
|
|
let btree_gist_activated = !db
|
|
.query(
|
|
"SELECT * FROM pg_extension WHERE extname = 'btree_gist'",
|
|
&[],
|
|
)
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(!btree_gist_activated);
|
|
});
|
|
|
|
test.after_completion(|db| {
|
|
let bloom_activated = !db
|
|
.query("SELECT * FROM pg_extension WHERE extname = 'bloom'", &[])
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(bloom_activated);
|
|
|
|
let btree_gin_activated = !db
|
|
.query(
|
|
"SELECT * FROM pg_extension WHERE extname = 'btree_gin'",
|
|
&[],
|
|
)
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(btree_gin_activated);
|
|
|
|
let btree_gist_activated = !db
|
|
.query(
|
|
"SELECT * FROM pg_extension WHERE extname = 'btree_gist'",
|
|
&[],
|
|
)
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(btree_gist_activated);
|
|
});
|
|
|
|
test.after_abort(|db| {
|
|
let bloom_activated = !db
|
|
.query("SELECT * FROM pg_extension WHERE extname = 'bloom'", &[])
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(!bloom_activated);
|
|
|
|
let btree_gin_activated = !db
|
|
.query(
|
|
"SELECT * FROM pg_extension WHERE extname = 'btree_gin'",
|
|
&[],
|
|
)
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(!btree_gin_activated);
|
|
|
|
let btree_gist_activated = !db
|
|
.query(
|
|
"SELECT * FROM pg_extension WHERE extname = 'btree_gist'",
|
|
&[],
|
|
)
|
|
.unwrap()
|
|
.is_empty();
|
|
assert!(!btree_gist_activated);
|
|
});
|
|
|
|
test.run();
|
|
}
|