/// <reference path="../pb_data/types.d.ts" />
migrate((app) => {
  const collection = app.findCollectionByNameOrId("entrant_readiness");

  const records = app.findRecordsByFilter(collection.id, "", "", 0, 0);
  for (const record of records) {
    app.delete(record);
  }

  collection.fields.removeByName("field");

  if (!collection.fields.fieldNames().includes("entrant_appearance")) {
    collection.fields.addAt(1, new Field({
      cascadeDelete: true,
      collectionId: "pbc_4190072853",
      hidden: false,
      id: "relation3847261520",
      maxSelect: 1,
      minSelect: 1,
      name: "entrant_appearance",
      presentable: false,
      required: true,
      system: false,
      type: "relation"
    }));
  }

  return app.save(collection);
}, (app) => {
  const collection = app.findCollectionByNameOrId("entrant_readiness");

  collection.fields.removeByName("entrant_appearance");

  if (!collection.fields.fieldNames().includes("field")) {
    collection.fields.addAt(1, new Field({
      cascadeDelete: false,
      collectionId: "pbc_918751319",
      hidden: false,
      id: "relation1542800728",
      maxSelect: 1,
      minSelect: 0,
      name: "field",
      presentable: false,
      required: false,
      system: false,
      type: "relation"
    }));
  }

  return app.save(collection);
});
