Skip to content
Deedboxlatest

Apply the schema

This guide shows you the ways to create and upgrade the Deedbox tables. Deedbox never changes the schema unless you ask it to. Without a current schema, start-up fails with the exact fix (DBX001).

Call ApplySchemaOnStartup() in AddDeedbox. Pods take a database lock, so concurrent pods apply each migration once.

Terminal window
dotnet tool install -g Deedbox.Cli --prerelease
deedbox schema apply --provider postgres --connection "$DEEDBOX_CONNECTION"

Or print the SQL for a DBA:

Terminal window
deedbox schema script --provider sqlserver --from 0 > deedbox.sql

--from is the version the database has now. The scripts are idempotent, and each records itself in schema_version.

// An EF Core migration that creates the Deedbox tables without adding them to your model.
public partial class AddDeedbox : Migration
{
protected override void Up(MigrationBuilder migrationBuilder) =>
migrationBuilder.Sql(PostgresSchema.Script(fromVersion: 0)); // SqlServerSchema.Script on SQL Server
}

The tables stay out of your EF Core model. For an upgrade, add a new migration with Script(fromVersion: n).

Save the output of deedbox schema script as a numbered script in your migrations folder. For SQL Server, the script separates batches with GO.

.Schema("es") puts the tables in es instead of deedbox. Names are lower-case letters, digits and underscores, at most 50 characters.