SchemaMigrator class
Automatically applies pending database migrations after authentication.
The bundled schema.sql (applied via Supabase Management API in Phase 1)
includes a _schema_meta table and an _apply_migration() SECURITY
DEFINER function. On each sign-in the app reads the current schema
version and calls the RPC for every migration the DB is behind on.
Adding a new migration
- Create
supabase/migrations/NNN_description.sql - Run
./dto schema bundle— regeneratesassets/schema/schema.sql,assets/migrations/NNN.sql, andlib/data/services/schema_version.g.dart - Commit all generated artifacts alongside the migration
The CI drift guard fails if the bundled assets are stale.
Constructors
-
SchemaMigrator(SupabaseClient _client, {List<
Migration> ? migrations, MigrationLoader? migrationLoader}) -
Creates a migrator.
migrationsoverrides the default asset-backed loader (useful for tests).migrationLoaderis an alternate override that defers loading untilrun()is called.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
readFunctionsHash(
) → Future< String?> -
Reads the deployed Edge Function bundle hash from
_schema_meta. -
run(
) → Future< int?> - Applies any pending migrations and returns the final schema version.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- expectedVersion → int
-
The schema version that this build of the app expects. Always matches
the highest
supabase/migrations/NNN_*.sqlat the time./dto schema bundlewas last run.no setter