buildDownMigration method

Method buildDownMigration(
  1. OrmBuildContext? ctx
)

Generate down() method to drop tables

Implementation

Method buildDownMigration(OrmBuildContext? ctx) {
  return Method((b) {
    b
      ..name = 'down'
      ..returns = refer('void')
      ..annotations.add(refer('override'))
      ..requiredParameters.add(_schemaParam)
      ..body = Block((b) {
        var named = <String, Expression>{};

        if (ctx!.relations.values.any((r) =>
            r.type == RelationshipType.hasOne ||
            r.type == RelationshipType.hasMany ||
            r.isManyToMany)) {
          named['cascade'] = literalTrue;
        }

        b.addExpression(_schema
            .property('drop')
            .call([literalString(ctx.tableName!)], named));
      });
  });
}