mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix(data): baseline 迁移末尾恢复 search_path 为 public,确保 sqlx 记账正常
This commit is contained in:
@@ -4579,9 +4579,12 @@ EXCEPTION
|
||||
WHEN invalid_table_definition THEN NULL;
|
||||
END $mig$;
|
||||
|
||||
-- Restore a normal lookup path before sqlx records this migration in the
|
||||
-- same transaction. sqlx inserts into `_sqlx_migrations` unqualified.
|
||||
SELECT pg_catalog.set_config('search_path', 'public', true);
|
||||
|
||||
|
||||
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
|
||||
@@ -168,17 +168,23 @@ mod tests {
|
||||
use super::MIGRATOR;
|
||||
|
||||
#[test]
|
||||
fn baseline_migration_keeps_empty_search_path_transaction_local() {
|
||||
fn baseline_migration_restores_search_path_for_sqlx_bookkeeping() {
|
||||
let baseline = MIGRATOR
|
||||
.iter()
|
||||
.find(|migration| migration.version == 20260403000000)
|
||||
.expect("baseline migration should be embedded");
|
||||
let first_empty_search_path = baseline
|
||||
.sql
|
||||
.find("SELECT pg_catalog.set_config('search_path', '', true);")
|
||||
.expect("baseline migration should clear search_path transaction-local");
|
||||
let restore_public_search_path = baseline
|
||||
.sql
|
||||
.rfind("SELECT pg_catalog.set_config('search_path', 'public', true);")
|
||||
.expect("baseline migration should restore search_path before sqlx bookkeeping");
|
||||
|
||||
assert!(
|
||||
baseline
|
||||
.sql
|
||||
.contains("SELECT pg_catalog.set_config('search_path', '', true);"),
|
||||
"baseline migration must keep empty search_path transaction-local so sqlx bookkeeping can still access _sqlx_migrations",
|
||||
first_empty_search_path < restore_public_search_path,
|
||||
"baseline migration must restore search_path after clearing it",
|
||||
);
|
||||
assert!(
|
||||
!baseline
|
||||
@@ -186,5 +192,11 @@ mod tests {
|
||||
.contains("SELECT pg_catalog.set_config('search_path', '', false);"),
|
||||
"baseline migration must not persist an empty search_path at session scope",
|
||||
);
|
||||
assert!(
|
||||
!baseline
|
||||
.sql
|
||||
.contains("SELECT pg_catalog.set_config('search_path', 'public', false);"),
|
||||
"baseline migration must not persist a restored search_path at session scope",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user