1mod types;
16pub use types::*;
17
18mod core;
19pub use core::core_schema;
20
21mod collector;
22pub use collector::{SchemaError, YAuthSchema, collect_schema};
23
24mod postgres;
25pub use postgres::{generate_postgres_ddl, generate_postgres_drop, generate_postgres_drops};
26
27mod sqlite;
28pub use sqlite::{generate_sqlite_ddl, generate_sqlite_drop, generate_sqlite_drops};
29
30mod mysql;
31pub use mysql::{generate_mysql_ddl, generate_mysql_drop, generate_mysql_drops};
32
33mod diesel_schema;
34pub use diesel_schema::generate_diesel_schema;
35
36mod tracking;
37pub use tracking::schema_hash;
38
39pub mod plugin_schemas;
40
41pub mod config;
42pub mod diff;
43pub mod generate;
44
45pub const ALL_PLUGINS: &[&str] = &[
47 "email-password",
48 "passkey",
49 "mfa",
50 "oauth",
51 "bearer",
52 "api-key",
53 "magic-link",
54 "oauth2-server",
55 "account-lockout",
56 "webhooks",
57 "oidc",
58];
59
60pub fn plugin_schema_by_name(name: &str) -> Option<Vec<TableDef>> {
64 match name {
65 "email-password" => Some(plugin_schemas::email_password_schema()),
66 "passkey" => Some(plugin_schemas::passkey_schema()),
67 "mfa" => Some(plugin_schemas::mfa_schema()),
68 "oauth" => Some(plugin_schemas::oauth_schema()),
69 "bearer" => Some(plugin_schemas::bearer_schema()),
70 "api-key" => Some(plugin_schemas::api_key_schema()),
71 "magic-link" => Some(plugin_schemas::magic_link_schema()),
72 "oauth2-server" => Some(plugin_schemas::oauth2_server_schema()),
73 "account-lockout" => Some(plugin_schemas::account_lockout_schema()),
74 "webhooks" => Some(plugin_schemas::webhooks_schema()),
75 "oidc" => Some(plugin_schemas::oidc_schema()),
76 _ => None,
77 }
78}
79
80pub fn is_known_plugin(name: &str) -> bool {
83 matches!(
84 name,
85 "email-password"
86 | "passkey"
87 | "mfa"
88 | "oauth"
89 | "bearer"
90 | "api-key"
91 | "magic-link"
92 | "admin"
93 | "status"
94 | "oauth2-server"
95 | "account-lockout"
96 | "webhooks"
97 | "oidc"
98 | "telemetry"
99 | "openapi"
100 )
101}
102
103pub fn collect_schema_for_plugins(
108 plugins: &[String],
109 table_prefix: &str,
110) -> Result<YAuthSchema, SchemaError> {
111 let mut table_lists = vec![core_schema()];
112 for plugin in plugins {
113 match plugin_schema_by_name(plugin) {
114 Some(tables) => table_lists.push(tables),
115 None if is_known_plugin(plugin) => {
116 }
118 None => {
119 return Err(SchemaError::UnknownPlugin(plugin.clone()));
120 }
121 }
122 }
123
124 if table_prefix != "yauth_" {
126 for list in &mut table_lists {
127 for table in list.iter_mut() {
128 table.apply_prefix("yauth_", table_prefix);
129 }
130 }
131 }
132
133 collect_schema(table_lists)
134}
135
136pub fn generate_ddl(schema: &YAuthSchema, dialect: Dialect) -> String {
138 match dialect {
139 Dialect::Postgres => generate_postgres_ddl(schema),
140 Dialect::Sqlite => generate_sqlite_ddl(schema),
141 Dialect::Mysql => generate_mysql_ddl(schema),
142 }
143}
144
145#[cfg(test)]
146mod tests;