Skip to main content

Databases

The plugin has its own SuperAdminDbContext and connection string. Its tables can live in your app database or in a separate one, even on another database server.

Tables​

With the default prefix sa_:

sa_users, sa_roles, sa_permissions, sa_permission_routes, sa_menus, sa_user_roles, sa_role_permissions, sa_user_permissions, sa_role_menus, sa_operation_logs, sa_settings.

All DateTime values are stored and read as UTC (DateTimeKind.Utc), so ToLocalTime() gives the right local time.

Supported databases​

Install the EF Core 10 provider for your database and pass it to AddSuperAdmin:

DatabaseProvider packageAddSuperAdmin(..., db => ...)Tested
SQL Server, Azure SQL, LocalDBMicrosoft.EntityFrameworkCore.SqlServerdb.UseSqlServer(cs)Yes (LocalDB)
PostgreSQLNpgsql.EntityFrameworkCore.PostgreSQLdb.UseNpgsql(cs)Yes (17)
MySQLMySql.EntityFrameworkCore (Oracle's provider)db.UseMySQL(cs)Yes (9.1)
Oracle 23aiOracle.EntityFrameworkCoredb.UseOracle(cs)Script and model checks only
Oracle 19c / 21cOracle.EntityFrameworkCoredb.UseOracle(cs, o => o.UseOracleSQLCompatibility(OracleSQLCompatibility.DatabaseVersion19))Script and model checks only
SQLiteMicrosoft.EntityFrameworkCore.Sqlitedb.UseSqlite(cs)Yes
MongoDB-Not supported-

"Yes" means the provider test suite (tests/.../ProviderTests.cs: create, seed, users, roles, permissions, menus, import with explicit ids, UTC dates, log purge, install/re-run/upgrade scripts) passes against a real server. Run it against your own server with SA_TEST_SQLSERVER, SA_TEST_POSTGRES, SA_TEST_MYSQL or SA_TEST_ORACLE set to a connection string.

Provider notes​

  • MySQL / MariaDB: Pomelo.EntityFrameworkCore.MySql has no EF Core 10 release yet (latest 9.0.0), so use MySql.EntityFrameworkCore. To run the SQL scripts through ADO.NET, add Allow User Variables=True to the connection string. MariaDB is not tested.
  • Oracle: '' is NULL in Oracle, so the "any method" column sa_permission_routes.HttpMethods is nullable there. JSON attributes, logged input and settings are NCLOB. The shipped sql/oracle scripts use BOOLEAN (23ai). For 19c/21c, set the compatibility option above and generate the script with superadmin sql-script.
  • MongoDB: the plugin needs a relational database (joins, integer identities, transactions). If your app data is in MongoDB, keep the plugin tables in a small relational database, for example SQLite or PostgreSQL. Only the admin users, roles and permissions live there.

Modes​

InitializeSuperAdminAsync() handles the schema according to Database:Mode. Then it checks every plugin table and column, and stops the app with a clear error if one is missing, instead of failing on the first request.

ModeWhat it does
Auto (default)Apply your EF Core migrations if the app has them, otherwise like Create
CreateCreate the plugin tables if none exist, and add nullable columns introduced by newer package versions. Works in a database that already has your tables
MigrateApply your EF Core migrations only
NoneTouch nothing, only check. For teams that create schemas with reviewed SQL scripts

To manage the schema yourself, see Migrations and SQL scripts.