Ver Fonte

set id as unique

carlos há 3 anos atrás
pai
commit
ab7962b9ed

BIN
XPContactProvider.apk


+ 119 - 0
app/schemas/com.xplora.contactprovider.dao.ContactDatabase/2.json

@@ -0,0 +1,119 @@
+{
+  "formatVersion": 1,
+  "database": {
+    "version": 2,
+    "identityHash": "97c38008c01e91c02d0dd98917aabb43",
+    "entities": [
+      {
+        "tableName": "contact",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `id` TEXT, `userId` TEXT, `name` TEXT, `profile` TEXT, `phoneNumber` TEXT, `countryPN` TEXT, `sim` TEXT, `type` TEXT, `rate` TEXT, `unRead` TEXT, `profilePath` TEXT)",
+        "fields": [
+          {
+            "fieldPath": "_id",
+            "columnName": "_id",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "id",
+            "columnName": "id",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "userId",
+            "columnName": "userId",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "name",
+            "columnName": "name",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "profile",
+            "columnName": "profile",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "phoneNumber",
+            "columnName": "phoneNumber",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "countryPN",
+            "columnName": "countryPN",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "sim",
+            "columnName": "sim",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "type",
+            "columnName": "type",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "rate",
+            "columnName": "rate",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "unRead",
+            "columnName": "unRead",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "profilePath",
+            "columnName": "profilePath",
+            "affinity": "TEXT",
+            "notNull": false
+          }
+        ],
+        "primaryKey": {
+          "columnNames": [
+            "_id"
+          ],
+          "autoGenerate": true
+        },
+        "indices": [
+          {
+            "name": "index_contact__id",
+            "unique": true,
+            "columnNames": [
+              "_id"
+            ],
+            "orders": [],
+            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_contact__id` ON `${TABLE_NAME}` (`_id`)"
+          },
+          {
+            "name": "index_contact_id",
+            "unique": true,
+            "columnNames": [
+              "id"
+            ],
+            "orders": [],
+            "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_contact_id` ON `${TABLE_NAME}` (`id`)"
+          }
+        ],
+        "foreignKeys": []
+      }
+    ],
+    "views": [],
+    "setupQueries": [
+      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '97c38008c01e91c02d0dd98917aabb43')"
+    ]
+  }
+}

+ 4 - 2
app/src/main/java/com/xplora/contactprovider/dao/ContactDatabase.kt

@@ -5,10 +5,12 @@ import androidx.room.Database
 import androidx.room.RoomDatabase
 
 @Database(
-    entities = [ContactInfo::class], version = 1,
+    entities = [ContactInfo::class], version = 2,
+    autoMigrations = [
+        AutoMigration(from = 1, to = 2)
+    ],
     exportSchema = true
 )
-//    autoMigrations = [AutoMigration(from = 1, to = 2)],
 abstract class ContactDatabase : RoomDatabase() {
     abstract fun contactDao(): ContactDao
 }

+ 2 - 1
app/src/main/java/com/xplora/contactprovider/dao/ContactInfo.kt

@@ -8,7 +8,8 @@ import com.google.gson.annotations.SerializedName
 import com.xplora.contactprovider.provider.WatchContactProvider.Companion.TABLE_NAME_CONTACT
 
 
-@Entity(tableName = TABLE_NAME_CONTACT, indices = [Index(value = ["_id"], unique = true)])
+@Entity(tableName = TABLE_NAME_CONTACT, indices = [Index(value = ["_id"], unique = true),
+    Index(value = ["id"], unique = true)])
 data class ContactInfo(
     @PrimaryKey(autoGenerate = true)
     @NonNull