title: Understanding Migrations in Vapor-Fluent (Server side Swift)
body: <p>I'm writing a web service in Swift using Vapor framework. </p>
  
  <p>I have model named <code>Item</code>. Intially it has only name and id properties. </p>
  
  <pre><code>typealias VaporModel = Content &amp; PostgreSQLModel &amp; Parameter
  final class Item: VaporModel {
      var id: Int?
      var name: String
  }
  </code></pre>
  
  <p>After I configure a controller for the model and add the routes, when I hit the post Item request, I get the error as <code>Model.defaultDatabase is required to use as DatabaseConnectable</code>. I think the error is because I have not added <code>Item</code> to <code>Migrations</code> in <code>configure.swift</code> and I do the same after conforming <code>Item</code> to <code>PostgreSQLMigration</code>.</p>
  
  <pre><code>var migrations = MigrationConfig()
  migrations.add(model: Item.self, database: .psql)
  services.register(migrations)
  </code></pre>
  
  <p>Now, I am able to hit the post request and create items in the database. </p>
  
  <p>So I understand that <code>Migration</code> protocol creates the default schema for a model and adds a new table to the database with the model's properties as columns.</p>
  
  <p>Now I want to add a property such as <code>price</code> to my Item class. Now when I hit the post request, I get the error as <code>column "price" of relation "Item" does not exist</code>. 
  I assume the Migration protocol will be able to identify the schema changes and the column to my table (that's what I was used to in while using Realm for my iOS apps). But I am wrong and I read through the Migration docs and implement the <code>prepare</code> and <code>revert</code> methods in migration like below.</p>
  
  <pre><code>extension Item: PostgreSQLMigration {
      static func prepare(on conn: PostgreSQLConnection) -&gt; Future&lt;Void&gt; {
          return Database.create(self, on: conn) { creator in
              creator.field(for: \.price)
          }
      }
  
      static func revert(on connection: PostgreSQLConnection) -&gt; EventLoopFuture&lt;Void&gt; {
          return Future.map(on: connection) { }
      }
  } 
  </code></pre>
  
  <p>I'm still struck with the same error <code>column "price" of relation "Item" does not exist</code>. What am I missing here? Is my migration code correct?</p>
  
  <p>Also, I understand that if am not making any changes to the Model, I can comment out the migration config, because they need not run every time I run the service. Is that correct?</p>