1use rustauth_core::db::sql::{plan_schema_migration, SqlDialect, SqlSchemaSnapshot};
2use rustauth_core::db::{auth_schema, AuthSchemaOptions, DbSchema, SchemaMigrationPlan};
3use rustauth_core::error::RustAuthError;
4
5use crate::config::CliConfig;
6use crate::plugins::schema_context_for_config;
7
8pub fn target_schema(config: &CliConfig) -> Result<DbSchema, RustAuthError> {
9 if config.plugins.enabled.is_empty() {
10 return Ok(auth_schema(AuthSchemaOptions::default()));
11 }
12 Ok(schema_context_for_config(&config.plugins.enabled)?.db_schema)
13}
14
15pub fn dialect_from_provider(provider: &str) -> Option<SqlDialect> {
16 match provider {
17 "postgres" | "postgresql" | "pg" => Some(SqlDialect::Postgres),
18 "mysql" => Some(SqlDialect::MySql),
19 "sqlite" | "sqlite3" => Some(SqlDialect::Sqlite),
20 _ => None,
21 }
22}
23
24pub fn full_schema_plan(
25 dialect: SqlDialect,
26 schema: &DbSchema,
27) -> Result<SchemaMigrationPlan, RustAuthError> {
28 plan_schema_migration(dialect, schema, &SqlSchemaSnapshot::default())
29}
30
31pub fn dialect_name(dialect: SqlDialect) -> &'static str {
32 match dialect {
33 SqlDialect::MySql => "mysql",
34 SqlDialect::Postgres => "postgres",
35 SqlDialect::Sqlite => "sqlite",
36 }
37}