deleteCollection method Null safety

Future deleteCollection(
  1. String name
)

deleteCollection deletes the provided Collection model. This method automatically deletes the related collection records table.

The collection cannot be deleted, if:

  • is system collection (aka. collection.System is true)
  • is referenced as part of a relation field in another collection

Implementation

Future deleteCollection(String name) => transaction(() async {
      // TODO: implement edge cases

      // if (collection.system) {
      //   throw Exception('Cannot delete system collection');
      // }

      // final referenced = await (select(field)
      //       ..where((_) => _.collectionId.equals(collection.id)))
      //     .get();

      // if (referenced.isNotEmpty) {
      //   throw Exception(
      //       'Cannot delete collection, because it is referenced in other collections');
      // }

      // await (delete(attachedDatabase.collection)
      //       ..where((_) => _.id.equals(collection.id)))
      //     .go();

      // await (delete(attachedDatabase.field)
      //       ..where((_) => _.collectionId.equals(collection.id)))
      //     .go();

      await _migrator.deleteTable(name);
    });