|
1 |
| -use once_cell::sync::Lazy; |
2 | 1 | use regex::Regex;
|
3 | 2 | use siphasher::sip::SipHasher13;
|
4 | 3 | use time::OffsetDateTime;
|
5 | 4 |
|
6 | 5 | use std::cmp::Ordering;
|
7 | 6 | use std::fmt;
|
8 | 7 | use std::hash::{Hash, Hasher};
|
| 8 | +use std::sync::OnceLock; |
9 | 9 |
|
10 | 10 | use crate::error::Kind;
|
11 | 11 | use crate::traits::DEFAULT_MIGRATION_TABLE_NAME;
|
12 | 12 | use crate::{AsyncMigrate, Error, Migrate};
|
13 | 13 | use std::fmt::Formatter;
|
14 | 14 |
|
15 | 15 | // regex used to match file names
|
16 |
| -pub fn file_match_re() -> Regex { |
17 |
| - Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap() |
| 16 | +pub fn file_match_re() -> &'static Regex { |
| 17 | + static RE: OnceLock<regex::Regex> = OnceLock::new(); |
| 18 | + RE.get_or_init(|| Regex::new(r"^([U|V])(\d+(?:\.\d+)?)__(\w+)").unwrap()) |
18 | 19 | }
|
19 | 20 |
|
20 |
| -pub(crate) static RE: Lazy<regex::Regex> = Lazy::new(file_match_re); |
21 |
| - |
22 | 21 | /// An enum set that represents the type of the Migration
|
23 | 22 | #[derive(Clone, PartialEq)]
|
24 | 23 | pub enum Type {
|
@@ -83,7 +82,7 @@ impl Migration {
|
83 | 82 | /// Create an unapplied migration, name and version are parsed from the input_name,
|
84 | 83 | /// which must be named in the format (U|V){1}__{2}.rs where {1} represents the migration version and {2} the name.
|
85 | 84 | pub fn unapplied(input_name: &str, sql: &str) -> Result<Migration, Error> {
|
86 |
| - let captures = RE |
| 85 | + let captures = file_match_re() |
87 | 86 | .captures(input_name)
|
88 | 87 | .filter(|caps| caps.len() == 4)
|
89 | 88 | .ok_or_else(|| Error::new(Kind::InvalidName, None))?;
|
|
0 commit comments