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

  1. Create supabase/migrations/NNN_description.sql
  2. Run ./dto schema bundle — regenerates assets/schema/schema.sql, assets/migrations/NNN.sql, and lib/data/services/schema_version.g.dart
  3. 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. migrations overrides the default asset-backed loader (useful for tests). migrationLoader is an alternate override that defers loading until run() 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_*.sql at the time ./dto schema bundle was last run.
no setter