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 seaorm_entities;
37pub use seaorm_entities::generate_seaorm_entities;
38
39mod toasty_models;
40pub use toasty_models::generate_toasty_models;
41
42mod tracking;
43pub use tracking::schema_hash;
44
45pub mod plugin_schemas;
46
47pub mod config;
48pub mod diff;
49pub mod generate;
50
51pub const ALL_PLUGINS: &[&str] = &[
53 "email-password",
54 "passkey",
55 "mfa",
56 "oauth",
57 "bearer",
58 "api-key",
59 "magic-link",
60 "oauth2-server",
61 "account-lockout",
62 "webhooks",
63 "oidc",
64];
65
66pub fn plugin_schema_by_name(name: &str) -> Option<Vec<TableDef>> {
70 match name {
71 "email-password" => Some(plugin_schemas::email_password_schema()),
72 "passkey" => Some(plugin_schemas::passkey_schema()),
73 "mfa" => Some(plugin_schemas::mfa_schema()),
74 "oauth" => Some(plugin_schemas::oauth_schema()),
75 "bearer" => Some(plugin_schemas::bearer_schema()),
76 "api-key" => Some(plugin_schemas::api_key_schema()),
77 "magic-link" => Some(plugin_schemas::magic_link_schema()),
78 "oauth2-server" => Some(plugin_schemas::oauth2_server_schema()),
79 "account-lockout" => Some(plugin_schemas::account_lockout_schema()),
80 "webhooks" => Some(plugin_schemas::webhooks_schema()),
81 "oidc" => Some(plugin_schemas::oidc_schema()),
82 _ => None,
83 }
84}
85
86pub fn is_known_plugin(name: &str) -> bool {
89 matches!(
90 name,
91 "email-password"
92 | "passkey"
93 | "mfa"
94 | "oauth"
95 | "bearer"
96 | "api-key"
97 | "magic-link"
98 | "admin"
99 | "status"
100 | "oauth2-server"
101 | "account-lockout"
102 | "webhooks"
103 | "oidc"
104 | "telemetry"
105 | "openapi"
106 )
107}
108
109pub fn collect_schema_for_plugins(
114 plugins: &[String],
115 table_prefix: &str,
116) -> Result<YAuthSchema, SchemaError> {
117 let mut table_lists = vec![core_schema()];
118 for plugin in plugins {
119 match plugin_schema_by_name(plugin) {
120 Some(tables) => table_lists.push(tables),
121 None if is_known_plugin(plugin) => {
122 }
124 None => {
125 return Err(SchemaError::UnknownPlugin(plugin.clone()));
126 }
127 }
128 }
129
130 if table_prefix != "yauth_" {
132 for list in &mut table_lists {
133 for table in list.iter_mut() {
134 table.apply_prefix("yauth_", table_prefix);
135 }
136 }
137 }
138
139 collect_schema(table_lists)
140}
141
142pub fn generate_ddl(schema: &YAuthSchema, dialect: Dialect) -> String {
144 match dialect {
145 Dialect::Postgres => generate_postgres_ddl(schema),
146 Dialect::Sqlite => generate_sqlite_ddl(schema),
147 Dialect::Mysql => generate_mysql_ddl(schema),
148 }
149}
150
151#[cfg(test)]
152mod tests;