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