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