draftFromDatabase method

Future<PostgresqlMigrationDraft> draftFromDatabase({
  1. required SessionExecutor executor,
  2. required SchemaDocument target,
  3. required String migrationName,
})

Creates a migration draft by diffing the live database against target.

Implementation

Future<PostgresqlMigrationDraft> draftFromDatabase({
  required pg.SessionExecutor executor,
  required SchemaDocument target,
  required String migrationName,
}) async {
  final source = filterSchemaForUserModels(
    await planner.schemaIntrospector.introspect(executor),
    historyTableName: PostgresqlMigrationRunner.historyTableName,
  );
  final plan = _mergeRiskWarnings(
    planner.plan(from: source, to: target),
    detectPotentialDataLossWarnings(from: source, to: target),
  );
  return PostgresqlMigrationDraft(
    name: migrationName,
    generatedAt: DateTime.now().toUtc(),
    plan: plan,
    beforeSchema: schemaToSource(source),
    afterSchema: schemaToSource(target),
  );
}