Create db migration to add and use the merchants and tellers tables.

This commit is contained in:
Severiano Jaramillo 2019-01-22 13:55:28 -06:00
parent 6ed34d20eb
commit 4558d54d27
4 changed files with 455 additions and 15 deletions

View file

@ -0,0 +1,431 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "79a582fa39e989852699b131383e993a",
"entities": [
{
"tableName": "assets",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `symbol` TEXT NOT NULL, `precision` INTEGER NOT NULL, `description` TEXT NOT NULL, `bit_asset_id` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "symbol",
"columnName": "symbol",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "precision",
"columnName": "precision",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "description",
"columnName": "description",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "bitAssetId",
"columnName": "bit_asset_id",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "authorities",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `user_id` TEXT NOT NULL, `authority_type` INTEGER NOT NULL, `encrypted_wif` TEXT NOT NULL, `encrypted_brain_key` TEXT NOT NULL, `encrypted_sequence_number` TEXT NOT NULL)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "userId",
"columnName": "user_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "authorityType",
"columnName": "authority_type",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "encryptedWIF",
"columnName": "encrypted_wif",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "encryptedBrainKey",
"columnName": "encrypted_brain_key",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "encryptedSequenceNumber",
"columnName": "encrypted_sequence_number",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "balances",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`asset_id` TEXT NOT NULL, `asset_amount` INTEGER NOT NULL, `last_update` INTEGER NOT NULL, PRIMARY KEY(`asset_id`))",
"fields": [
{
"fieldPath": "assetId",
"columnName": "asset_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "assetAmount",
"columnName": "asset_amount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "lastUpdate",
"columnName": "last_update",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"asset_id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "equivalent_values",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `transfer_id` TEXT NOT NULL, `value` INTEGER NOT NULL, `asset_id` TEXT NOT NULL, FOREIGN KEY(`transfer_id`) REFERENCES `transfers`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION , FOREIGN KEY(`asset_id`) REFERENCES `assets`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION )",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "transferId",
"columnName": "transfer_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "value",
"columnName": "value",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "assetId",
"columnName": "asset_id",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": [
{
"table": "transfers",
"onDelete": "NO ACTION",
"onUpdate": "NO ACTION",
"columns": [
"transfer_id"
],
"referencedColumns": [
"id"
]
},
{
"table": "assets",
"onDelete": "NO ACTION",
"onUpdate": "NO ACTION",
"columns": [
"asset_id"
],
"referencedColumns": [
"id"
]
}
]
},
{
"tableName": "transfers",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `block_number` INTEGER NOT NULL, `timestamp` INTEGER NOT NULL, `fee_amount` INTEGER NOT NULL, `fee_asset_id` TEXT NOT NULL, `source` TEXT NOT NULL, `destination` TEXT NOT NULL, `transfer_amount` INTEGER NOT NULL, `transfer_asset_id` TEXT NOT NULL, `memo` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "blockNumber",
"columnName": "block_number",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "timestamp",
"columnName": "timestamp",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "feeAmount",
"columnName": "fee_amount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "feeAssetId",
"columnName": "fee_asset_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "source",
"columnName": "source",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "destination",
"columnName": "destination",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "transferAmount",
"columnName": "transfer_amount",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "transferAssetId",
"columnName": "transfer_asset_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "memo",
"columnName": "memo",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "user_accounts",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `is_ltm` INTEGER NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isLtm",
"columnName": "is_ltm",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "merchants",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `address` TEXT, `lat` REAL NOT NULL, `lon` REAL NOT NULL, `phone` TEXT, `telegram` TEXT, `website` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "_id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "address",
"columnName": "address",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "lat",
"columnName": "lat",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "lon",
"columnName": "lon",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "phone",
"columnName": "phone",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "telegram",
"columnName": "telegram",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "website",
"columnName": "website",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "tellers",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `name` TEXT NOT NULL, `address` TEXT, `lat` REAL NOT NULL, `lon` REAL NOT NULL, `phone` TEXT, `telegram` TEXT, `website` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "_id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "gt_name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "address",
"columnName": "address",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "lat",
"columnName": "lat",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "lon",
"columnName": "lon",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "phone",
"columnName": "phone",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "telegram",
"columnName": "telegram",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "url",
"columnName": "website",
"affinity": "TEXT",
"notNull": false
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": false
},
"indices": [],
"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, \"79a582fa39e989852699b131383e993a\")"
]
}
}

View file

@ -4,6 +4,8 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import cy.agorise.bitsybitshareswallet.database.daos.*
import cy.agorise.bitsybitshareswallet.database.entities.*
import cy.agorise.bitsybitshareswallet.database.joins.BalanceDetailDao
@ -15,9 +17,11 @@ import cy.agorise.bitsybitshareswallet.database.joins.TransferDetailDao
Balance::class,
EquivalentValue::class,
Transfer::class,
UserAccount::class
UserAccount::class,
Merchant::class,
Teller::class
],
version = 1,
version = 2,
exportSchema = true)
abstract class BitsyDatabase : RoomDatabase() {
@ -29,9 +33,8 @@ abstract class BitsyDatabase : RoomDatabase() {
abstract fun userAccountDao(): UserAccountDao
abstract fun balanceDetailDao(): BalanceDetailDao
abstract fun transferDetailDao(): TransferDetailDao
// version 2
// abstract fun merchantDao(): MerchantDao
// abstract fun tellerDao(): TellerDao
abstract fun merchantDao(): MerchantDao
abstract fun tellerDao(): TellerDao
companion object {
@ -45,12 +48,18 @@ abstract class BitsyDatabase : RoomDatabase() {
INSTANCE = Room.databaseBuilder(
context.applicationContext,
BitsyDatabase::class.java, "BiTSyWallet.db"
)
.build()
).addMigrations(MIGRATION_1_2).build()
}
}
return INSTANCE
}
private val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("CREATE TABLE IF NOT EXISTS 'merchants' ('id' TEXT NOT NULL PRIMARY KEY, 'name' TEXT NOT NULL, 'address' TEXT, 'lat' REAL NOT NULL, 'lon' REAL NOT NULL, 'phone' TEXT, 'telegram' TEXT, 'website' TEXT)")
database.execSQL("CREATE TABLE IF NOT EXISTS 'tellers' ('id' TEXT NOT NULL PRIMARY KEY, 'name' TEXT NOT NULL, 'address' TEXT, 'lat' REAL NOT NULL, 'lon' REAL NOT NULL, 'phone' TEXT, 'telegram' TEXT, 'website' TEXT)")
}
}
}
}

View file

@ -9,10 +9,10 @@ data class Merchant(
@PrimaryKey
@ColumnInfo(name = "id") val _id: String,
@ColumnInfo(name = "name") val name: String,
@ColumnInfo(name = "address") val address: String,
@ColumnInfo(name = "address") val address: String?,
@ColumnInfo(name = "lat") val lat: Float,
@ColumnInfo(name = "lon") val lon: Float,
@ColumnInfo(name = "phone") val phone: String,
@ColumnInfo(name = "telegram") val telegram: String,
@ColumnInfo(name = "website") val website: String
@ColumnInfo(name = "phone") val phone: String?,
@ColumnInfo(name = "telegram") val telegram: String?,
@ColumnInfo(name = "website") val website: String?
)

View file

@ -9,10 +9,10 @@ data class Teller(
@PrimaryKey
@ColumnInfo(name = "id") val _id: String,
@ColumnInfo(name = "name") val gt_name: String,
@ColumnInfo(name = "address") val address: String,
@ColumnInfo(name = "address") val address: String?,
@ColumnInfo(name = "lat") val lat: Float,
@ColumnInfo(name = "lon") val lon: Float,
@ColumnInfo(name = "phone") val phone: String,
@ColumnInfo(name = "telegram") val telegram: String,
@ColumnInfo(name = "website") val url: String
@ColumnInfo(name = "phone") val phone: String?,
@ColumnInfo(name = "telegram") val telegram: String?,
@ColumnInfo(name = "website") val url: String?
)