database_migration/
config.rs1use crate::definition::ExcludedFiles;
2use std::borrow::Cow;
3use std::path::Path;
4
5pub const DEFAULT_MIGRATIONS_FOLDER: &str = "migrations";
6pub const DEFAULT_MIGRATIONS_TABLE: &str = "migrations";
7pub const DEFAULT_EXCLUDED_FILES: &str = ".*|README*|TODO*";
8
9pub const MIGRATION_KEY_FORMAT_STR: &str = "%Y%m%d_%H%M%S";
10
11#[must_use]
12#[derive(Debug, Clone, PartialEq)]
13pub struct RunnerConfig<'a> {
14 pub migrations_folder: Cow<'a, Path>,
15 pub excluded_files: ExcludedFiles,
16 pub migrations_table: Cow<'a, str>,
17 pub ignore_checksum: bool,
18 pub ignore_order: bool,
19}
20
21impl Default for RunnerConfig<'_> {
22 fn default() -> Self {
23 let excluded_files = ExcludedFiles::default();
24
25 Self {
26 migrations_folder: Path::new(DEFAULT_MIGRATIONS_FOLDER).into(),
27 excluded_files,
28 migrations_table: DEFAULT_MIGRATIONS_TABLE.into(),
29 ignore_checksum: false,
30 ignore_order: false,
31 }
32 }
33}
34
35impl<'a> RunnerConfig<'a> {
36 pub fn with_migrations_folder(mut self, migrations_folder: impl Into<Cow<'a, Path>>) -> Self {
37 self.migrations_folder = migrations_folder.into();
38 self
39 }
40
41 pub fn with_migrations_table(mut self, migrations_table: impl Into<Cow<'a, str>>) -> Self {
42 self.migrations_table = migrations_table.into();
43 self
44 }
45
46 pub const fn with_ignore_checksum(mut self, ignore_checksum: bool) -> Self {
47 self.ignore_checksum = ignore_checksum;
48 self
49 }
50
51 pub const fn with_ignore_order(mut self, ignore_order: bool) -> Self {
52 self.ignore_order = ignore_order;
53 self
54 }
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
58pub enum DbAuthLevel {
59 Root,
60 Namespace,
61 Database,
62}
63
64#[must_use]
65#[derive(Debug, Clone, PartialEq, Eq)]
66pub struct DbClientConfig<'a> {
67 pub address: Cow<'a, str>,
75
76 pub namespace: Cow<'a, str>,
80
81 pub database: Cow<'a, str>,
85
86 pub auth_level: DbAuthLevel,
90
91 pub username: Cow<'a, str>,
95
96 pub password: Cow<'a, str>,
100
101 pub capacity: usize,
109}
110
111impl Default for DbClientConfig<'_> {
112 fn default() -> Self {
113 Self {
114 address: "ws://localhost:8000".into(),
115 namespace: "test".into(),
116 database: "test".into(),
117 auth_level: DbAuthLevel::Root,
118 username: "root".into(),
119 password: "root".into(),
120 capacity: 20,
121 }
122 }
123}
124
125impl<'a> DbClientConfig<'a> {
126 pub fn with_address(mut self, address: impl Into<Cow<'a, str>>) -> Self {
127 self.address = address.into();
128 self
129 }
130
131 pub fn with_namespace(mut self, namespace: impl Into<Cow<'a, str>>) -> Self {
132 self.namespace = namespace.into();
133 self
134 }
135
136 pub fn with_database(mut self, database: impl Into<Cow<'a, str>>) -> Self {
137 self.database = database.into();
138 self
139 }
140
141 pub const fn with_auth_level(mut self, auth_level: DbAuthLevel) -> Self {
142 self.auth_level = auth_level;
143 self
144 }
145
146 pub fn with_username(mut self, username: impl Into<Cow<'a, str>>) -> Self {
147 self.username = username.into();
148 self
149 }
150
151 pub fn with_password(mut self, password: impl Into<Cow<'a, str>>) -> Self {
152 self.password = password.into();
153 self
154 }
155
156 pub const fn with_capacity(mut self, capacity: usize) -> Self {
157 self.capacity = capacity;
158 self
159 }
160}