Repository: julioz/FloorPlan (kotlin)

Issue:
Support rendering of default values
Room supports `DEFAULT` values, we should consider these and render them a part of [DBML type notes](https://www.dbml.org/docs/#default-value).

Pull request description:
Fixes #4

Patch:
diff --git a/src/main/kotlin/com/zynger/floorplan/dbml/Field.kt b/src/main/kotlin/com/zynger/floorplan/dbml/Field.kt
index 13cb2d8..03a2467 100644
--- a/src/main/kotlin/com/zynger/floorplan/dbml/Field.kt
+++ b/src/main/kotlin/com/zynger/floorplan/dbml/Field.kt
@@ -22,6 +22,14 @@ class Field(
             .apply {
                 append(" ")
                 append("[")
+                if (field.defaultValue != null) {
+                    append("default:")
+                    append(" ")
+                    append("`")
+                    append(field.defaultValue)
+                    append("`")
+                    append(", ")
+                }
                 if (isPrimaryKey) {
                     append("pk")
                     if (tablePrimaryKey.autoGenerate) {
diff --git a/src/main/kotlin/com/zynger/floorplan/model/Field.kt b/src/main/kotlin/com/zynger/floorplan/model/Field.kt
index ee70091..a0de321 100644
--- a/src/main/kotlin/com/zynger/floorplan/model/Field.kt
+++ b/src/main/kotlin/com/zynger/floorplan/model/Field.kt
@@ -7,5 +7,6 @@ data class Field (
     val fieldPath: String,
     val columnName: String,
     val affinity: String,
-    val notNull: Boolean
+    val notNull: Boolean,
+    val defaultValue: String? = null
 )
\ No newline at end of file


Test patch:
diff --git a/src/test/kotlin/com/zynger/floorplan/dbml/FieldTest.kt b/src/test/kotlin/com/zynger/floorplan/dbml/FieldTest.kt
index d465808..3114c4f 100644
--- a/src/test/kotlin/com/zynger/floorplan/dbml/FieldTest.kt
+++ b/src/test/kotlin/com/zynger/floorplan/dbml/FieldTest.kt
@@ -37,6 +37,62 @@ class FieldTest {
         )
     }
 
+    @Test
+    fun `non-primary key with default value gets rendered with default note`() {
+        val defaultValue = "defVal"
+        val textField = DbField(FIELD_PATH, COLUMN_NAME, "TEXT", true, defaultValue)
+        val tablePrimaryKey = PrimaryKey(emptyList(), false)
+
+        assertEquals(
+            """
+                $COLUMN_NAME varchar [default: `$defaultValue`, note: 'not null']
+            """.trimIndent(),
+            Field(textField, tablePrimaryKey).toString()
+        )
+    }
+
+    @Test
+    fun `non-primary key with default value gets rendered with default note even if it is an empty string`() {
+        val defaultValue = ""
+        val textField = DbField(FIELD_PATH, COLUMN_NAME, "TEXT", true, defaultValue)
+        val tablePrimaryKey = PrimaryKey(emptyList(), false)
+
+        assertEquals(
+            """
+                $COLUMN_NAME varchar [default: ``, note: 'not null']
+            """.trimIndent(),
+            Field(textField, tablePrimaryKey).toString()
+        )
+    }
+
+    @Test
+    fun `primary key with default value gets rendered with default note`() {
+        val defaultValue = "defVal"
+        val textField = DbField(FIELD_PATH, COLUMN_NAME, "INTEGER", false, defaultValue)
+        val tablePrimaryKey = PrimaryKey(listOf(COLUMN_NAME), false)
+
+        assertEquals(
+            """
+                $COLUMN_NAME int [default: `$defaultValue`, pk]
+            """.trimIndent(),
+            Field(textField, tablePrimaryKey).toString()
+        )
+    }
+
+    @Test
+    fun `non-primary key with default value using quotes gets rendered with default note`() {
+        val defaultValue = "\"quoted\""
+        val textField = DbField(FIELD_PATH, COLUMN_NAME, "TEXT", true, defaultValue)
+        val tablePrimaryKey = PrimaryKey(emptyList(), false)
+
+        assertEquals(
+            """
+                $COLUMN_NAME varchar [default: `$defaultValue`, note: 'not null']
+            """.trimIndent(),
+            Field(textField, tablePrimaryKey).toString()
+        )
+    }
+
     @Test
     fun `field with INTEGER type becomes int`() {
         val textField = DbField(FIELD_PATH, COLUMN_NAME, "INTEGER", false)