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

  // update collection data
  unmarshal({
    "viewQuery": "SELECT \n  (ROW_NUMBER() OVER()) as id, \n  doctor, count(doctor) as cnt\nfrom rmias\ngroup by doctor\n\n"
  }, collection)

  // remove field
  collection.fields.removeById("_clone_5r0b")

  // add field
  collection.fields.addAt(1, new Field({
    "autogeneratePattern": "",
    "hidden": false,
    "id": "_clone_hx2W",
    "max": 0,
    "min": 0,
    "name": "doctor",
    "pattern": "",
    "presentable": false,
    "primaryKey": false,
    "required": false,
    "system": false,
    "type": "text"
  }))

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

  // update collection data
  unmarshal({
    "viewQuery": "SELECT \n  (ROW_NUMBER() OVER()) as id, \n  doctor, count(doctor) as cnt\nfrom rmias\n\n"
  }, collection)

  // add field
  collection.fields.addAt(1, new Field({
    "autogeneratePattern": "",
    "hidden": false,
    "id": "_clone_5r0b",
    "max": 0,
    "min": 0,
    "name": "doctor",
    "pattern": "",
    "presentable": false,
    "primaryKey": false,
    "required": false,
    "system": false,
    "type": "text"
  }))

  // remove field
  collection.fields.removeById("_clone_hx2W")

  return app.save(collection)
})
